Search in sources :

Example 1 with AddSecretVersionRequest

use of com.google.cloud.secretmanager.v1.AddSecretVersionRequest in project spring-cloud-gcp by GoogleCloudPlatform.

the class SecretManagerTemplate method createNewSecretVersion.

/**
 * Create a new version of the secret with the specified payload under a {@link Secret}. Will also
 * create the parent secret if it does not already exist.
 */
private void createNewSecretVersion(String secretId, ByteString payload, String projectId) {
    if (!secretExists(secretId, projectId)) {
        createSecretInternal(secretId, projectId);
    }
    SecretName name = SecretName.of(projectId, secretId);
    AddSecretVersionRequest payloadRequest = AddSecretVersionRequest.newBuilder().setParent(name.toString()).setPayload(SecretPayload.newBuilder().setData(payload)).build();
    secretManagerServiceClient.addSecretVersion(payloadRequest);
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) AddSecretVersionRequest(com.google.cloud.secretmanager.v1.AddSecretVersionRequest)

Example 2 with AddSecretVersionRequest

use of com.google.cloud.secretmanager.v1.AddSecretVersionRequest in project spring-cloud-gcp by spring-cloud.

the class SecretManagerTemplateTests method verifyAddSecretRequest.

private void verifyAddSecretRequest(String secretId, String payload, String projectId) {
    AddSecretVersionRequest addSecretVersionRequest = AddSecretVersionRequest.newBuilder().setParent("projects/" + projectId + "/secrets/" + secretId).setPayload(SecretPayload.newBuilder().setData(ByteString.copyFromUtf8(payload))).build();
    verify(this.client).addSecretVersion(addSecretVersionRequest);
}
Also used : AddSecretVersionRequest(com.google.cloud.secretmanager.v1.AddSecretVersionRequest)

Example 3 with AddSecretVersionRequest

use of com.google.cloud.secretmanager.v1.AddSecretVersionRequest in project spring-cloud-gcp by spring-cloud.

the class SecretManagerTemplate method createNewSecretVersion.

/**
 * Create a new version of the secret with the specified payload under a {@link Secret}.
 * Will also create the parent secret if it does not already exist.
 */
private void createNewSecretVersion(String secretId, ByteString payload, String projectId) {
    if (!secretExists(secretId, projectId)) {
        createSecretInternal(secretId, projectId);
    }
    SecretName name = SecretName.of(projectId, secretId);
    AddSecretVersionRequest payloadRequest = AddSecretVersionRequest.newBuilder().setParent(name.toString()).setPayload(SecretPayload.newBuilder().setData(payload)).build();
    secretManagerServiceClient.addSecretVersion(payloadRequest);
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) AddSecretVersionRequest(com.google.cloud.secretmanager.v1.AddSecretVersionRequest)

Example 4 with AddSecretVersionRequest

use of com.google.cloud.secretmanager.v1.AddSecretVersionRequest in project java-docs-samples by GoogleCloudPlatform.

the class SnippetsIT method addSecretVersion.

private static SecretVersion addSecretVersion(Secret secret) throws IOException {
    SecretName parent = SecretName.parse(secret.getName());
    AddSecretVersionRequest request = AddSecretVersionRequest.newBuilder().setParent(parent.toString()).setPayload(SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("my super secret data")).build()).build();
    try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
        return client.addSecretVersion(request);
    }
}
Also used : SecretName(com.google.cloud.secretmanager.v1.SecretName) AddSecretVersionRequest(com.google.cloud.secretmanager.v1.AddSecretVersionRequest) SecretManagerServiceClient(com.google.cloud.secretmanager.v1.SecretManagerServiceClient)

Example 5 with AddSecretVersionRequest

use of com.google.cloud.secretmanager.v1.AddSecretVersionRequest in project spring-cloud-gcp by GoogleCloudPlatform.

the class SecretManagerTemplateTests method verifyAddSecretRequest.

private void verifyAddSecretRequest(String secretId, String payload, String projectId) {
    AddSecretVersionRequest addSecretVersionRequest = AddSecretVersionRequest.newBuilder().setParent("projects/" + projectId + "/secrets/" + secretId).setPayload(SecretPayload.newBuilder().setData(ByteString.copyFromUtf8(payload))).build();
    verify(this.client).addSecretVersion(addSecretVersionRequest);
}
Also used : AddSecretVersionRequest(com.google.cloud.secretmanager.v1.AddSecretVersionRequest)

Aggregations

AddSecretVersionRequest (com.google.cloud.secretmanager.v1.AddSecretVersionRequest)6 SecretName (com.google.cloud.secretmanager.v1.SecretName)4 SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)2 AddSecretVersionRequest (com.google.cloud.secretmanager.v1beta1.AddSecretVersionRequest)1 CreateSecretRequest (com.google.cloud.secretmanager.v1beta1.CreateSecretRequest)1 Replication (com.google.cloud.secretmanager.v1beta1.Replication)1 Secret (com.google.cloud.secretmanager.v1beta1.Secret)1 BeforeClass (org.junit.BeforeClass)1