use of keywhiz.api.ClientDetailResponse in project keywhiz by square.
the class AutomationClientResource method findClient.
/**
* Retrieve Client by a specified name, or all Clients if no name given
*
* @param automationClient the client with automation access performing this operation
* @param name the name of the Client to retrieve, if provided
* @return the specified client if found, or all clients if name omitted
*
* optionalParams name
* description Returns a single Client or a set of all Clients
* responseMessage 200 Found and retrieved Client(s)
* responseMessage 404 Client with given name not found (if name provided)
*/
@Timed
@ExceptionMetered
@GET
public Response findClient(@Auth AutomationClient automationClient, @QueryParam("name") Optional<String> name) {
logger.info("Automation ({}) - Looking up a name {}", automationClient.getName(), name);
if (name.isPresent()) {
Client client = clientDAO.getClientByName(name.get()).orElseThrow(NotFoundException::new);
ImmutableList<Group> groups = ImmutableList.copyOf(aclDAO.getGroupsFor(client));
return Response.ok().entity(ClientDetailResponse.fromClient(client, groups, ImmutableList.of())).build();
}
List<ClientDetailResponse> clients = clientDAO.getClients().stream().map(c -> ClientDetailResponse.fromClient(c, ImmutableList.copyOf(aclDAO.getGroupsFor(c)), ImmutableList.of())).collect(toList());
return Response.ok().entity(clients).build();
}
use of keywhiz.api.ClientDetailResponse in project keywhiz by square.
the class AutomationClientResourceTest method createNewClient.
@Test
public void createNewClient() {
Client client = new Client(543L, "client", "2nd client", null, now, "test", now, "test", null, null, true, false);
CreateClientRequest request = new CreateClientRequest("client");
when(clientDAO.getClientByName("client")).thenReturn(Optional.empty());
when(clientDAO.createClient("client", automation.getName(), "", null)).thenReturn(543L);
when(clientDAO.getClientById(543L)).thenReturn(Optional.of(client));
when(aclDAO.getGroupsFor(client)).thenReturn(ImmutableSet.of());
ClientDetailResponse response = ClientDetailResponse.fromClient(client, ImmutableList.of(), ImmutableList.of());
ClientDetailResponse response1 = resource.createClient(automation, request);
assertThat(response.name).isEqualTo(response1.name);
}
use of keywhiz.api.ClientDetailResponse in project keywhiz by square.
the class AutomationClientResourceTest method createNewClientAlreadyExists.
@Test
public void createNewClientAlreadyExists() {
Client client = new Client(543L, "client", "2nd client", null, now, "test", now, "test", null, null, true, false);
CreateClientRequest request = new CreateClientRequest("client");
when(clientDAO.getClientByName("client")).thenReturn(Optional.empty());
when(clientDAO.createClient("client", automation.getName(), "", null)).thenReturn(543L);
when(clientDAO.getClientById(543L)).thenReturn(Optional.of(client));
ClientDetailResponse response = ClientDetailResponse.fromClient(client, ImmutableList.of(), ImmutableList.of());
ClientDetailResponse response1 = resource.createClient(automation, request);
assertThat(response.name).isEqualTo(response1.name);
}
use of keywhiz.api.ClientDetailResponse in project keywhiz by square.
the class ClientsResourceTest method includesTheClient.
@Test
public void includesTheClient() {
when(clientDAO.getClientById(1)).thenReturn(Optional.of(client));
when(aclDAO.getGroupsFor(client)).thenReturn(Collections.emptySet());
when(aclDAO.getSanitizedSecretsFor(client)).thenReturn(ImmutableSet.of());
ClientDetailResponse response = resource.getClient(user, new LongParam("1"));
assertThat(response.id).isEqualTo(client.getId());
assertThat(response.name).isEqualTo(client.getName());
assertThat(response.description).isEqualTo(client.getDescription());
assertThat(response.creationDate).isEqualTo(client.getCreatedAt());
assertThat(response.createdBy).isEqualTo(client.getCreatedBy());
assertThat(response.updateDate).isEqualTo(client.getUpdatedAt());
assertThat(response.updatedBy).isEqualTo(client.getUpdatedBy());
}
use of keywhiz.api.ClientDetailResponse in project keywhiz by square.
the class ClientsResourceTest method handlesNoAssociations.
@Test
public void handlesNoAssociations() {
when(clientDAO.getClientById(1)).thenReturn(Optional.of(client));
when(aclDAO.getGroupsFor(client)).thenReturn(Collections.emptySet());
when(aclDAO.getSanitizedSecretsFor(client)).thenReturn(ImmutableSet.of());
ClientDetailResponse response = resource.getClient(user, new LongParam("1"));
assertThat(response.groups).isEmpty();
assertThat(response.secrets).isEmpty();
}
Aggregations