public Policy GetSubscriptionIamPolicy(string projectId, string subscriptionId) { PublisherServiceApiClient publisher = PublisherServiceApiClient.Create(); SubscriptionName subscriptionName = SubscriptionName.FromProjectSubscription(projectId, subscriptionId); Policy policy = publisher.GetIamPolicy(subscriptionName); return(policy); }
public Policy GetTopicIamPolicy(string projectId, string topicId) { PublisherServiceApiClient publisher = PublisherServiceApiClient.Create(); TopicName topicName = TopicName.FromProjectTopic(projectId, topicId); Policy policy = publisher.GetIamPolicy(topicName); return(policy); }
/// <summary>Snippet for GetIamPolicy</summary> public void GetIamPolicy() { // Snippet: GetIamPolicy(string,CallSettings) // Create client PublisherServiceApiClient publisherServiceApiClient = PublisherServiceApiClient.Create(); // Initialize request argument(s) string formattedResource = new TopicName("[PROJECT]", "[TOPIC]").ToString(); // Make the request Policy response = publisherServiceApiClient.GetIamPolicy(formattedResource); // End snippet }
public static object GetTopicIamPolicy(string projectId, string topicId) { PublisherServiceApiClient publisher = PublisherServiceApiClient.Create(); // [START pubsub_get_topic_policy] TopicName topicName = new TopicName(projectId, topicId); Policy policy = publisher.GetIamPolicy(topicName.ToString()); Console.WriteLine($"Topic IAM Policy found for {topicId}:"); Console.WriteLine(policy.Bindings); // [END pubsub_get_topic_policy] return(0); }
public static object GetSubscriptionIamPolicy(string projectId, string subscriptionId) { PublisherServiceApiClient publisher = PublisherServiceApiClient.Create(); // [START pubsub_get_subscription_policy] SubscriptionName subscriptionName = new SubscriptionName(projectId, subscriptionId); Policy policy = publisher.GetIamPolicy(subscriptionName.ToString()); Console.WriteLine($"Subscription IAM Policy found for {subscriptionId}:"); Console.WriteLine(policy.Bindings); // [END pubsub_get_subscription_policy] return(0); }
/// <summary>Snippet for GetIamPolicy</summary> public void GetIamPolicy_RequestObject() { // Snippet: GetIamPolicy(GetIamPolicyRequest,CallSettings) // Create client PublisherServiceApiClient publisherServiceApiClient = PublisherServiceApiClient.Create(); // Initialize request argument(s) GetIamPolicyRequest request = new GetIamPolicyRequest { Resource = new TopicName("[PROJECT]", "[TOPIC]").ToString(), }; // Make the request Policy response = publisherServiceApiClient.GetIamPolicy(request); // End snippet }
public void GetIamPolicy() { string projectId = _fixture.ProjectId; string topicId = _fixture.CreateTopicId(); PublisherServiceApiClient.Create().CreateTopic(new TopicName(projectId, topicId)); // Snippet: GetIamPolicy(string,*) PublisherServiceApiClient client = PublisherServiceApiClient.Create(); string topicName = new TopicName(projectId, topicId).ToString(); Policy policy = client.GetIamPolicy(topicName); Console.WriteLine($"Policy for {topicName}: {policy}"); // End snippet }
public void NotificationsOverview() { string projectId = _fixture.ProjectId; string bucket = _fixture.BucketName; string topicId = IdGenerator.FromGuid(prefix: "topic-"); // Sample: NotificationsOverview // First create a Pub/Sub topic. PublisherServiceApiClient publisherClient = PublisherServiceApiClient.Create(); TopicName topicName = new TopicName(projectId, topicId); publisherClient.CreateTopic(topicName); // Prepare the topic for Storage notifications. The Storage Service Account must have Publish permission // for the topic. The code below adds the service account into the "roles/pubsub.publisher" role for the topic. // Determine the Storage Service Account name to use in IAM operations. StorageClient storageClient = StorageClient.Create(); string storageServiceAccount = $"serviceAccount:{storageClient.GetStorageServiceAccountEmail(projectId)}"; // Fetch the IAM policy for the topic. Iam.V1.Policy policy = publisherClient.GetIamPolicy(topicName.ToString()); var role = "roles/pubsub.publisher"; // Ensure the Storage Service Account is in the publisher role, setting the IAM policy for the topic // on the server if necessary. if (policy.AddRoleMember(role, storageServiceAccount)) { publisherClient.SetIamPolicy(topicName.ToString(), policy); } // Now that the topic is ready, we can create a notification configuration for Storage Notification notification = new Notification { Topic = $"//pubsub.googleapis.com/{topicName}", PayloadFormat = "JSON_API_V1" }; notification = storageClient.CreateNotification(bucket, notification); Console.WriteLine($"Created notification ID: {notification.Id}"); // End sample _fixture.RegisterTopicToDelete(topicName); }