use of keywhiz.api.automation.v2.CreateClientRequestV2 in project keywhiz by square.
the class ClientResourceTest method modifyClient_success.
@Ignore
@Test
public void modifyClient_success() throws Exception {
// Create sample client
create(CreateClientRequestV2.builder().name("client9").build());
ClientDetailResponseV2 originalClient = lookup("client9");
// Modify client
ModifyClientRequestV2 request = ModifyClientRequestV2.forName("client9b");
ClientDetailResponseV2 clientDetail = modify("client9", request);
assertThat(clientDetail.name()).isEqualTo("client9b");
assertThat(clientDetail).isEqualToIgnoringGivenFields(originalClient, "name", "updateDate");
assertThat(clientDetail.updatedAtSeconds()).isGreaterThan(originalClient.updatedAtSeconds());
}
use of keywhiz.api.automation.v2.CreateClientRequestV2 in project keywhiz by square.
the class ClientResourceTest method modifyClientGroups_success.
@Test
public void modifyClientGroups_success() throws Exception {
// Create sample client and groups
createGroup("group8a");
createGroup("group8b");
createGroup("group8c");
create(CreateClientRequestV2.builder().name("client8").groups("group8a", "group8b").build());
// Modify client
ModifyGroupsRequestV2 request = ModifyGroupsRequestV2.builder().addGroups("group8c", "non-existent1").removeGroups("group8a", "non-existent2").build();
List<String> groups = modifyGroups("client8", request);
assertThat(groups).containsOnly("group8b", "group8c");
}
use of keywhiz.api.automation.v2.CreateClientRequestV2 in project keywhiz by square.
the class ClientResourceTest method clientInfo_groupExists.
@Test
public void clientInfo_groupExists() throws Exception {
// Sample client
create(CreateClientRequestV2.builder().name("client3").build());
ClientDetailResponseV2 clientDetail = lookup("client3");
assertThat(clientDetail.name()).isEqualTo("client3");
assertThat(clientDetail.description()).isEmpty();
assertThat(clientDetail.createdBy()).isEqualTo(clientDetail.updatedBy()).isEqualTo("client");
}
use of keywhiz.api.automation.v2.CreateClientRequestV2 in project keywhiz by square.
the class ClientResource method createClient.
/**
* Creates a client and assigns to given groups
*
* @excludeParams automationClient
* @param request JSON request to create a client
*
* @responseMessage 201 Created client and assigned to given groups
* @responseMessage 409 Client already exists
*/
@Timed
@ExceptionMetered
@POST
@Consumes(APPLICATION_JSON)
public Response createClient(@Auth AutomationClient automationClient, @Valid CreateClientRequestV2 request) {
String creator = automationClient.getName();
String client = request.name();
clientDAOReadWrite.getClient(client).ifPresent((c) -> {
logger.info("Automation ({}) - Client {} already exists", creator, client);
throw new ConflictException("Client name already exists.");
});
// Creates new client record
long clientId = clientDAOReadWrite.createClient(client, creator, request.description());
auditLog.recordEvent(new Event(Instant.now(), EventTag.CLIENT_CREATE, creator, client));
// Enrolls client in any requested groups
groupsToGroupIds(request.groups()).forEach((maybeGroupId) -> maybeGroupId.ifPresent((groupId) -> aclDAOReadWrite.findAndEnrollClient(clientId, groupId, auditLog, creator, new HashMap<>())));
URI uri = UriBuilder.fromResource(ClientResource.class).path(client).build();
return Response.created(uri).build();
}
use of keywhiz.api.automation.v2.CreateClientRequestV2 in project keywhiz by square.
the class ClientResourceTest method createClient_duplicate.
@Test
public void createClient_duplicate() throws Exception {
CreateClientRequestV2 request = CreateClientRequestV2.builder().name("client2").build();
// Initial request OK
create(request);
// Duplicate request fails
Response httpResponse = create(request);
assertThat(httpResponse.code()).isEqualTo(409);
}
Aggregations