use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class AutomationSecretAccessResource method allowAccess.
/**
* Assign Secret to Group
*
* @excludeParams automationClient
* @param secretId the ID of the Secret to assign
* @param groupId the ID of the Group to be assigned to
*
* @description Assigns the Secret specified by the secretID to the Group specified by the groupID
* @responseMessage 200 Successfully enrolled Secret in Group
* @responseMessage 404 Could not find Secret or Group
*/
@Timed
@ExceptionMetered
@PUT
public Response allowAccess(@Auth AutomationClient automationClient, @PathParam("secretId") LongParam secretId, @PathParam("groupId") LongParam groupId) {
logger.info("Client '{}' allowing groupId={} access to secretId={}", automationClient, secretId, groupId);
try {
Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("deprecated", "true");
aclDAO.findAndAllowAccess(secretId.get(), groupId.get(), auditLog, automationClient.getName(), extraInfo);
} catch (IllegalStateException e) {
throw new NotFoundException();
}
return Response.ok().build();
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class AutomationSecretAccessResource method disallowAccess.
/**
* Remove Secret from Group
*
* @excludeParams automationClient
* @param secretId the ID of the Secret to unassign
* @param groupId the ID of the Group to be removed from
*
* @description Unassigns the Secret specified by the secretID from the Group specified by the groupID
* @responseMessage 200 Successfully removed Secret from Group
* @responseMessage 404 Could not find Secret or Group
*/
@Timed
@ExceptionMetered
@DELETE
public Response disallowAccess(@Auth AutomationClient automationClient, @PathParam("secretId") LongParam secretId, @PathParam("groupId") LongParam groupId) {
logger.info("Client '{}' disallowing groupId={} access to secretId={}", automationClient, secretId, groupId);
try {
Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("deprecated", "true");
aclDAO.findAndRevokeAccess(secretId.get(), groupId.get(), auditLog, automationClient.getName(), extraInfo);
} catch (IllegalStateException e) {
throw new NotFoundException();
}
return Response.ok().build();
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class AutomationSecretResource method createSecret.
/**
* Create secret
*
* @excludeParams automationClient
* @param request JSON request to formulate the secret
*
* @description Creates a secret with the name, content, and metadata from a valid secret request
* @responseMessage 200 Successfully created secret
* @responseMessage 409 Secret with given name already exists
*/
@Timed
@ExceptionMetered
@POST
@Consumes(APPLICATION_JSON)
public AutomationSecretResponse createSecret(@Auth AutomationClient automationClient, @Valid CreateSecretRequest request) {
SecretController.SecretBuilder builder = secretController.builder(request.name, request.content, automationClient.getName(), request.expiry).withDescription(nullToEmpty(request.description));
if (request.metadata != null) {
builder.withMetadata(request.metadata);
}
Secret secret;
try {
secret = builder.create();
} catch (DataAccessException e) {
logger.info(format("Cannot create secret %s", request.name), e);
throw new ConflictException(format("Cannot create secret %s.", request.name));
}
ImmutableList<Group> groups = ImmutableList.copyOf(aclDAO.getGroupsFor(secret));
Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("deprecated", "true");
if (request.description != null) {
extraInfo.put("description", request.description);
}
if (request.metadata != null) {
extraInfo.put("metadata", request.metadata.toString());
}
extraInfo.put("expiry", Long.toString(request.expiry));
auditLog.recordEvent(new Event(Instant.now(), EventTag.SECRET_CREATE, automationClient.getName(), request.name, extraInfo));
return AutomationSecretResponse.fromSecret(secret, groups);
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class AutomationSecretResource method deleteSecretSeries.
/**
* Deletes all versions of a secret series
*
* @excludeParams automationClient
* @param secretName the name of the secret series to delete
*
* @description Deletes all versions of a secret series. This will delete a single secret ID.
* @responseMessage 200 Deleted secret series
* @responseMessage 404 Secret series not Found
*/
@Path("{secretName}")
@Timed
@ExceptionMetered
@DELETE
public Response deleteSecretSeries(@Auth AutomationClient automationClient, @PathParam("secretName") String secretName) {
Secret secret = secretController.getSecretByName(secretName).orElseThrow(() -> new NotFoundException("Secret series not found."));
Set<String> groups = aclDAO.getGroupsFor(secret).stream().map(Group::getName).collect(toSet());
secretDAO.deleteSecretsByName(secretName);
// Record all groups to which this secret belongs, so they can be restored manually if necessary
Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("deprecated", "true");
extraInfo.put("groups", groups.toString());
extraInfo.put("current version", secret.getVersion().toString());
auditLog.recordEvent(new Event(Instant.now(), EventTag.SECRET_DELETE, automationClient.getName(), secretName, extraInfo));
return Response.ok().build();
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class ClientResource method createClient.
/**
* Creates a client and assigns to given groups
*
* @excludeParams automationClient
* @param request JSON request to create a client
*
* @responseMessage 201 Created client and assigned to given groups
* @responseMessage 409 Client already exists
*/
@Timed
@ExceptionMetered
@POST
@Consumes(APPLICATION_JSON)
public Response createClient(@Auth AutomationClient automationClient, @Valid CreateClientRequestV2 request) {
String creator = automationClient.getName();
String client = request.name();
clientDAOReadWrite.getClient(client).ifPresent((c) -> {
logger.info("Automation ({}) - Client {} already exists", creator, client);
throw new ConflictException("Client name already exists.");
});
// Creates new client record
long clientId = clientDAOReadWrite.createClient(client, creator, request.description());
auditLog.recordEvent(new Event(Instant.now(), EventTag.CLIENT_CREATE, creator, client));
// Enrolls client in any requested groups
groupsToGroupIds(request.groups()).forEach((maybeGroupId) -> maybeGroupId.ifPresent((groupId) -> aclDAOReadWrite.findAndEnrollClient(clientId, groupId, auditLog, creator, new HashMap<>())));
URI uri = UriBuilder.fromResource(ClientResource.class).path(client).build();
return Response.created(uri).build();
}
Aggregations