use of com.google.spanner.admin.instance.v1.ProjectName 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.google.spanner.admin.instance.v1.ProjectName in project java-dlp by googleapis.
the class DlpServiceClientTest method listJobTriggersExceptionTest2.
@Test
public void listJobTriggersExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockDlpService.addException(exception);
try {
ProjectName parent = ProjectName.of("[PROJECT]");
client.listJobTriggers(parent);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.spanner.admin.instance.v1.ProjectName in project java-dlp by googleapis.
the class DlpServiceClientTest method listDlpJobsExceptionTest2.
@Test
public void listDlpJobsExceptionTest2() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockDlpService.addException(exception);
try {
ProjectName parent = ProjectName.of("[PROJECT]");
client.listDlpJobs(parent);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.spanner.admin.instance.v1.ProjectName in project java-dlp by googleapis.
the class DlpServiceClientTest method createDlpJobExceptionTest3.
@Test
public void createDlpJobExceptionTest3() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockDlpService.addException(exception);
try {
ProjectName parent = ProjectName.of("[PROJECT]");
InspectJobConfig inspectJob = InspectJobConfig.newBuilder().build();
client.createDlpJob(parent, inspectJob);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.spanner.admin.instance.v1.ProjectName in project java-dlp by googleapis.
the class DlpServiceClientTest method listStoredInfoTypesExceptionTest4.
@Test
public void listStoredInfoTypesExceptionTest4() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockDlpService.addException(exception);
try {
ProjectName parent = ProjectName.of("[PROJECT]");
client.listStoredInfoTypes(parent);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
Aggregations