Search in sources :

Example 61 with Secret

use of com.google.cloud.secretmanager.v1.Secret in project native-image-support-java by GoogleCloudPlatform.

the class SecretManagerSampleApplication method createSecret.

static void createSecret(SecretManagerServiceClient client, String projectId, String secretId) {
    ProjectName projectName = ProjectName.of(projectId);
    Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
    Secret createdSecret = client.createSecret(projectName, secretId, secret);
    System.out.println("Created secret: " + createdSecret.getName());
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) ProjectName(com.google.cloud.secretmanager.v1.ProjectName)

Example 62 with Secret

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

the class SecretManagerPropertyUtilsTests method testLongProperty_projectSecretVersion.

@Test
public void testLongProperty_projectSecretVersion() {
    String property = "sm://projects/my-project/secrets/the-secret/versions/3";
    SecretVersionName secretIdentifier = SecretManagerPropertyUtils.getSecretVersionName(property, DEFAULT_PROJECT_ID_PROVIDER);
    assertThat(secretIdentifier.getProject()).isEqualTo("my-project");
    assertThat(secretIdentifier.getSecret()).isEqualTo("the-secret");
    assertThat(secretIdentifier.getSecretVersion()).isEqualTo("3");
}
Also used : SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName) Test(org.junit.Test)

Example 63 with Secret

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

the class SecretManagerPropertyUtilsTests method testShortProperty_projectSecretIdVersion.

@Test
public void testShortProperty_projectSecretIdVersion() {
    String property = "sm://my-project/the-secret/2";
    SecretVersionName secretIdentifier = SecretManagerPropertyUtils.getSecretVersionName(property, DEFAULT_PROJECT_ID_PROVIDER);
    assertThat(secretIdentifier.getProject()).isEqualTo("my-project");
    assertThat(secretIdentifier.getSecret()).isEqualTo("the-secret");
    assertThat(secretIdentifier.getSecretVersion()).isEqualTo("2");
}
Also used : SecretVersionName(com.google.cloud.secretmanager.v1.SecretVersionName) Test(org.junit.Test)

Example 64 with Secret

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

the class SecretManagerTemplateTests method verifyCreateSecretRequest.

private void verifyCreateSecretRequest(String secretId, String projectId) {
    Secret secretToAdd = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder()).build()).build();
    CreateSecretRequest createSecretRequest = CreateSecretRequest.newBuilder().setParent("projects/" + projectId).setSecretId(secretId).setSecret(secretToAdd).build();
    verify(this.client).createSecret(createSecretRequest);
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) CreateSecretRequest(com.google.cloud.secretmanager.v1.CreateSecretRequest)

Example 65 with Secret

use of com.google.cloud.secretmanager.v1.Secret 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)

Aggregations

SecretManagerServiceClient (com.google.cloud.secretmanager.v1.SecretManagerServiceClient)52 SecretVersionName (com.google.cloud.secretmanager.v1.SecretVersionName)45 SecretName (com.google.cloud.secretmanager.v1.SecretName)44 Test (org.junit.Test)42 SecretVersion (com.google.cloud.secretmanager.v1.SecretVersion)22 Secret (com.google.cloud.secretmanager.v1.Secret)21 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)16 ByteString (com.google.protobuf.ByteString)13 Test (org.junit.jupiter.api.Test)13 AccessSecretVersionResponse (com.google.cloud.secretmanager.v1.AccessSecretVersionResponse)10 ListSecretsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretsPagedResponse)7 CreateSecretRequest (com.google.cloud.secretmanager.v1.CreateSecretRequest)6 SecretPayload (com.google.cloud.secretmanager.v1.SecretPayload)6 AddSecretVersionRequest (com.google.cloud.secretmanager.v1.AddSecretVersionRequest)4 DeleteSecretRequest (com.google.cloud.secretmanager.v1.DeleteSecretRequest)4 ListSecretVersionsPagedResponse (com.google.cloud.secretmanager.v1.SecretManagerServiceClient.ListSecretVersionsPagedResponse)4 Binding (com.google.iam.v1.Binding)4 Policy (com.google.iam.v1.Policy)4 ListSecretsRequest (com.google.cloud.secretmanager.v1.ListSecretsRequest)3 Secret (com.google.cloud.secretmanager.v1beta1.Secret)3