Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
Merge branch 'feature/metadata_restore'
Browse files Browse the repository at this point in the history
  • Loading branch information
fieldju committed Feb 22, 2017
2 parents 1827fb5 + b80225f commit ee4e19a
Show file tree
Hide file tree
Showing 29 changed files with 1,159 additions and 243 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/nike/cerberus/dao/CategoryDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,8 @@ public int createCategory(final CategoryRecord record) {
public int deleteCategory(final String id) {
return categoryMapper.deleteCategory(id);
}

public String getCategoryIdByName(String categoryName) {
return categoryMapper.getCategoryIdByName(categoryName);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/nike/cerberus/dao/SafeDepositBoxDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,16 @@ public int updateSafeDepositBox(final SafeDepositBoxRecord safeDepositBox) {
return safeDepositBoxMapper.updateSafeDepositBox(safeDepositBox);
}

public int fullUpdateSafeDepositBox(final SafeDepositBoxRecord safeDepositBox) {
return safeDepositBoxMapper.fullUpdateSafeDepositBox(safeDepositBox);
}

public int deleteSafeDepositBox(final String id) {
return safeDepositBoxMapper.deleteSafeDepositBox(id);
}

public String getSafeDepositBoxIdByName(String name) {
return safeDepositBoxMapper.getSafeDepositBoxIdByName(name);
}

}
15 changes: 15 additions & 0 deletions src/main/java/com/nike/cerberus/domain/IamRolePermission.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ public void setAccountId(String accountId) {
this.accountId = accountId;
}

public IamRolePermission withAccountId(String accountId) {
this.accountId = accountId;
return this;
}

public String getIamRoleName() {
return iamRoleName;
}
Expand All @@ -74,6 +79,11 @@ public void setIamRoleName(String iamRoleName) {
this.iamRoleName = iamRoleName;
}

public IamRolePermission withIamRoleName(String iamRoleName) {
this.iamRoleName = iamRoleName;
return this;
}

public String getRoleId() {
return roleId;
}
Expand All @@ -82,6 +92,11 @@ public void setRoleId(String roleId) {
this.roleId = roleId;
}

public IamRolePermission withRoleId(String roleId) {
this.roleId = roleId;
return this;
}

public OffsetDateTime getCreatedTs() {
return createdTs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Date;
import java.util.Map;

public class SdbMetadata {
public class SDBMetadata {

private String name;
private String path;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/nike/cerberus/domain/SDBMetadataResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class SDBMetadataResult {
private int offset = 0;
private int sdbCountInResult;
private int totalSDBCount;
private List<SdbMetadata> safeDepositBoxMetadata;
private List<SDBMetadata> safeDepositBoxMetadata;

public boolean isHasNext() {
return hasNext;
Expand Down Expand Up @@ -76,11 +76,11 @@ public void setTotalSDBCount(int totalSDBCount) {
this.totalSDBCount = totalSDBCount;
}

public List<SdbMetadata> getSafeDepositBoxMetadata() {
public List<SDBMetadata> getSafeDepositBoxMetadata() {
return safeDepositBoxMetadata;
}

public void setSafeDepositBoxMetadata(List<SdbMetadata> safeDepositBoxMetadata) {
public void setSafeDepositBoxMetadata(List<SDBMetadata> safeDepositBoxMetadata) {
this.safeDepositBoxMetadata = safeDepositBoxMetadata;
}
}
42 changes: 42 additions & 0 deletions src/main/java/com/nike/cerberus/domain/SafeDepositBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,46 @@ public Set<IamRolePermission> getIamRolePermissions() {
public void setIamRolePermissions(Set<IamRolePermission> iamRolePermissions) {
this.iamRolePermissions = iamRolePermissions;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

SafeDepositBox that = (SafeDepositBox) o;

if (id != null ? !id.equals(that.id) : that.id != null) return false;
if (categoryId != null ? !categoryId.equals(that.categoryId) : that.categoryId != null) return false;
if (name != null ? !name.equals(that.name) : that.name != null) return false;
if (description != null ? !description.equals(that.description) : that.description != null) return false;
if (path != null ? !path.equals(that.path) : that.path != null) return false;
if (createdTs != null ? !createdTs.equals(that.createdTs) : that.createdTs != null) return false;
if (lastUpdatedTs != null ? !lastUpdatedTs.equals(that.lastUpdatedTs) : that.lastUpdatedTs != null)
return false;
if (createdBy != null ? !createdBy.equals(that.createdBy) : that.createdBy != null) return false;
if (lastUpdatedBy != null ? !lastUpdatedBy.equals(that.lastUpdatedBy) : that.lastUpdatedBy != null)
return false;
if (owner != null ? !owner.equals(that.owner) : that.owner != null) return false;
if (userGroupPermissions != null ? !userGroupPermissions.equals(that.userGroupPermissions) : that.userGroupPermissions != null)
return false;
return iamRolePermissions != null ? iamRolePermissions.equals(that.iamRolePermissions) : that.iamRolePermissions == null;

}

@Override
public int hashCode() {
int result = id != null ? id.hashCode() : 0;
result = 31 * result + (categoryId != null ? categoryId.hashCode() : 0);
result = 31 * result + (name != null ? name.hashCode() : 0);
result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + (path != null ? path.hashCode() : 0);
result = 31 * result + (createdTs != null ? createdTs.hashCode() : 0);
result = 31 * result + (lastUpdatedTs != null ? lastUpdatedTs.hashCode() : 0);
result = 31 * result + (createdBy != null ? createdBy.hashCode() : 0);
result = 31 * result + (lastUpdatedBy != null ? lastUpdatedBy.hashCode() : 0);
result = 31 * result + (owner != null ? owner.hashCode() : 0);
result = 31 * result + (userGroupPermissions != null ? userGroupPermissions.hashCode() : 0);
result = 31 * result + (iamRolePermissions != null ? iamRolePermissions.hashCode() : 0);
return result;
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/nike/cerberus/domain/UserGroupPermission.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public void setName(String name) {
this.name = name;
}

public UserGroupPermission withName(String name) {
this.name = name;
return this;
}

public String getRoleId() {
return roleId;
}
Expand All @@ -67,6 +72,11 @@ public void setRoleId(String roleId) {
this.roleId = roleId;
}

public UserGroupPermission withRoleId(String roleId) {
this.roleId = roleId;
return this;
}

public OffsetDateTime getCreatedTs() {
return createdTs;
}
Expand Down
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);
}
}
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;
}
}
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;
}
}
Loading

0 comments on commit ee4e19a

Please sign in to comment.