use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class AutomationGroupResource method deleteGroup.
/**
* Deletes a group
*
* @param automationClient the client with automation access performing this operation
* @param groupId the ID of the group to delete
* @return 200 if the group was removed successfully, 404 if the group was not found
*
* description Deletes a single group by id
* responseMessage 200 Deleted group
* responseMessage 404 Group not found by id
*/
@Timed
@ExceptionMetered
@DELETE
@Path("{groupId}")
public Response deleteGroup(@Auth AutomationClient automationClient, @PathParam("groupId") LongParam groupId) {
Group group = groupDAO.getGroupById(groupId.get()).orElseThrow(NotFoundException::new);
groupDAO.deleteGroup(group);
Map<String, String> extraInfo = new HashMap<>();
extraInfo.put("deprecated", "true");
auditLog.recordEvent(new Event(Instant.now(), EventTag.GROUP_DELETE, automationClient.getName(), group.getName(), extraInfo));
return Response.ok().build();
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class AutomationGroupResource method getGroupById.
/**
* Retrieve Group by ID
*
* @param automationClient the client with automation access performing this operation
* @param groupId the ID of the group to retrieve
* @return details on the specified group
*
* description Returns a single Group if found
* responseMessage 200 Found and retrieved Group with given ID
* responseMessage 404 Group with given ID not Found
*/
@Timed
@ExceptionMetered
@GET
@Path("{groupId}")
public GroupDetailResponse getGroupById(@Auth AutomationClient automationClient, @PathParam("groupId") LongParam groupId) {
Group group = groupDAO.getGroupById(groupId.get()).orElseThrow(NotFoundException::new);
ImmutableList<Client> clients = ImmutableList.copyOf(aclDAO.getClientsFor(group));
ImmutableList<SanitizedSecret> sanitizedSecrets = ImmutableList.copyOf(aclDAO.getSanitizedSecretsFor(group));
return GroupDetailResponse.fromGroup(group, sanitizedSecrets, clients);
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class SecretDeliveryResource method getSecret.
/**
* Retrieve Secret by name
*
* @param secretName the name of the Secret to retrieve
* @param client the client performing the retrieval
* @return the secret with the specified name, if present and accessible to the client
*
* responseMessage 200 Found and retrieved Secret with given name
* responseMessage 403 Secret is not assigned to Client
* responseMessage 404 Secret with given name not found
* responseMessage 500 Secret response could not be generated for given Secret
*/
@Timed
@ExceptionMetered
@GET
public SecretDeliveryResponse getSecret(@NotEmpty @PathParam("secretName") String secretName, @Auth Client client) {
Optional<SanitizedSecret> sanitizedSecret = aclDAO.getSanitizedSecretFor(client, secretName);
Optional<Secret> secret = secretController.getSecretByName(secretName);
if (!sanitizedSecret.isPresent()) {
boolean clientExists = clientDAO.getClientByName(client.getName()).isPresent();
boolean secretExists = secret.isPresent();
if (clientExists && secretExists) {
throw new ForbiddenException(format("Access denied: %s at '%s' by '%s'", client.getName(), "/secret/" + secretName, client));
} else {
if (clientExists) {
logger.info("Client {} requested unknown secret {}", client.getName(), secretName);
}
throw new NotFoundException();
}
}
logger.info("Client {} granted access to {}.", client.getName(), secretName);
try {
return SecretDeliveryResponse.fromSecret(secret.get());
} catch (IllegalArgumentException e) {
logger.error(format("Failed creating response for secret %s", secretName), e);
throw new InternalServerErrorException();
}
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class AutomationSecretResource method createSecret.
/**
* Create secret
*
* @param automationClient the client with automation access performing this operation
* @param request JSON request to formulate the secret
* @return details on the newly created secret, or 409 if the secret name already exists
*
* 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)).withOwnerName(request.owner);
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
*
* @param automationClient the client with automation access performing this operation
* @param secretName the name of the secret series to delete
* @return 200 if the deletion is successful, or 404 if the given secret was not found
*
* 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();
}
Aggregations