use of keywhiz.api.automation.v2.PartialUpdateSecretRequestV2 in project keywhiz by square.
the class KeywhizClient method updateSecret.
public SecretDetailResponse updateSecret(String name, boolean descriptionPresent, String description, boolean contentPresent, byte[] content, boolean metadataPresent, ImmutableMap<String, String> metadata, boolean expiryPresent, long expiry) throws IOException {
checkArgument(!name.isEmpty());
String b64Content = Base64.getEncoder().encodeToString(content);
PartialUpdateSecretRequestV2 request = PartialUpdateSecretRequestV2.builder().descriptionPresent(descriptionPresent).description(description).contentPresent(contentPresent).content(b64Content).metadataPresent(metadataPresent).metadata(metadata).expiryPresent(expiryPresent).expiry(expiry).build();
String response = httpPost(baseUrl.resolve(format("/admin/secrets/%s/partialupdate", name)), request);
return mapper.readValue(response, SecretDetailResponse.class);
}
use of keywhiz.api.automation.v2.PartialUpdateSecretRequestV2 in project keywhiz by square.
the class SecretDAOTest method partialUpdateSecretWhenSecretSeriesDoesNotExist.
//---------------------------------------------------------------------------------------
// updateSecret
//---------------------------------------------------------------------------------------
@Test(expected = NotFoundException.class)
public void partialUpdateSecretWhenSecretSeriesDoesNotExist() {
String name = "newSecret";
String content = "c2VjcmV0MQ==";
PartialUpdateSecretRequestV2 request = PartialUpdateSecretRequestV2.builder().contentPresent(true).content(content).build();
secretDAO.partialUpdateSecret(name, "test", request);
}
use of keywhiz.api.automation.v2.PartialUpdateSecretRequestV2 in project keywhiz by square.
the class SecretDAOTest method partialUpdateSecretWhenSecretContentDoesNotExist.
@Test(expected = NotFoundException.class)
public void partialUpdateSecretWhenSecretContentDoesNotExist() {
String name = "newSecret";
String content = "c2VjcmV0MQ==";
PartialUpdateSecretRequestV2 request = PartialUpdateSecretRequestV2.builder().contentPresent(true).content(content).build();
jooqContext.insertInto(SECRETS).set(SECRETS.ID, 12L).set(SECRETS.NAME, name).set(SECRETS.DESCRIPTION, series1.description()).set(SECRETS.CREATEDBY, series1.createdBy()).set(SECRETS.CREATEDAT, series1.createdAt().toEpochSecond()).set(SECRETS.UPDATEDBY, series1.updatedBy()).set(SECRETS.UPDATEDAT, series1.updatedAt().toEpochSecond()).set(SECRETS.CURRENT, 12L).execute();
secretDAO.partialUpdateSecret(name, "test", request);
}
use of keywhiz.api.automation.v2.PartialUpdateSecretRequestV2 in project keywhiz by square.
the class SecretsResourceTest method partialUpdateSecret.
@Test
public void partialUpdateSecret() throws Exception {
when(secretController.getSecretById(secret.getId())).thenReturn(Optional.of(secret));
PartialUpdateSecretRequestV2 req = PartialUpdateSecretRequestV2.builder().description(secret.getDescription()).descriptionPresent(true).metadata(ImmutableMap.of("owner", "keywhizAdmin")).metadataPresent(true).expiry(1487268151L).expiryPresent(true).type("test").typePresent(true).content(secret.getSecret()).contentPresent(true).build();
when(secretDAO.partialUpdateSecret(eq(secret.getName()), any(), eq(req))).thenReturn(secret.getId());
Response response = resource.partialUpdateSecret(user, secret.getName(), req);
assertThat(response.getStatus()).isEqualTo(201);
assertThat(response.getMetadata().get(HttpHeaders.LOCATION)).containsExactly(new URI("/admin/secrets/" + secret.getName() + "/partialupdate"));
}
use of keywhiz.api.automation.v2.PartialUpdateSecretRequestV2 in project keywhiz by square.
the class SecretDAOTest method partialUpdateSecretWhenSecretCurrentIsNotSet.
@Test(expected = NotFoundException.class)
public void partialUpdateSecretWhenSecretCurrentIsNotSet() {
String content = "c2VjcmV0MQ==";
PartialUpdateSecretRequestV2 request = PartialUpdateSecretRequestV2.builder().contentPresent(true).content(content).build();
secretDAO.partialUpdateSecret(series3.name(), "test", request);
}
Aggregations