public void SetIamPolicy2() { Mock <DatabaseAdmin.DatabaseAdminClient> mockGrpcClient = new Mock <DatabaseAdmin.DatabaseAdminClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); SetIamPolicyRequest request = new SetIamPolicyRequest { Resource = new Google.Cloud.Spanner.Common.V1.DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString(), Policy = new Policy(), }; Policy expectedResponse = new Policy { Version = 351608024, Etag = ByteString.CopyFromUtf8("21"), }; mockGrpcClient.Setup(x => x.SetIamPolicy(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); DatabaseAdminClient client = new DatabaseAdminClientImpl(mockGrpcClient.Object, null); Policy response = client.SetIamPolicy(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
/// <summary> /// Sets the access control policy on the specified dataset. Replaces anyexisting policy.For the definitions of datasets and other genomics resources, see[Fundamentals of GoogleGenomics](https://cloud.google.com/genomics/fundamentals-of-google-genomics)See <a href="/iam/docs/managing-policies#setting_a_policy">Setting aPolicy</a> for more information. /// Documentation https://developers.google.com/genomics/v1/reference/datasets/setIamPolicy /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated Genomics service.</param> /// <param name="resource">REQUIRED: The resource for which policy is being specified. Format is`datasets/<dataset ID>`.</param> /// <param name="body">A valid Genomics v1 body.</param> /// <returns>PolicyResponse</returns> public static Policy SetIamPolicy(GenomicsService service, string resource, SetIamPolicyRequest body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } if (resource == null) { throw new ArgumentNullException(resource); } // Make the request. return(service.Datasets.SetIamPolicy(body, resource).Execute()); } catch (Exception ex) { throw new Exception("Request Datasets.SetIamPolicy failed.", ex); } }
// [END iot_set_device_config] // [START iot_set_iam_policy] public static object SetIamPolicy(string projectId, string cloudRegion, string registryId, string role, string member) { var cloudIot = CreateAuthorizedClient(); // The resource name of the location associated with the key rings. var parent = $"projects/{projectId}/locations/{cloudRegion}/registries/{registryId}"; try { var req = new SetIamPolicyRequest(); Policy pol = new Policy(); pol.Bindings = new List <Binding>(); Binding bind = new Binding() { Role = role, Members = new List <string>() }; bind.Members.Add(member); pol.Bindings.Add(bind); req.Policy = pol; var result = cloudIot.Projects.Locations.Registries.SetIamPolicy(req, parent).Execute(); } catch (Google.GoogleApiException e) { Console.WriteLine(e.Message); return(e.Error.Code); } return(0); }
public void SetIamPolicy() { Mock <InstanceAdmin.InstanceAdminClient> mockGrpcClient = new Mock <InstanceAdmin.InstanceAdminClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); SetIamPolicyRequest expectedRequest = new SetIamPolicyRequest { Resource = new InstanceName("[PROJECT]", "[INSTANCE]").ToString(), Policy = new Policy(), }; Policy expectedResponse = new Policy { Version = 351608024, Etag = ByteString.CopyFromUtf8("21"), }; mockGrpcClient.Setup(x => x.SetIamPolicy(expectedRequest, It.IsAny <CallOptions>())) .Returns(expectedResponse); InstanceAdminClient client = new InstanceAdminClientImpl(mockGrpcClient.Object, null); string formattedResource = new InstanceName("[PROJECT]", "[INSTANCE]").ToString(); Policy policy = new Policy(); Policy response = client.SetIamPolicy(formattedResource, policy); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public Policy SetSubscriptionIamPolicy(string projectId, string subscriptionId, string role, string member) { PublisherServiceApiClient publisher = PublisherServiceApiClient.Create(); string roleToBeAddedToPolicy = $"roles/{role}"; Policy policy = new Policy { Bindings = { new Binding { Role = roleToBeAddedToPolicy, Members ={ member } } } }; SetIamPolicyRequest request = new SetIamPolicyRequest { ResourceAsResourceName = SubscriptionName.FromProjectSubscription(projectId, subscriptionId), Policy = policy }; Policy response = publisher.SetIamPolicy(request); return(response); }
internal void ModifyRequest(SetIamPolicyRequest request) { if (UserProject != null) { request.UserProject = UserProject; } }
// [END secretmanager_iam_grant_access] // [START secretmanager_iam_revoke_access] /// <summary> /// Revoke a user or account access to the secret. /// </summary> /// <param name="projectId">ID of the project where the secret resides.</param> /// <param name="secretId">ID of the secret.</param> /// <param name="member">IAM member to revoke with user: or serviceAccount: prefix</param> /// <example> /// Revoke a user or account access to the secret. /// <code>IAMRevokeAccess("my-project", "my-secret", "user:[email protected]")</code> /// </example> public static void IAMRevokeAccess(string projectId, string secretId, string member) { SecretManagerServiceClient client = SecretManagerServiceClient.Create(); // Create the request to get the current IAM policy. var getRequest = new GetIamPolicyRequest { ResourceAsResourceName = new SecretName(projectId, secretId), }; // Get the current IAM policy. var policy = client.GetIamPolicy(getRequest); // Remove the user to the list of bindings. policy.RemoveRoleMember("roles/secretmanager.secretAccessor", member); // Create the request to update the IAM policy. var setRequest = new SetIamPolicyRequest { ResourceAsResourceName = new SecretName(projectId, secretId), Policy = policy, }; // Save the updated IAM policy. client.SetIamPolicy(setRequest); Console.WriteLine($"Updated IAM policy for {secretId}"); }
public async Task SetIamPolicyAsync2() { Mock <InstanceAdmin.InstanceAdminClient> mockGrpcClient = new Mock <InstanceAdmin.InstanceAdminClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); SetIamPolicyRequest request = new SetIamPolicyRequest { Resource = new InstanceName("[PROJECT]", "[INSTANCE]").ToString(), Policy = new Policy(), }; Policy expectedResponse = new Policy { Version = 351608024, Etag = ByteString.CopyFromUtf8("21"), }; mockGrpcClient.Setup(x => x.SetIamPolicyAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <Policy>(Task.FromResult(expectedResponse), null, null, null, null)); InstanceAdminClient client = new InstanceAdminClientImpl(mockGrpcClient.Object, null); Policy response = await client.SetIamPolicyAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public static object SetSubscriptionIamPolicy(string projectId, string subscriptionId, string role, string member) { PublisherServiceApiClient publisher = PublisherServiceApiClient.Create(); string roleToBeAddedToPolicy = $"roles/{role}"; // [START pubsub_set_subscription_policy] Policy policy = new Policy { Bindings = { new Binding { Role = roleToBeAddedToPolicy, Members ={ member } } } }; SetIamPolicyRequest request = new SetIamPolicyRequest { Resource = new SubscriptionName(projectId, subscriptionId).ToString(), Policy = policy }; Policy response = publisher.SetIamPolicy(request); Console.WriteLine($"Subscription IAM Policy updated: {response}"); // [END pubsub_set_subscription_policy] return(0); }
public Policy SetSubscriptionIamPolicy(string subscriptionId, PublisherClient publisher) { // [START pubsub_set_subscription_policy] Policy policy = new Policy { Bindings = { new Binding { Role = "roles/pubsub.editor", Members ={ "group:[email protected]" } }, new Binding { Role = "roles/pubsub.viewer", Members ={ "allUsers" } } } }; SetIamPolicyRequest request = new SetIamPolicyRequest { Resource = new SubscriptionName(_projectId, subscriptionId).ToString(), Policy = policy }; Policy response = publisher.SetIamPolicy(request); return(response); // [END pubsub_set_subscription_policy] }
public async stt::Task SetIamPolicyRequestObjectAsync() { moq::Mock <IAMPolicy.IAMPolicyClient> mockGrpcClient = new moq::Mock <IAMPolicy.IAMPolicyClient>(moq::MockBehavior.Strict); SetIamPolicyRequest request = new SetIamPolicyRequest { ResourceAsResourceName = new gax::UnparsedResourceName("a/wildcard/resource"), Policy = new Policy(), }; Policy expectedResponse = new Policy { Version = 271578922, Etag = proto::ByteString.CopyFromUtf8("etage8ad7218"), Bindings = { new Binding(), }, }; mockGrpcClient.Setup(x => x.SetIamPolicyAsync(request, moq::It.IsAny <grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall <Policy>(stt::Task.FromResult(expectedResponse), null, null, null, null)); IAMPolicyClient client = new IAMPolicyClientImpl(mockGrpcClient.Object, null); Policy responseCallSettings = await client.SetIamPolicyAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None)); xunit::Assert.Same(expectedResponse, responseCallSettings); Policy responseCancellationToken = await client.SetIamPolicyAsync(request, st::CancellationToken.None); xunit::Assert.Same(expectedResponse, responseCancellationToken); mockGrpcClient.VerifyAll(); }
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}"); }
public async Task SetIamPolicyAsync() { Mock <DatabaseAdmin.DatabaseAdminClient> mockGrpcClient = new Mock <DatabaseAdmin.DatabaseAdminClient>(MockBehavior.Strict); mockGrpcClient.Setup(x => x.CreateOperationsClient()) .Returns(new Mock <Operations.OperationsClient>().Object); SetIamPolicyRequest expectedRequest = new SetIamPolicyRequest { Resource = new Google.Cloud.Spanner.Common.V1.DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString(), Policy = new Policy(), }; Policy expectedResponse = new Policy { Version = 351608024, Etag = ByteString.CopyFromUtf8("21"), }; mockGrpcClient.Setup(x => x.SetIamPolicyAsync(expectedRequest, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <Policy>(Task.FromResult(expectedResponse), null, null, null, null)); DatabaseAdminClient client = new DatabaseAdminClientImpl(mockGrpcClient.Object, null); string formattedResource = new Google.Cloud.Spanner.Common.V1.DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString(); Policy policy = new Policy(); Policy response = await client.SetIamPolicyAsync(formattedResource, policy); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void ModifyRequest_DefaultOptions() { var request = new SetIamPolicyRequest(null, null, "bucket"); var options = new SetBucketIamPolicyOptions(); options.ModifyRequest(request); Assert.Null(request.UserProject); }
/// <summary> /// /// <para>SetTopicIamPolicy:</para> /// /// <para>Adds IAM policy to the given pub/sub topic</para> /// /// </summary> public bool SetTopicIamPolicy( string _TopicName, List <BGCPubSubIamPolicy> _PoliciesToAdd, Action <string> _ErrorMessageAction = null) { _TopicName = GetGoogleFriendlyTopicName(_TopicName); var TopicInstance = new TopicName(ProjectID, _TopicName); if (GetPublisher(out PublisherServiceApiClient Client, TopicInstance, _ErrorMessageAction)) { try { var NewPolicy = new Policy(); foreach (var PolicyToAdd in _PoliciesToAdd) { var NewBinding = new Binding() { Role = PolicyToAdd.Role }; foreach (var Member in PolicyToAdd.Members) { NewBinding.Members.Add(Member); } NewPolicy.Bindings.Add(NewBinding); } var Request = new SetIamPolicyRequest { ResourceAsResourceName = TopicInstance, Policy = NewPolicy }; var Response = Client.SetIamPolicy(Request); if (Response == null) { return(false); } } catch (Exception e) { if (e is RpcException && (e as RpcException).Status.StatusCode == StatusCode.NotFound) { lock (LockablePublisherTopicDictionaryObject(_TopicName)) { PublisherTopicDictionary.Remove(TopicInstance.TopicId); } } else { _ErrorMessageAction?.Invoke("BPubSubServiceGC->SetTopicIamPolicy: " + e.Message + ", Trace: " + e.StackTrace); } return(false); } } return(true); }
public void ModifyRequest_AllOptions() { var request = new SetIamPolicyRequest(null, null, "bucket"); var options = new SetBucketIamPolicyOptions { UserProject = "proj" }; options.ModifyRequest(request); Assert.Equal("proj", request.UserProject); }
/// <summary>Snippet for SetIamPolicy</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void SetIamPolicyRequestObject() { // Create client DataCatalogClient dataCatalogClient = DataCatalogClient.Create(); // Initialize request argument(s) SetIamPolicyRequest request = new SetIamPolicyRequest { ResourceAsResourceName = new UnparsedResourceName("a/wildcard/resource"), Policy = new Policy(), }; // Make the request Policy response = dataCatalogClient.SetIamPolicy(request); }
/// <summary>Snippet for SetIamPolicy</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public void SetIamPolicyRequestObject() { // Create client BigtableInstanceAdminClient bigtableInstanceAdminClient = BigtableInstanceAdminClient.Create(); // Initialize request argument(s) SetIamPolicyRequest request = new SetIamPolicyRequest { ResourceAsResourceName = new UnparsedResourceName("a/wildcard/resource"), Policy = new Policy(), }; // Make the request Policy response = bigtableInstanceAdminClient.SetIamPolicy(request); }
/// <summary>Snippet for SetIamPolicyAsync</summary> /// <remarks> /// This snippet has been automatically generated for illustrative purposes only. /// It may require modifications to work in your environment. /// </remarks> public async Task SetIamPolicyRequestObjectAsync() { // Create client ConnectionServiceClient connectionServiceClient = await ConnectionServiceClient.CreateAsync(); // Initialize request argument(s) SetIamPolicyRequest request = new SetIamPolicyRequest { ResourceAsResourceName = new UnparsedResourceName("a/wildcard/resource"), Policy = new Policy(), }; // Make the request Policy response = await connectionServiceClient.SetIamPolicyAsync(request); }
// [END kms_add_member_to_cryptokey_policy] // [START kms_remove_member_from_cryptokey_policy] public static object RemoveMemberFromCryptoKeyPolicy(string projectId, string location, string keyRing, string cryptoKey, string role, string member) { var cloudKms = CreateAuthorizedClient(); // Generate the full path of the parent to use for updating the crypto key IAM policy. var parent = $"projects/{projectId}/locations/{location}/keyRings/{keyRing}/cryptoKeys/{cryptoKey}"; var result = cloudKms.Projects.Locations.KeyRings.CryptoKeys.GetIamPolicy(parent).Execute(); if (result.Bindings != null) { result.Bindings.ToList().ForEach(response => { if (response.Role == role) { // Remove the role/member combo from the crypto key IAM policy. response.Members = response.Members.Where(m => m != member).ToList(); } }); // Set the modified crypto key IAM policy to be the cryto key's current IAM policy. SetIamPolicyRequest setIamPolicyRequest = new SetIamPolicyRequest(); setIamPolicyRequest.Policy = result; var request = new ProjectsResource.LocationsResource.KeyRingsResource.CryptoKeysResource .SetIamPolicyRequest(cloudKms, setIamPolicyRequest, parent); var setIamPolicyResult = request.Execute(); // Get and display the modified crypto key IAM policy. var resultAfterUpdate = cloudKms.Projects.Locations.KeyRings.CryptoKeys.GetIamPolicy(parent).Execute(); if (resultAfterUpdate.Bindings != null) { Console.WriteLine($"Policy Bindings: {resultAfterUpdate.Bindings}"); resultAfterUpdate.Bindings.ToList().ForEach(response => { Console.WriteLine($"Role: {response.Role}"); response.Members.ToList().ForEach(memberAfterUpdate => { Console.WriteLine($" Member: {memberAfterUpdate}"); }); }); } else { Console.WriteLine($"Empty IAM policy found for CryptoKey: {parent}"); } } else { Console.WriteLine($"Empty IAM policy found for CryptoKey: {parent}"); } return(0); }
/// <summary>Snippet for SetIamPolicy</summary> public void SetIamPolicyRequestObject() { // Snippet: SetIamPolicy(SetIamPolicyRequest, CallSettings) // Create client ContainerAnalysisClient containerAnalysisClient = ContainerAnalysisClient.Create(); // Initialize request argument(s) SetIamPolicyRequest request = new SetIamPolicyRequest { ResourceAsResourceName = new UnparsedResourceName("a/wildcard/resource"), Policy = new Policy(), }; // Make the request Policy response = containerAnalysisClient.SetIamPolicy(request); // End snippet }
/// <summary>Snippet for SetIamPolicy</summary> public void SetIamPolicy_RequestObject() { // Snippet: SetIamPolicy(SetIamPolicyRequest,CallSettings) // Create client InstanceAdminClient instanceAdminClient = InstanceAdminClient.Create(); // Initialize request argument(s) SetIamPolicyRequest request = new SetIamPolicyRequest { Resource = new Google.Cloud.Spanner.Common.V1.InstanceName("[PROJECT]", "[INSTANCE]").ToString(), Policy = new Policy(), }; // Make the request Policy response = instanceAdminClient.SetIamPolicy(request); // End snippet }
/// <summary>Snippet for SetIamPolicy</summary> public void SetIamPolicy_RequestObject() { // Snippet: SetIamPolicy(SetIamPolicyRequest,CallSettings) // Create client ContainerAnalysisClient containerAnalysisClient = ContainerAnalysisClient.Create(); // Initialize request argument(s) SetIamPolicyRequest request = new SetIamPolicyRequest { ResourceAsResourceName = IamResourceNameOneof.From(new NoteName("[PROJECT]", "[NOTE]")), Policy = new Policy(), }; // Make the request Policy response = containerAnalysisClient.SetIamPolicy(request); // End snippet }
public void SetIamPolicy_RequestObject() { // Snippet: SetIamPolicy(SetIamPolicyRequest,CallSettings) // Create client SubscriberClient subscriberClient = SubscriberClient.Create(); // Initialize request argument(s) SetIamPolicyRequest request = new SetIamPolicyRequest { Resource = new SubscriptionName("[PROJECT]", "[SUBSCRIPTION]").ToString(), Policy = new Policy(), }; // Make the request Policy response = subscriberClient.SetIamPolicy(request); // End snippet }
public void SetIamPolicy_RequestObject() { // Snippet: SetIamPolicy(SetIamPolicyRequest,CallSettings) // Create client PublisherClient publisherClient = PublisherClient.Create(); // Initialize request argument(s) SetIamPolicyRequest request = new SetIamPolicyRequest { Resource = new TopicName("[PROJECT]", "[TOPIC]").ToString(), Policy = new Policy(), }; // Make the request Policy response = publisherClient.SetIamPolicy(request); // End snippet }
/// <summary>Snippet for SetIamPolicy</summary> public void SetIamPolicyRequestObject() { // Snippet: SetIamPolicy(SetIamPolicyRequest, CallSettings) // Create client IdentityAwareProxyAdminServiceClient identityAwareProxyAdminServiceClient = IdentityAwareProxyAdminServiceClient.Create(); // Initialize request argument(s) SetIamPolicyRequest request = new SetIamPolicyRequest { ResourceAsResourceName = new UnparsedResourceName("a/wildcard/resource"), Policy = new Policy(), }; // Make the request Policy response = identityAwareProxyAdminServiceClient.SetIamPolicy(request); // End snippet }
/// <summary>Snippet for SetIamPolicy</summary> public void SetIamPolicy_RequestObject() { // Snippet: SetIamPolicy(SetIamPolicyRequest,CallSettings) // Create client DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.Create(); // Initialize request argument(s) SetIamPolicyRequest request = new SetIamPolicyRequest { Resource = new DatabaseName("[PROJECT]", "[INSTANCE]", "[DATABASE]").ToString(), Policy = new Policy(), }; // Make the request Policy response = databaseAdminClient.SetIamPolicy(request); // End snippet }
// [END kms_get_keyring_policy] // [START kms_add_member_to_keyring_policy] public static object AddMemberToKeyRingPolicy(string projectId, string location, string keyRing, string role, string member) { var cloudKms = CreateAuthorizedClient(); // Generate the full path of the parent to use for updating the key ring IAM policy. var parent = $"projects/{projectId}/locations/{location}/keyRings/{keyRing}"; SetIamPolicyRequest setIamPolicyRequest = new SetIamPolicyRequest(); var result = cloudKms.Projects.Locations.KeyRings.GetIamPolicy(parent).Execute(); if (result.Bindings != null) { // Policy already exists, so add a new Binding to it. Binding bindingToAdd = new Binding(); bindingToAdd.Role = role; string[] testMembers = { member }; bindingToAdd.Members = testMembers; result.Bindings.Add(bindingToAdd); setIamPolicyRequest.Policy = result; } else { // Policy does not yet exist, so create a new one Policy newPolicy = new Policy(); newPolicy.Bindings = new List <Binding>(); Binding bindingToAdd = new Binding(); bindingToAdd.Role = role; string[] testMembers = { member }; bindingToAdd.Members = testMembers; newPolicy.Bindings.Add(bindingToAdd); setIamPolicyRequest.Policy = newPolicy; } var request = new ProjectsResource.LocationsResource.KeyRingsResource .SetIamPolicyRequest(cloudKms, setIamPolicyRequest, parent); var setIamPolicyResult = request.Execute(); var updateResult = cloudKms.Projects.Locations.KeyRings.GetIamPolicy(parent).Execute(); updateResult.Bindings.ToList().ForEach(response => { Console.WriteLine($"Role: {response.Role}"); response.Members.ToList().ForEach(memberFound => { Console.WriteLine($" Member: {memberFound}"); }); }); return(0); }
/// <summary>Snippet for SetIamPolicyAsync</summary> public async Task SetIamPolicyAsync_RequestObject() { // Snippet: SetIamPolicyAsync(SetIamPolicyRequest,CallSettings) // Create client PublisherServiceApiClient publisherServiceApiClient = await PublisherServiceApiClient.CreateAsync(); // Initialize request argument(s) SetIamPolicyRequest request = new SetIamPolicyRequest { Resource = new TopicName("[PROJECT]", "[TOPIC]").ToString(), Policy = new Policy(), }; // Make the request Policy response = await publisherServiceApiClient.SetIamPolicyAsync(request); // End snippet }
public async Task SetIamPolicyAsync_RequestObject() { // Snippet: SetIamPolicyAsync(SetIamPolicyRequest,CallSettings) // Create client InstanceAdminClient instanceAdminClient = await InstanceAdminClient.CreateAsync(); // Initialize request argument(s) SetIamPolicyRequest request = new SetIamPolicyRequest { Resource = new InstanceName("[PROJECT]", "[INSTANCE]").ToString(), Policy = new Policy(), }; // Make the request Policy response = await instanceAdminClient.SetIamPolicyAsync(request); // End snippet }