/** * Gets the access control policy for a resource. Returns an empty policy if the resource exists * and does not have a policy set. * * <p>Sample code: * * <pre><code> * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) { * KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); * Policy response = keyManagementServiceClient.getIamPolicy(resource); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(KeyName resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder() .setResource(resource == null ? null : resource.toString()) .build(); return getIamPolicy(request); }
/** * Gets the access control policy for a note or an occurrence resource. Requires * `containeranalysis.notes.setIamPolicy` or `containeranalysis.occurrences.setIamPolicy` * permission if the resource is a note or occurrence, respectively. * * <p>The resource takes the format `projects/[PROJECT_ID]/notes/[NOTE_ID]` for notes and * `projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]` for occurrences. * * <p>Sample code: * * <pre><code> * try (ContainerAnalysisV1Beta1Client containerAnalysisV1Beta1Client = ContainerAnalysisV1Beta1Client.create()) { * IamResourceName resource = NoteName.of("[PROJECT]", "[NOTE]"); * Policy response = containerAnalysisV1Beta1Client.getIamPolicy(resource); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(IamResourceName resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder() .setResource(resource == null ? null : resource.toString()) .build(); return getIamPolicy(request); }
@Test public void testGetIamPolicy() { // Setup com.google.iam.v1.GetIamPolicyRequest expectedRequest = com.google.iam.v1.GetIamPolicyRequest.newBuilder() .setResource(NameUtil.formatInstanceName(PROJECT_ID, INSTANCE_ID)) .build(); com.google.iam.v1.Policy expectedResponse = com.google.iam.v1.Policy.newBuilder() .addBindings( com.google.iam.v1.Binding.newBuilder() .setRole("roles/bigtable.user") .addMembers("user:someone@example.com")) .setEtag(ByteString.copyFromUtf8("my-etag")) .build(); Mockito.when(mockGetIamPolicyCallable.futureCall(expectedRequest)) .thenReturn(ApiFutures.immediateFuture(expectedResponse)); // Execute Policy actualResult = adminClient.getIamPolicy(INSTANCE_ID); // Verify assertThat(actualResult) .isEqualTo( Policy.newBuilder() .addIdentity(Role.of("bigtable.user"), Identity.user("someone@example.com")) .setEtag(BaseEncoding.base64().encode("my-etag".getBytes())) .build()); }
/** * Gets the access control policy for an instance resource. Returns an empty policy if an instance * exists but does not have a policy set. * * <p>Sample code: * * <pre><code> * try (BaseBigtableInstanceAdminClient baseBigtableInstanceAdminClient = BaseBigtableInstanceAdminClient.create()) { * String formattedResource = InstanceName.format("[PROJECT]", "[INSTANCE]"); * Policy response = baseBigtableInstanceAdminClient.getIamPolicy(formattedResource); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); }
String name = NameUtil.formatInstanceName(projectId, instanceId); GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(name).build();
/** * Gets the access control policy for a [Queue][google.cloud.tasks.v2beta3.Queue]. Returns an * empty policy if the resource exists and does not have a policy set. * * <p>Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission * on the specified resource parent: * * <p>* `cloudtasks.queues.getIamPolicy` * * <p>Sample code: * * <pre><code> * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { * QueueName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); * Policy response = cloudTasksClient.getIamPolicy(resource.toString()); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); }
/** * Gets the access control policy for a [Queue][google.cloud.tasks.v2beta3.Queue]. Returns an * empty policy if the resource exists and does not have a policy set. * * <p>Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission * on the specified resource parent: * * <p>* `cloudtasks.queues.getIamPolicy` * * <p>Sample code: * * <pre><code> * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { * QueueName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); * Policy response = cloudTasksClient.getIamPolicy(resource); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(QueueName resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder() .setResource(resource == null ? null : resource.toString()) .build(); return getIamPolicy(request); }
/** * Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Returns an * empty policy if the resource exists and does not have a policy set. * * <p>Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission * on the specified resource parent: * * <p>* `cloudtasks.queues.getIamPolicy` * * <p>Sample code: * * <pre><code> * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { * QueueName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); * Policy response = cloudTasksClient.getIamPolicy(resource.toString()); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); }
/** * Gets the access control policy for a [Queue][google.cloud.tasks.v2beta2.Queue]. Returns an * empty policy if the resource exists and does not have a policy set. * * <p>Authorization requires the following [Google IAM](https://cloud.google.com/iam) permission * on the specified resource parent: * * <p>* `cloudtasks.queues.getIamPolicy` * * <p>Sample code: * * <pre><code> * try (CloudTasksClient cloudTasksClient = CloudTasksClient.create()) { * QueueName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); * Policy response = cloudTasksClient.getIamPolicy(resource); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(QueueName resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder() .setResource(resource == null ? null : resource.toString()) .build(); return getIamPolicy(request); }
/** * Gets the access control policy for an instance resource. Returns an empty policy if an instance * exists but does not have a policy set. * * <p>Authorization requires `spanner.instances.getIamPolicy` on * [resource][google.iam.v1.GetIamPolicyRequest.resource]. * * <p>Sample code: * * <pre><code> * try (InstanceAdminClient instanceAdminClient = InstanceAdminClient.create()) { * String formattedResource = InstanceName.format("[PROJECT]", "[INSTANCE]"); * Policy response = instanceAdminClient.getIamPolicy(formattedResource); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); }
/** * Gets the access control policy for a database resource. Returns an empty policy if a database * exists but does not have a policy set. * * <p>Authorization requires `spanner.databases.getIamPolicy` permission on * [resource][google.iam.v1.GetIamPolicyRequest.resource]. * * <p>Sample code: * * <pre><code> * try (DatabaseAdminClient databaseAdminClient = DatabaseAdminClient.create()) { * String formattedResource = DatabaseName.format("[PROJECT]", "[INSTANCE]", "[DATABASE]"); * Policy response = databaseAdminClient.getIamPolicy(formattedResource); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); }
/** * Gets the access control policy for a resource. Returns an empty policy if the resource exists * and does not have a policy set. * * <p>Sample code: * * <pre><code> * try (DeviceManagerClient deviceManagerClient = DeviceManagerClient.create()) { * RegistryName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]"); * Policy response = deviceManagerClient.getIamPolicy(resource.toString()); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); }
/** * Gets the access control policy for a resource. Returns an empty policy if the resource exists * and does not have a policy set. * * <p>Sample code: * * <pre><code> * try (TopicAdminClient topicAdminClient = TopicAdminClient.create()) { * String formattedResource = ProjectTopicName.format("[PROJECT]", "[TOPIC]"); * Policy response = topicAdminClient.getIamPolicy(formattedResource); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); }
/** * Gets the access control policy for a resource. Returns an empty policy if the resource exists * and does not have a policy set. * * <p>Sample code: * * <pre><code> * try (SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create()) { * String formattedResource = ProjectSubscriptionName.format("[PROJECT]", "[SUBSCRIPTION]"); * Policy response = subscriptionAdminClient.getIamPolicy(formattedResource); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); }
/** * Gets 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 response = securityCenterClient.getIamPolicy(resource); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(SourceName resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder() .setResource(resource == null ? null : resource.toString()) .build(); return getIamPolicy(request); }
/** * Gets the access control policy for a note or an occurrence resource. Requires * `containeranalysis.notes.setIamPolicy` or `containeranalysis.occurrences.setIamPolicy` * permission if the resource is a note or occurrence, respectively. * * <p>The resource takes the format `projects/[PROJECT_ID]/notes/[NOTE_ID]` for notes and * `projects/[PROJECT_ID]/occurrences/[OCCURRENCE_ID]` for occurrences. * * <p>Sample code: * * <pre><code> * try (ContainerAnalysisV1Beta1Client containerAnalysisV1Beta1Client = ContainerAnalysisV1Beta1Client.create()) { * IamResourceName resource = NoteName.of("[PROJECT]", "[NOTE]"); * Policy response = containerAnalysisV1Beta1Client.getIamPolicy(resource.toString()); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); }
/** * Gets the access control policy for a resource. Returns an empty policy if the resource exists * and does not have a policy set. * * <p>Sample code: * * <pre><code> * try (DeviceManagerClient deviceManagerClient = DeviceManagerClient.create()) { * RegistryName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]"); * Policy response = deviceManagerClient.getIamPolicy(resource); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(RegistryName resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder() .setResource(resource == null ? null : resource.toString()) .build(); return getIamPolicy(request); }
/** * Gets the access control policy for a resource. Returns an empty policy if the resource exists * and does not have a policy set. * * <p>Sample code: * * <pre><code> * try (KeyManagementServiceClient keyManagementServiceClient = KeyManagementServiceClient.create()) { * KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); * Policy response = keyManagementServiceClient.getIamPolicy(resource.toString()); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); }
/** * Gets the access control policy for an instance resource. Returns an empty policy if an instance * exists but does not have a policy set. * * <p>Sample code: * * <pre><code> * try (BaseBigtableInstanceAdminClient baseBigtableInstanceAdminClient = BaseBigtableInstanceAdminClient.create()) { * String formattedResource = InstanceName.format("[PROJECT]", "[INSTANCE]"); * Policy response = baseBigtableInstanceAdminClient.getIamPolicy(formattedResource); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); }
/** * Gets 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 response = securityCenterClient.getIamPolicy(resource.toString()); * } * </code></pre> * * @param resource REQUIRED: The resource for which the policy is being requested. `resource` is * usually specified as a path. For example, a Project resource is specified as * `projects/{project}`. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final Policy getIamPolicy(String resource) { GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build(); return getIamPolicy(request); }