/** * Sets the access control policy on the specified resource. Replaces any existing policy. * * <p>Sample code: * * <pre><code> * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) { * KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); * Policy policy = Policy.newBuilder().build(); * Policy response = keyManagementServiceClient.setIamPolicy(resource, policy); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being specified. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud * Platform services (such as Projects) might reject them. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy setIamPolicy(KeyName resource, Policy policy) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder() .setResource(resource == null ? null : resource.toString()) .setPolicy(policy) .build(); return setIamPolicy(request); }
.setResource(resource == null ? null : resource.toString()) .setPolicy(policy) .build();
.setResource(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) .setPolicy( com.google.iam.v1.Policy.newBuilder()
.setResource(name) .setPolicy(marshaller.toPb(policy)) .build();
.setResource(resource == null ? null : resource.toString()) .setPolicy(policy) .build();
SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build(); return setIamPolicy(request);
SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build(); return setIamPolicy(request);
.setResource(resource == null ? null : resource.toString()) .setPolicy(policy) .build();
/** * Sets the access control policy on the specified Source. * * <p>Sample code: * * <pre><code> * try (SecurityCenterClient securityCenterClient = SecurityCenterClient.create()) { * SourceName resource = SourceName.of("[ORGANIZATION]", "[SOURCE]"); * Policy policy = Policy.newBuilder().build(); * Policy response = securityCenterClient.setIamPolicy(resource.toString(), policy); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being specified. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud * Platform services (such as Projects) might reject them. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy setIamPolicy(String resource, Policy policy) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build(); return setIamPolicy(request); }
/** * Sets the access control policy on the specified resource. Replaces any existing policy. * * <p>Sample code: * * <pre><code> * try (DeviceManagerClient deviceManagerClient = DeviceManagerClient.create()) { * RegistryName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]"); * Policy policy = Policy.newBuilder().build(); * Policy response = deviceManagerClient.setIamPolicy(resource.toString(), policy); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being specified. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud * Platform services (such as Projects) might reject them. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy setIamPolicy(String resource, Policy policy) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build(); return setIamPolicy(request); }
/** * Sets the access control policy on a database resource. Replaces any existing policy. * * <p>Authorization requires `spanner.databases.setIamPolicy` permission on * [resource][google.iam.v1.SetIamPolicyRequest.resource]. * * <p>Sample code: * * <pre><code> * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) { * String formattedResource = DatabaseName.format("[PROJECT]", "[INSTANCE]", "[DATABASE]"); * Policy policy = Policy.newBuilder().build(); * Policy response = databaseAdminClient.setIamPolicy(formattedResource, policy); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being specified. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud * Platform services (such as Projects) might reject them. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy setIamPolicy(String resource, Policy policy) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build(); return setIamPolicy(request); }
SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build(); return setIamPolicy(request);
/** * Sets the access control policy on the specified resource. Replaces any existing policy. * * <p>Sample code: * * <pre><code> * try (DeviceManagerClient deviceManagerClient = DeviceManagerClient.create()) { * RegistryName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]"); * Policy policy = Policy.newBuilder().build(); * Policy response = deviceManagerClient.setIamPolicy(resource, policy); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being specified. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud * Platform services (such as Projects) might reject them. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy setIamPolicy(RegistryName resource, Policy policy) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder() .setResource(resource == null ? null : resource.toString()) .setPolicy(policy) .build(); return setIamPolicy(request); }
private static void ensureKmsKeyRingIamPermissionsForTests( IAMPolicyGrpc.IAMPolicyBlockingStub iamStub, String projectId, String location, String keyRingName) throws StatusRuntimeException { ServiceAccount serviceAccount = storage.getServiceAccount(projectId); String kmsKeyRingResourcePath = KeyRingName.of(projectId, location, keyRingName).toString(); Binding binding = Binding.newBuilder() .setRole("roles/cloudkms.cryptoKeyEncrypterDecrypter") .addMembers("serviceAccount:" + serviceAccount.getEmail()) .build(); com.google.iam.v1.Policy policy = com.google.iam.v1.Policy.newBuilder().addBindings(binding).build(); SetIamPolicyRequest setIamPolicyRequest = SetIamPolicyRequest.newBuilder() .setResource(kmsKeyRingResourcePath) .setPolicy(policy) .build(); requestParamsHeader.put(requestParamsKey, "parent=" + kmsKeyRingResourcePath); iamStub = MetadataUtils.attachHeaders(iamStub, requestParamsHeader); iamStub.setIamPolicy(setIamPolicyRequest); }
/** * Sets the access control policy on the specified Source. * * <p>Sample code: * * <pre><code> * try (SecurityCenterClient securityCenterClient = SecurityCenterClient.create()) { * SourceName resource = SourceName.of("[ORGANIZATION]", "[SOURCE]"); * Policy policy = Policy.newBuilder().build(); * Policy response = securityCenterClient.setIamPolicy(resource, policy); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being specified. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud * Platform services (such as Projects) might reject them. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy setIamPolicy(SourceName resource, Policy policy) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder() .setResource(resource == null ? null : resource.toString()) .setPolicy(policy) .build(); return setIamPolicy(request); }
/** * Sets the access control policy on the specified resource. Replaces any existing policy. * * <p>Sample code: * * <pre><code> * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) { * KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); * Policy policy = Policy.newBuilder().build(); * Policy response = keyManagementServiceClient.setIamPolicy(resource.toString(), policy); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being specified. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud * Platform services (such as Projects) might reject them. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy setIamPolicy(String resource, Policy policy) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build(); return setIamPolicy(request); }
/** * Sets the access control policy on the specified resource. Replaces any existing policy. * * <p>Sample code: * * <pre><code> * try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { * String formattedResource = ProjectSubscriptionName.format("[PROJECT]", "[SUBSCRIPTION]"); * Policy policy = Policy.newBuilder().build(); * Policy response = subscriptionAdminClient.setIamPolicy(formattedResource, policy); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being specified. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud * Platform services (such as Projects) might reject them. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy setIamPolicy(String resource, Policy policy) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build(); return setIamPolicy(request); }
/** * Sets the access control policy on an instance resource. Replaces any existing policy. * * <p>Sample code: * * <pre><code> * try (BaseBigtableInstanceAdminClient baseBigtableInstanceAdminClient = BaseBigtableInstanceAdminClient.create()) { * String formattedResource = InstanceName.format("[PROJECT]", "[INSTANCE]"); * Policy policy = Policy.newBuilder().build(); * Policy response = baseBigtableInstanceAdminClient.setIamPolicy(formattedResource, policy); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being specified. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud * Platform services (such as Projects) might reject them. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy setIamPolicy(String resource, Policy policy) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build(); return setIamPolicy(request); }
/** * Sets the access control policy on an instance resource. Replaces any existing policy. * * <p>Authorization requires `spanner.instances.setIamPolicy` on * [resource][google.iam.v1.SetIamPolicyRequest.resource]. * * <p>Sample code: * * <pre><code> * try (InstanceAdminClient instanceAdminClient = InstanceAdminClient.create()) { * String formattedResource = InstanceName.format("[PROJECT]", "[INSTANCE]"); * Policy policy = Policy.newBuilder().build(); * Policy response = instanceAdminClient.setIamPolicy(formattedResource, policy); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being specified. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud * Platform services (such as Projects) might reject them. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy setIamPolicy(String resource, Policy policy) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build(); return setIamPolicy(request); }
/** * Sets the access control policy on the specified resource. Replaces any existing policy. * * <p>Sample code: * * <pre><code> * try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { * String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]"); * Policy policy = Policy.newBuilder().build(); * Policy response = topicAdminClient.setIamPolicy(formattedResource, policy); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being specified. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @param policy REQUIRED: The complete policy to be applied to the `resource`. The size of the * policy is limited to a few 10s of KB. An empty policy is a valid policy but certain Cloud * Platform services (such as Projects) might reject them. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy setIamPolicy(String resource, Policy policy) { SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build(); return setIamPolicy(request); }