Search in sources :

Example 6 with AddSecretVersionRequest

use of com.google.cloud.secretmanager.v1.AddSecretVersionRequest in project java-secretmanager by googleapis.

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 7 with AddSecretVersionRequest

use of com.google.cloud.secretmanager.v1.AddSecretVersionRequest in project java-secretmanager by googleapis.

the class ITSystemTest method setUp.

@BeforeClass
public static void setUp() throws IOException {
    /* create secret */
    client = SecretManagerServiceClient.create();
    Replication createReplication = Replication.newBuilder().setUserManaged(Replication.UserManaged.newBuilder().addReplicas(Replication.UserManaged.Replica.newBuilder().setLocation(LOCATION).build())).build();
    Secret createSecret = Secret.newBuilder().setReplication(createReplication).build();
    CreateSecretRequest secretRequest = CreateSecretRequest.newBuilder().setParent(PROJECT_NAME).setSecretId(SECRET_ID).setSecret(createSecret).build();
    secret = client.createSecret(secretRequest);
    secretId = getName(secret.getName());
    formattedSecretName = SecretName.of(PROJECT_ID, secretId).toString();
    /* create secret version */
    AddSecretVersionRequest versionRequest = AddSecretVersionRequest.newBuilder().setParent(formattedSecretName).setPayload(PAYLOAD).build();
    secretVersion = client.addSecretVersion(versionRequest);
    secretVersionId = getName(secretVersion.getName());
    formattedSecretVersion = SecretVersionName.of(PROJECT_ID, secretId, secretVersionId).toString();
}
Also used : Secret(com.google.cloud.secretmanager.v1beta1.Secret) AddSecretVersionRequest(com.google.cloud.secretmanager.v1beta1.AddSecretVersionRequest) CreateSecretRequest(com.google.cloud.secretmanager.v1beta1.CreateSecretRequest) Replication(com.google.cloud.secretmanager.v1beta1.Replication) BeforeClass(org.junit.BeforeClass)

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