This repository has been archived by the owner on Jan 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/metadata_restore'
- Loading branch information
Showing
29 changed files
with
1,159 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
src/main/java/com/nike/cerberus/endpoints/admin/PutSDBMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Copyright (c) 2017 Nike, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.nike.cerberus.endpoints.admin; | ||
|
||
import com.google.inject.Inject; | ||
import com.nike.cerberus.domain.SDBMetadata; | ||
import com.nike.cerberus.endpoints.AdminStandardEndpoint; | ||
import com.nike.cerberus.security.VaultAuthPrincipal; | ||
import com.nike.cerberus.service.MetadataService; | ||
import com.nike.riposte.server.http.RequestInfo; | ||
import com.nike.riposte.server.http.ResponseInfo; | ||
import com.nike.riposte.util.Matcher; | ||
import io.netty.channel.ChannelHandlerContext; | ||
import io.netty.handler.codec.http.HttpMethod; | ||
import io.netty.handler.codec.http.HttpResponseStatus; | ||
|
||
import javax.ws.rs.core.SecurityContext; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.Executor; | ||
|
||
/** | ||
* Allows an Admin to restore (create or update) Metadata for an SDB | ||
*/ | ||
public class PutSDBMetadata extends AdminStandardEndpoint<SDBMetadata, Void> { | ||
|
||
private final MetadataService metadataService; | ||
|
||
@Inject | ||
public PutSDBMetadata(MetadataService metadataService) { | ||
this.metadataService = metadataService; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<ResponseInfo<Void>> doExecute(RequestInfo<SDBMetadata> request, | ||
Executor longRunningTaskExecutor, | ||
ChannelHandlerContext ctx, | ||
SecurityContext securityContext) { | ||
|
||
return CompletableFuture.supplyAsync(() -> { | ||
VaultAuthPrincipal vaultAuthPrincipal = (VaultAuthPrincipal) securityContext.getUserPrincipal(); | ||
metadataService.restoreMetadata(request.getContent(), vaultAuthPrincipal.getName()); | ||
|
||
return ResponseInfo.<Void>newBuilder() | ||
.withHttpStatusCode(HttpResponseStatus.NO_CONTENT.code()) | ||
.build(); | ||
}, longRunningTaskExecutor); | ||
} | ||
|
||
@Override | ||
public Matcher requestMatcher() { | ||
return Matcher.match("/v1/metadata", HttpMethod.PUT); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/nike/cerberus/error/InvalidCategoryNameApiError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2017 Nike, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.nike.cerberus.error; | ||
|
||
import com.nike.backstopper.apierror.ApiError; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import java.util.Map; | ||
|
||
public class InvalidCategoryNameApiError implements ApiError { | ||
|
||
private final String categoryName; | ||
|
||
public InvalidCategoryNameApiError(String categoryName) { | ||
this.categoryName = categoryName; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "InvalidCategoryNameApiError"; | ||
} | ||
|
||
@Override | ||
public String getErrorCode() { | ||
return DefaultApiError.ENTITY_NOT_FOUND.getErrorCode(); | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return String.format("The category %s could not be mapped to a valid category id", categoryName); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getMetadata() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getHttpStatusCode() { | ||
return HttpServletResponse.SC_BAD_REQUEST; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/com/nike/cerberus/error/InvalidIamRoleArnApiError.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* Copyright (c) 2017 Nike, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.nike.cerberus.error; | ||
|
||
import com.nike.backstopper.apierror.ApiError; | ||
|
||
import javax.servlet.http.HttpServletResponse; | ||
import java.util.Map; | ||
|
||
public class InvalidIamRoleArnApiError implements ApiError { | ||
|
||
private final String arn; | ||
|
||
public InvalidIamRoleArnApiError(String arn) { | ||
this.arn = arn; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "InvalidIamRoleArnApiError"; | ||
} | ||
|
||
@Override | ||
public String getErrorCode() { | ||
return DefaultApiError.ENTITY_NOT_FOUND.getErrorCode(); | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return String.format("The arn %s was not a valid arn in 'arn:aws:iam::(.*?):role/(.*)' format", arn); | ||
} | ||
|
||
@Override | ||
public Map<String, Object> getMetadata() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public int getHttpStatusCode() { | ||
return HttpServletResponse.SC_BAD_REQUEST; | ||
} | ||
} |
Oops, something went wrong.