use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project java-secretmanager by googleapis.
the class Quickstart method quickstart.
public void quickstart(String projectId, String secretId) throws Exception {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the parent name from the project.
ProjectName projectName = ProjectName.of(projectId);
// Create the parent secret.
Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
Secret createdSecret = client.createSecret(projectName, secretId, secret);
// Add a secret version.
SecretPayload payload = SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("hello world!")).build();
SecretVersion addedVersion = client.addSecretVersion(createdSecret.getName(), payload);
// Access the secret version.
AccessSecretVersionResponse response = client.accessSecretVersion(addedVersion.getName());
// Print the secret payload.
//
// WARNING: Do not print the secret in a production environment - this
// snippet is showing how to access the secret material.
String data = response.getPayload().getData().toStringUtf8();
System.out.printf("Plaintext: %s\n", data);
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project java-secretmanager by googleapis.
the class UpdateSecret method updateSecret.
// Update an existing secret.
public void updateSecret(String projectId, String secretId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the name.
SecretName secretName = SecretName.of(projectId, secretId);
// Build the updated secret.
Secret secret = Secret.newBuilder().setName(secretName.toString()).putLabels("secretmanager", "rocks").build();
// Build the field mask.
FieldMask fieldMask = FieldMaskUtil.fromString("labels");
// Create the secret.
Secret updatedSecret = client.updateSecret(secret, fieldMask);
System.out.printf("Updated secret %s\n", updatedSecret.getName());
}
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project nomulus by google.
the class SecretManagerClientImpl method createSecret.
@Override
public void createSecret(String secretId) {
checkNotNull(secretId, "secretId");
Secret secretSettings = Secret.newBuilder().setReplication(defaultReplicationPolicy()).build();
callSecretManager(() -> csmClient.createSecret(ProjectName.of(project), secretId, secretSettings));
}
use of com.marcnuri.yakc.model.io.k8s.api.core.v1.Secret in project native-image-support-java by GoogleCloudPlatform.
the class SecretManagerSampleApplication method hasSecret.
static boolean hasSecret(SecretManagerServiceClient client, String projectId, String secretId) {
ProjectName projectName = ProjectName.of(projectId);
ListSecretsPagedResponse pagedResponse = client.listSecrets(projectName);
for (Secret secret : pagedResponse.iterateAll()) {
String otherSecretId = extractSecretId(secret);
if (secretId.equals(otherSecretId)) {
return true;
}
}
return false;
}
use of com.marcnuri.yakc.model.io.k8s.api.core.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());
}
Aggregations