Search in sources :

Example 11 with AutomationClient

use of keywhiz.api.model.AutomationClient in project keywhiz by square.

the class AutomationClientResource method deleteClient.

/**
   * Deletes a client
   *
   * @param clientId the ID of the client to delete
   * @excludeParams automationClient
   * @description Deletes a single client by id
   * @responseMessage 200 Deleted client
   * @responseMessage 404 Client not found by id
   */
@Timed
@ExceptionMetered
@DELETE
@Path("{clientId}")
public Response deleteClient(@Auth AutomationClient automationClient, @PathParam("clientId") LongParam clientId) {
    Client client = clientDAO.getClientById(clientId.get()).orElseThrow(NotFoundException::new);
    clientDAO.deleteClient(client);
    Map<String, String> extraInfo = new HashMap<>();
    extraInfo.put("deprecated", "true");
    auditLog.recordEvent(new Event(Instant.now(), EventTag.CLIENT_CREATE, automationClient.getName(), client.getName(), extraInfo));
    return Response.ok().build();
}
Also used : HashMap(java.util.HashMap) NotFoundException(javax.ws.rs.NotFoundException) Event(keywhiz.log.Event) AutomationClient(keywhiz.api.model.AutomationClient) Client(keywhiz.api.model.Client) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Timed(com.codahale.metrics.annotation.Timed) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Example 12 with AutomationClient

use of keywhiz.api.model.AutomationClient in project keywhiz by square.

the class AutomationClientResource method findClientById.

/**
   * Retrieve Client by ID
   *
   * @param clientId the ID of the Client to retrieve
   * @excludeParams automationClient
   * @description Returns a single Client if found
   * @responseMessage 200 Found and retrieved Client with given ID
   * @responseMessage 404 Client with given ID not Found
   */
@Timed
@ExceptionMetered
@GET
@Path("{clientId}")
public Response findClientById(@Auth AutomationClient automationClient, @PathParam("clientId") LongParam clientId) {
    logger.info("Automation ({}) - Looking up an ID {}", automationClient.getName(), clientId);
    Client client = clientDAO.getClientById(clientId.get()).orElseThrow(NotFoundException::new);
    ImmutableList<Group> groups = ImmutableList.copyOf(aclDAO.getGroupsFor(client));
    return Response.ok().entity(ClientDetailResponse.fromClient(client, groups, ImmutableList.of())).build();
}
Also used : Group(keywhiz.api.model.Group) NotFoundException(javax.ws.rs.NotFoundException) AutomationClient(keywhiz.api.model.AutomationClient) Client(keywhiz.api.model.Client) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ExceptionMetered(com.codahale.metrics.annotation.ExceptionMetered)

Aggregations

ExceptionMetered (com.codahale.metrics.annotation.ExceptionMetered)12 Timed (com.codahale.metrics.annotation.Timed)12 AutomationClient (keywhiz.api.model.AutomationClient)12 NotFoundException (javax.ws.rs.NotFoundException)11 Path (javax.ws.rs.Path)11 Client (keywhiz.api.model.Client)10 Event (keywhiz.log.Event)9 HashMap (java.util.HashMap)8 Consumes (javax.ws.rs.Consumes)8 DELETE (javax.ws.rs.DELETE)8 GET (javax.ws.rs.GET)8 POST (javax.ws.rs.POST)8 Group (keywhiz.api.model.Group)8 Produces (javax.ws.rs.Produces)7 ConflictException (keywhiz.service.exceptions.ConflictException)7 Auth (io.dropwizard.auth.Auth)6 Instant (java.time.Instant)6 Optional (java.util.Optional)6 Inject (javax.inject.Inject)6 Valid (javax.validation.Valid)6