use of keywhiz.api.GroupDetailResponse in project keywhiz by square.
the class Printing method printGroupWithDetails.
public void printGroupWithDetails(Group group) {
System.out.println(group.getName());
GroupDetailResponse groupDetails;
try {
groupDetails = keywhizClient.groupDetailsForId(group.getId());
} catch (IOException e) {
throw Throwables.propagate(e);
}
System.out.println("\tClients:");
groupDetails.getClients().stream().sorted(Comparator.comparing(Client::getName)).forEach(c -> System.out.println(INDENT + c.getName()));
System.out.println("\tSecrets:");
groupDetails.getSecrets().stream().sorted(Comparator.comparing(SanitizedSecret::name)).forEach(s -> System.out.println(INDENT + SanitizedSecret.displayName(s)));
System.out.println("\tMetadata:");
if (!groupDetails.getMetadata().isEmpty()) {
String metadata;
try {
metadata = new ObjectMapper().writeValueAsString(groupDetails.getMetadata());
} catch (JsonProcessingException e) {
throw Throwables.propagate(e);
}
System.out.println(INDENT + metadata);
}
if (!groupDetails.getDescription().isEmpty()) {
System.out.println("\tDescription:");
System.out.println(INDENT + groupDetails.getDescription());
}
if (!groupDetails.getCreatedBy().isEmpty()) {
System.out.println("\tCreated by:");
System.out.println(INDENT + groupDetails.getCreatedBy());
}
System.out.println("\tCreated at:");
Date d = new Date(groupDetails.getCreationDate().toEpochSecond() * 1000);
System.out.println(INDENT + DateFormat.getDateTimeInstance().format(d));
if (!groupDetails.getUpdatedBy().isEmpty()) {
System.out.println("\tUpdated by:");
System.out.println(INDENT + groupDetails.getUpdatedBy());
}
System.out.println("\tUpdated at:");
d = new Date(groupDetails.getUpdateDate().toEpochSecond() * 1000);
System.out.println(INDENT + DateFormat.getDateTimeInstance().format(d));
}
use of keywhiz.api.GroupDetailResponse in project keywhiz by square.
the class AutomationGroupResource method getGroupByName.
/**
* Retrieve Group by a specified name, or all Groups if no name given
*
* @param name the name of the Group to retrieve, if provided
* @excludeParams automationClient
* @optionalParams name
* @description Returns a single Group or a set of all Groups
* @responseMessage 200 Found and retrieved Group(s)
* @responseMessage 404 Group with given name not found (if name provided)
*/
@Timed
@ExceptionMetered
@GET
public Response getGroupByName(@Auth AutomationClient automationClient, @QueryParam("name") Optional<String> name) {
if (name.isPresent()) {
Group group = groupDAO.getGroup(name.get()).orElseThrow(NotFoundException::new);
ImmutableList<Client> clients = ImmutableList.copyOf(aclDAO.getClientsFor(group));
ImmutableList<SanitizedSecret> sanitizedSecrets = ImmutableList.copyOf(aclDAO.getSanitizedSecretsFor(group));
return Response.ok().entity(GroupDetailResponse.fromGroup(group, sanitizedSecrets, clients)).build();
}
ImmutableList<SanitizedSecret> emptySecrets = ImmutableList.of();
ImmutableList<Client> emptyClients = ImmutableList.of();
List<GroupDetailResponse> groups = groupDAO.getGroups().stream().map((g) -> GroupDetailResponse.fromGroup(g, emptySecrets, emptyClients)).collect(toList());
return Response.ok().entity(groups).build();
}
use of keywhiz.api.GroupDetailResponse in project keywhiz by square.
the class AutomationGroupResourceTest method findGroupById.
@Test
public void findGroupById() {
Group group = new Group(50, "testGroup", "testing group", now, "automation client", now, "automation client", ImmutableMap.of("app", "keywhiz"));
when(groupDAO.getGroupById(50)).thenReturn(Optional.of(group));
when(aclDAO.getClientsFor(group)).thenReturn(ImmutableSet.of());
when(aclDAO.getSanitizedSecretsFor(group)).thenReturn(ImmutableSet.of());
GroupDetailResponse expectedResponse = GroupDetailResponse.fromGroup(group, ImmutableList.of(), ImmutableList.of());
GroupDetailResponse response = resource.getGroupById(automation, new LongParam("50"));
assertThat(response).isEqualTo(expectedResponse);
}
use of keywhiz.api.GroupDetailResponse in project keywhiz by square.
the class AutomationGroupResourceTest method groupIncludesClientsAndSecrets.
@Test
public void groupIncludesClientsAndSecrets() {
Group group = new Group(50, "testGroup", "testing group", now, "automation client", now, "automation client", ImmutableMap.of("app", "keywhiz"));
Client groupClient = new Client(1, "firstClient", "Group client", now, "test", now, "test", null, true, true);
SanitizedSecret firstGroupSecret = SanitizedSecret.of(1, "name1", "checksum", "desc", now, "test", now, "test", null, "", null, 1136214245, 125L);
SanitizedSecret secondGroupSecret = SanitizedSecret.of(2, "name2", "checksum", "desc", now, "test", now, "test", null, "", null, 1136214245, 250L);
when(groupDAO.getGroup("testGroup")).thenReturn(Optional.of(group));
when(aclDAO.getClientsFor(group)).thenReturn(ImmutableSet.of(groupClient));
when(aclDAO.getSanitizedSecretsFor(group)).thenReturn(ImmutableSet.of(firstGroupSecret, secondGroupSecret));
GroupDetailResponse expectedResponse = GroupDetailResponse.fromGroup(group, ImmutableList.of(firstGroupSecret, secondGroupSecret), ImmutableList.of(groupClient));
Response response = resource.getGroupByName(automation, Optional.of("testGroup"));
assertThat(response.getEntity()).isEqualTo(expectedResponse);
}
use of keywhiz.api.GroupDetailResponse in project keywhiz by square.
the class AutomationGroupResourceTest method findGroupByName.
@Test
public void findGroupByName() {
Group group = new Group(50, "testGroup", "testing group", now, "automation client", now, "automation client", ImmutableMap.of("app", "keywhiz"));
when(groupDAO.getGroup("testGroup")).thenReturn(Optional.of(group));
when(aclDAO.getClientsFor(group)).thenReturn(ImmutableSet.of());
when(aclDAO.getSanitizedSecretsFor(group)).thenReturn(ImmutableSet.of());
GroupDetailResponse expectedResponse = GroupDetailResponse.fromGroup(group, ImmutableList.of(), ImmutableList.of());
Response response = resource.getGroupByName(automation, Optional.of("testGroup"));
assertThat(response.getEntity()).isEqualTo(expectedResponse);
}
Aggregations