use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class ClientResource method modifyClient.
/**
* Modify a client
*
* @param currentName Client name
* @param request JSON request to modify the client
* @return the updated client
* <p>
* responseMessage 201 Client updated
* <p>
* responseMessage 404 Client not found
*/
@Timed
@ExceptionMetered
@POST
@Path("{name}")
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
public ClientDetailResponseV2 modifyClient(@Auth AutomationClient automationClient, @PathParam("name") String currentName, @Valid ModifyClientRequestV2 request) {
Client client = clientDAOReadWrite.getClientByName(currentName).orElseThrow(NotFoundException::new);
String newName = request.name();
// TODO: implement change client (name, updatedAt, updatedBy)
throw new NotImplementedException(format("Need to implement mutation methods in DAO to rename %s to %s", client.getName(), newName));
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class GroupResource method groupInfo.
/**
* Retrieve information on a group
*
* @param name Group name
*
* responseMessage 200 Group information retrieved
* responseMessage 404 Group not found
*/
@Timed
@ExceptionMetered
@GET
@Path("{name}")
@Produces(APPLICATION_JSON)
public GroupDetailResponseV2 groupInfo(@Auth AutomationClient automationClient, @PathParam("name") String name) {
Group group = groupDAOReadOnly.getGroup(name).orElseThrow(NotFoundException::new);
Set<String> secrets = aclDAOReadOnly.getSecretSeriesFor(group).stream().map(SecretSeries::name).collect(toSet());
Set<String> clients = aclDAOReadOnly.getClientsFor(group).stream().map(Client::getName).collect(toSet());
return GroupDetailResponseV2.builder().group(group).secrets(secrets).clients(clients).build();
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class GroupResource method secretsWithGroupsForGroup.
/**
* Retrieve metadata for secrets in a particular group, including all
* groups linked to each secret.
*
* @param name Group name
*
* responseMessage 200 Group information retrieved
* responseMessage 404 Group not found
*/
@Timed
@ExceptionMetered
@GET
@Path("{name}/secretsandgroups")
@Produces(APPLICATION_JSON)
public Set<SanitizedSecretWithGroups> secretsWithGroupsForGroup(@Auth AutomationClient automationClient, @PathParam("name") String name) {
Group group = groupDAOReadOnly.getGroup(name).orElseThrow(NotFoundException::new);
Set<SanitizedSecret> secrets = aclDAOReadOnly.getSanitizedSecretsFor(group);
Map<Long, List<Group>> groupsForSecrets = aclDAOReadOnly.getGroupsForSecrets(secrets.stream().map(SanitizedSecret::id).collect(Collectors.toUnmodifiableSet()));
return secrets.stream().map(s -> {
List<Group> groups = groupsForSecrets.get(s.id());
if (groups == null) {
groups = ImmutableList.of();
}
return SanitizedSecretWithGroups.of(s, groups);
}).collect(Collectors.toUnmodifiableSet());
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class SecretResource method createOrUpdateSecret.
/**
* Creates or updates (if it exists) a secret.
*
* @param request JSON request to create a secret
*
* responseMessage 201 Created secret and assigned to given groups
*/
@Timed
@ExceptionMetered
@Path("{name}")
@POST
@Consumes(APPLICATION_JSON)
public Response createOrUpdateSecret(@Auth AutomationClient automationClient, @PathParam("name") String name, @Valid CreateOrUpdateSecretRequestV2 request) {
SecretBuilder builder = secretController.builder(name, request.content(), automationClient.getName(), request.expiry()).withDescription(request.description()).withMetadata(request.metadata()).withType(request.type());
builder.createOrUpdate();
Map<String, String> extraInfo = new HashMap<>();
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_CREATEORUPDATE, automationClient.getName(), name, extraInfo));
UriBuilder uriBuilder = UriBuilder.fromResource(SecretResource.class).path(name);
return Response.created(uriBuilder.build()).build();
}
use of com.codahale.metrics.annotation.ExceptionMetered in project keywhiz by square.
the class ClientsResource method createClient.
/**
* Create Client
*
* @param user the admin user creating this client
* @param createClientRequest the JSON client request used to formulate the Client
* @return 200 if the client is created successfully, 409 if it already exists
* <p>
* description Creates a Client with the name from a valid client request. Used by Keywhiz CLI and
* the web ui.
* <p>
* responseMessage 200 Successfully created Client
* <p>
* responseMessage 409 Client with given name already exists
*/
@Timed
@ExceptionMetered
@POST
@Consumes(APPLICATION_JSON)
public Response createClient(@Auth User user, @Valid CreateClientRequestV2 createClientRequest) {
logger.info("User '{}' creating client '{}'.", user, createClientRequest.name());
long clientId;
try {
clientId = clientDAO.createClient(createClientRequest.name(), user.getName(), createClientRequest.description(), new URI(createClientRequest.spiffeId()));
} catch (DataAccessException | URISyntaxException e) {
logger.warn("Cannot create client {}: {}", createClientRequest.name(), e);
throw new ConflictException("Conflict creating client.");
}
URI uri = UriBuilder.fromResource(ClientsResource.class).path("{clientId}").build(clientId);
Response response = Response.created(uri).entity(clientDetailResponseFromId(clientId)).build();
if (response.getStatus() == HttpStatus.SC_CREATED) {
auditLog.recordEvent(new Event(Instant.now(), EventTag.CLIENT_CREATE, user.getName(), createClientRequest.name()));
}
return response;
}
Aggregations