use of com.google.storage.v2.ProjectName in project java-docs-samples by GoogleCloudPlatform.
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.storage.v2.ProjectName in project divolte-collector by divolte.
the class GoogleCloudPubSubSinkConfiguration method createTopic.
private static void createTopic(final String hostPort, final TransportChannelProvider channelProvider, final ProjectTopicName topic) {
final TopicAdminClient topicClient;
try {
final TopicAdminSettings topicAdminSettings = TopicAdminSettings.newBuilder().setTransportChannelProvider(channelProvider).setCredentialsProvider(NoCredentialsProvider.create()).build();
topicClient = TopicAdminClient.create(topicAdminSettings);
} catch (final IOException e) {
throw new UncheckedIOException(String.format("Error creating topic %s for pub/sub emulator %s", topic, hostPort), e);
}
final ProjectName project = ProjectName.of(topic.getProject());
if (Streams.stream(topicClient.listTopics(project).iterateAll()).map(Topic::getName).map(ProjectTopicName::parse).noneMatch(topic::equals)) {
logger.info("Initializing Pub/Sub emulator topic: {}", topic);
topicClient.createTopic(topic);
}
}
use of com.google.storage.v2.ProjectName in project java-phishingprotection by googleapis.
the class PhishingProtectionServiceV1Beta1ClientTest method reportPhishingTest.
@Test
public void reportPhishingTest() throws Exception {
ReportPhishingResponse expectedResponse = ReportPhishingResponse.newBuilder().build();
mockPhishingProtectionServiceV1Beta1.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
String uri = "uri116076";
ReportPhishingResponse actualResponse = client.reportPhishing(parent, uri);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockPhishingProtectionServiceV1Beta1.getRequests();
Assert.assertEquals(1, actualRequests.size());
ReportPhishingRequest actualRequest = ((ReportPhishingRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertEquals(uri, actualRequest.getUri());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.storage.v2.ProjectName in project java-storage by googleapis.
the class StorageClientTest method listNotificationsTest.
@Test
public void listNotificationsTest() throws Exception {
Notification responsesElement = Notification.newBuilder().build();
ListNotificationsResponse expectedResponse = ListNotificationsResponse.newBuilder().setNextPageToken("").addAllNotifications(Arrays.asList(responsesElement)).build();
mockStorage.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
ListNotificationsPagedResponse pagedListResponse = client.listNotifications(parent);
List<Notification> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getNotificationsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockStorage.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListNotificationsRequest actualRequest = ((ListNotificationsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.storage.v2.ProjectName in project java-storage by googleapis.
the class StorageClientTest method listBucketsTest.
@Test
public void listBucketsTest() throws Exception {
Bucket responsesElement = Bucket.newBuilder().build();
ListBucketsResponse expectedResponse = ListBucketsResponse.newBuilder().setNextPageToken("").addAllBuckets(Arrays.asList(responsesElement)).build();
mockStorage.addResponse(expectedResponse);
ProjectName parent = ProjectName.of("[PROJECT]");
ListBucketsPagedResponse pagedListResponse = client.listBuckets(parent);
List<Bucket> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getBucketsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockStorage.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListBucketsRequest actualRequest = ((ListBucketsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations