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

Commit

Permalink
Remove deprecated 'stats' admin endpoint (#16)
Browse files Browse the repository at this point in the history
* Remove deprecated 'stats' admin endpoint
  • Loading branch information
sdford authored Jan 31, 2017
1 parent 15ce938 commit 03670d5
Show file tree
Hide file tree
Showing 10 changed files with 4 additions and 335 deletions.
31 changes: 0 additions & 31 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -444,38 +444,7 @@ Lists all the possible categories that a safe deposit box can belong to.
}
]

# Group Stats

## Basic Stats [/v1/stats]

### Get stats [GET]

Returns basic stats about each safe deposit box (name, owner, last updated ts). Requester must be an admin.

+ Response 200 (application/json)

+ Headers

X-Vault-Token: 7f6808f1-ede3-2177-aa9d-45f507391310

+ Body

{
"safe_deposit_box_stats": [
{
"name": "Web",
"owner": "Lst-CDT.CloudPlatformEngine.FTE",
"last_updated_ts": "2016-05-18T06:51:08Z"
},
{
"name": "OneLogin",
"owner": "Lst-CDT.CloudPlatformEngine.FTE",
"last_updated_ts": "2016-05-18T06:35:55Z"
}
],
"safe_deposit_box_total": 2
}

# Group Metadata

## SDB Metadata [/v1/metadata?limit={limit}&offset={offset}]
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ JDBC.password | Yes | The JDBC JDBC.password for the mysql db
root.user.arn | Yes | The arn for the root AWS user, needed to make the KMS keys deletable.
admin.role.arn | Yes | The arn for an AWS user, needed to make the KMS keys deletable.
cms.role.arn | Yes | The arn for the Instance profile for CMS instances, so they can admin KMS keys that they create.
cms.admin.group | Yes | Group that user can be identified by to get admin privileges, currently this just enables users to access `/v1/stats` see API.md
cms.admin.group | Yes | Group that user can be identified by to get admin privileges, currently this just enables users to access `/v1/metadata` see API.md
cms.auth.connector | Yes | The user authentication connector implementation to use for user auth.
cms.user.token.ttl.override | No | By default user tokens are created with a TTL of 1h, you can override that with this param
cms.iam.token.ttl.override | No | By default IAM tokens are created with a TTL of 1h, you can override that with this param
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
# limitations under the License.
#

version=0.8.0
version=0.11.0
groupId=com.nike.cerberus
artifactId=cms
58 changes: 0 additions & 58 deletions src/main/java/com/nike/cerberus/domain/SafeDepositBoxStats.java

This file was deleted.

