Beispiel #1
0
        public void CreatePubSubTopic(TopicName topicName)
        {
            var publisher = PublisherServiceApiClient.Create();

            try
            {
                publisher.CreateTopic(topicName);
            }
            catch (RpcException e)
                when(e.Status.StatusCode == StatusCode.AlreadyExists)
                {
                }
            Policy policy = new Policy
            {
                Bindings =
                {
                    new Binding {
                        Role    = "roles/pubsub.publisher",
                        Members ={ ServiceAccount   }
                    }
                }
            };
            SetIamPolicyRequest request = new SetIamPolicyRequest
            {
                Resource = $"projects/{ProjectId}/topics/{topicName.TopicId}",
                Policy   = policy
            };
            Policy response = publisher.SetIamPolicy(request);

            Console.WriteLine($"Topic IAM Policy updated: {response}");
        }
 /// <summary>
 /// Sets the access control policy on the specified resource. Replaces any
 /// existing policy.
 /// </summary>
 /// <param name="request">The request object containing all of the parameters for the API call.</param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>A Task containing the RPC response.</returns>
 public override stt::Task <Policy> SetIamPolicyAsync(SetIamPolicyRequest request, gaxgrpc::CallSettings callSettings = null)
 {
     Modify_SetIamPolicyRequest(ref request, ref callSettings);
     return(_callSetIamPolicy.Async(request, callSettings));
 }
 /// <summary>
 /// Sets the access control policy on the specified resource. Replaces any
 /// existing policy.
 /// </summary>
 /// <param name="request">The request object containing all of the parameters for the API call.</param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>The RPC response.</returns>
 public override Policy SetIamPolicy(SetIamPolicyRequest request, gaxgrpc::CallSettings callSettings = null)
 {
     Modify_SetIamPolicyRequest(ref request, ref callSettings);
     return(_callSetIamPolicy.Sync(request, callSettings));
 }
 partial void Modify_SetIamPolicyRequest(ref SetIamPolicyRequest request, ref gaxgrpc::CallSettings settings);
 /// <summary>
 /// Sets the access control policy on the specified resource. Replaces any
 /// existing policy.
 /// </summary>
 /// <param name="request">The request object containing all of the parameters for the API call.</param>
 /// <param name="cancellationToken">A <see cref="st::CancellationToken"/> to use for this RPC.</param>
 /// <returns>A Task containing the RPC response.</returns>
 public virtual stt::Task <Policy> SetIamPolicyAsync(SetIamPolicyRequest request, st::CancellationToken cancellationToken) =>
 SetIamPolicyAsync(request, gaxgrpc::CallSettings.FromCancellationToken(cancellationToken));
 /// <summary>
 /// Sets the access control policy on the specified resource. Replaces any
 /// existing policy.
 /// </summary>
 /// <param name="request">The request object containing all of the parameters for the API call.</param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>A Task containing the RPC response.</returns>
 public virtual stt::Task <Policy> SetIamPolicyAsync(SetIamPolicyRequest request, gaxgrpc::CallSettings callSettings = null) =>
 throw new sys::NotImplementedException();
 /// <summary>
 /// Sets the access control policy on the specified resource. Replaces any
 /// existing policy.
 /// </summary>
 /// <param name="request">The request object containing all of the parameters for the API call.</param>
 /// <param name="callSettings">If not null, applies overrides to this RPC call.</param>
 /// <returns>The RPC response.</returns>
 public virtual Policy SetIamPolicy(SetIamPolicyRequest request, gaxgrpc::CallSettings callSettings = null) =>
 throw new sys::NotImplementedException();