Search in sources :

Example 1 with PartialUpdateSecretRequestV2

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);
}
Also used : PartialUpdateSecretRequestV2(keywhiz.api.automation.v2.PartialUpdateSecretRequestV2)

Example 2 with PartialUpdateSecretRequestV2

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);
}
Also used : PartialUpdateSecretRequestV2(keywhiz.api.automation.v2.PartialUpdateSecretRequestV2) Test(org.junit.Test)

Example 3 with PartialUpdateSecretRequestV2

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);
}
Also used : PartialUpdateSecretRequestV2(keywhiz.api.automation.v2.PartialUpdateSecretRequestV2) Test(org.junit.Test)

Example 4 with PartialUpdateSecretRequestV2

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"));
}
Also used : Response(javax.ws.rs.core.Response) SecretDetailResponse(keywhiz.api.SecretDetailResponse) PartialUpdateSecretRequestV2(keywhiz.api.automation.v2.PartialUpdateSecretRequestV2) URI(java.net.URI) Test(org.junit.Test)

Example 5 with PartialUpdateSecretRequestV2

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);
}
Also used : PartialUpdateSecretRequestV2(keywhiz.api.automation.v2.PartialUpdateSecretRequestV2) Test(org.junit.Test)

Aggregations

PartialUpdateSecretRequestV2 (keywhiz.api.automation.v2.PartialUpdateSecretRequestV2)7 Test (org.junit.Test)6 URI (java.net.URI)2 Response (okhttp3.Response)2 Response (javax.ws.rs.core.Response)1 TestClients.clientRequest (keywhiz.TestClients.clientRequest)1 SecretDetailResponse (keywhiz.api.SecretDetailResponse)1 CreateOrUpdateSecretRequestV2 (keywhiz.api.automation.v2.CreateOrUpdateSecretRequestV2)1 Request (okhttp3.Request)1 RequestBody (okhttp3.RequestBody)1