53 changes: 0 additions & 53 deletions src/main/java/com/nike/cerberus/domain/Stats.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import com.nike.backstopper.exception.ApiException;
import com.nike.cerberus.domain.SDBMetaDataResult;
import com.nike.cerberus.endpoints.AdminStandardEndpoint;
import com.nike.cerberus.domain.Stats;
import com.nike.cerberus.error.DefaultApiError;
import com.nike.cerberus.service.MetaDataService;
import com.nike.riposte.server.http.RequestInfo;
Expand Down
61 changes: 0 additions & 61 deletions src/main/java/com/nike/cerberus/endpoints/admin/GetStats.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import com.nike.cerberus.endpoints.sdb.GetSafeDepositBox;
import com.nike.cerberus.endpoints.sdb.GetSafeDepositBoxes;
import com.nike.cerberus.endpoints.sdb.UpdateSafeDepositBox;
import com.nike.cerberus.endpoints.admin.GetStats;
import com.nike.cerberus.error.DefaultApiErrorsImpl;
import com.nike.cerberus.auth.connector.AuthConnector;
import com.nike.cerberus.security.CmsRequestSecurityValidator;
Expand Down Expand Up @@ -174,7 +173,6 @@ public Set<Endpoint<?>> appEndpoints(
DeleteSafeDepositBox deleteSafeDepositBox,
UpdateSafeDepositBox updateSafeDepositBox,
CreateSafeDepositBox createSafeDepositBox,
GetStats getStats,
GetSDBMetaData getSDBMetaData
) {
return new LinkedHashSet<>(Arrays.<Endpoint<?>>asList(
Expand All @@ -185,7 +183,7 @@ public Set<Endpoint<?>> appEndpoints(
getAllRoles, getRole,
getSafeDepositBoxes, getSafeDepositBox,
deleteSafeDepositBox, updateSafeDepositBox, createSafeDepositBox,
getStats, getSDBMetaData
getSDBMetaData
));
}

Expand Down
53 changes: 1 addition & 52 deletions src/main/java/com/nike/cerberus/service/MetaDataService.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,38 +16,28 @@

package com.nike.cerberus.service;

import com.nike.backstopper.exception.ApiException;
import com.nike.cerberus.dao.AwsIamRoleDao;
import com.nike.cerberus.dao.CategoryDao;
import com.nike.cerberus.dao.RoleDao;
import com.nike.cerberus.dao.SafeDepositBoxDao;
import com.nike.cerberus.dao.UserGroupDao;
import com.nike.cerberus.domain.Role;
import com.nike.cerberus.domain.SDBMetaData;
import com.nike.cerberus.domain.SDBMetaDataResult;
import com.nike.cerberus.domain.SafeDepositBoxStats;
import com.nike.cerberus.domain.Stats;
import com.nike.cerberus.error.DefaultApiError;
import com.nike.cerberus.record.AwsIamRolePermissionRecord;
import com.nike.cerberus.record.AwsIamRoleRecord;
import com.nike.cerberus.record.CategoryRecord;
import com.nike.cerberus.record.RoleRecord;
import com.nike.cerberus.record.SafeDepositBoxRecord;
import com.nike.cerberus.record.UserGroupPermissionRecord;
import com.nike.cerberus.record.UserGroupRecord;
import com.nike.cerberus.util.DateTimeSupplier;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;

/**
* Provides general stats about safe deposit boxes.
Expand All @@ -56,67 +46,26 @@ public class MetaDataService {

private final Logger logger = LoggerFactory.getLogger(this.getClass());

private final RoleService roleService;
private final SafeDepositBoxDao safeDepositBoxDao;
private final UserGroupDao userGroupDao;
private final DateTimeSupplier dateTimeSupplier;
private final CategoryDao categoryDao;
private final RoleDao roleDao;
private final AwsIamRoleDao awsIamRoleDao;

@Inject
public MetaDataService(RoleService roleService,
SafeDepositBoxDao safeDepositBoxDao,
public MetaDataService(SafeDepositBoxDao safeDepositBoxDao,
UserGroupDao userGroupDao,
DateTimeSupplier dateTimeSupplier,
CategoryDao categoryDao,
RoleDao roleDao,
AwsIamRoleDao awsIamRoleDao) {

this.roleService = roleService;
this.safeDepositBoxDao = safeDepositBoxDao;
this.userGroupDao = userGroupDao;
this.dateTimeSupplier = dateTimeSupplier;
this.categoryDao = categoryDao;
this.roleDao = roleDao;
this.awsIamRoleDao = awsIamRoleDao;
}

@Deprecated // Use getSDBMetaData
public Stats getStats() {
final Optional<Role> ownerRole = roleService.getRoleByName(RoleRecord.ROLE_OWNER);

if (!ownerRole.isPresent()) {
throw ApiException.newBuilder()
.withApiErrors(DefaultApiError.MISCONFIGURED_APP)
.withExceptionMessage("Owner role doesn't exist!")
.build();
}

final Set<SafeDepositBoxStats> safeDepositBoxStats = new HashSet<>();
final List<SafeDepositBoxRecord> safeDepositBoxRecords = safeDepositBoxDao.getSafeDepositBoxes(1000, 0);

safeDepositBoxRecords.forEach(r -> {
final List<UserGroupRecord> userGroupOwnerRecords =
userGroupDao.getUserGroupsByRole(r.getId(), ownerRole.get().getId());

if (userGroupOwnerRecords.size() != 1) {
throw ApiException.newBuilder()
.withApiErrors(DefaultApiError.SDB_TOO_MANY_OWNERS)
.withExceptionMessage("SDB has more than one owner!")
.build();
}

final SafeDepositBoxStats sdbStats = new SafeDepositBoxStats();
sdbStats.setName(r.getName());
sdbStats.setOwner(userGroupOwnerRecords.get(0).getName());
sdbStats.setLastUpdatedTs(r.getLastUpdatedTs());
safeDepositBoxStats.add(sdbStats);
});

return new Stats().setSafeDepositBoxStats(safeDepositBoxStats).setGeneratedTs(dateTimeSupplier.get());
}

/**
* Method for retrieving meta data about SDBs sorted by created date.
*
Expand Down
Loading

0 comments on commit 03670d5

Please sign in to comment.