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());
}
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");
}
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");
}
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);
}
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);
}
Aggregations