@Override public Map<String, String> extract(SetIamPolicyRequest request) { ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); params.put("resource", String.valueOf(request.getResource())); return params.build(); } })
/** * 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); }
@Test @SuppressWarnings("all") public void setIamPolicyTest() { int version = 351608024; ByteString etag = ByteString.copyFromUtf8("21"); Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build(); mockCloudTasks.addResponse(expectedResponse); QueueName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); Policy policy = Policy.newBuilder().build(); Policy actualResponse = client.setIamPolicy(resource, policy); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockCloudTasks.getRequests(); Assert.assertEquals(1, actualRequests.size()); SetIamPolicyRequest actualRequest = (SetIamPolicyRequest) actualRequests.get(0); Assert.assertEquals(Objects.toString(resource), Objects.toString(actualRequest.getResource())); Assert.assertEquals(policy, actualRequest.getPolicy()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
private static io.grpc.MethodDescriptor< com.google.iam.v1.SetIamPolicyRequest, com.google.iam.v1.Policy> getSetIamPolicyMethodHelper() { io.grpc.MethodDescriptor<com.google.iam.v1.SetIamPolicyRequest, com.google.iam.v1.Policy> getSetIamPolicyMethod; if ((getSetIamPolicyMethod = CloudTasksGrpc.getSetIamPolicyMethod) == null) { synchronized (CloudTasksGrpc.class) { if ((getSetIamPolicyMethod = CloudTasksGrpc.getSetIamPolicyMethod) == null) { CloudTasksGrpc.getSetIamPolicyMethod = getSetIamPolicyMethod = io.grpc.MethodDescriptor .<com.google.iam.v1.SetIamPolicyRequest, com.google.iam.v1.Policy>newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName( generateFullMethodName( "google.cloud.tasks.v2beta3.CloudTasks", "SetIamPolicy")) .setSampledToLocalTracing(true) .setRequestMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.iam.v1.SetIamPolicyRequest.getDefaultInstance())) .setResponseMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.iam.v1.Policy.getDefaultInstance())) .setSchemaDescriptor(new CloudTasksMethodDescriptorSupplier("SetIamPolicy")) .build(); } } } return getSetIamPolicyMethod; }
@Test @SuppressWarnings("all") public void setIamPolicyTest() { int version = 351608024; ByteString etag = ByteString.copyFromUtf8("21"); Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build(); mockIAMPolicy.addResponse(expectedResponse); KeyName resource = KeyRingName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]"); Policy policy = Policy.newBuilder().build(); Policy actualResponse = client.setIamPolicy(resource, policy); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockIAMPolicy.getRequests(); Assert.assertEquals(1, actualRequests.size()); SetIamPolicyRequest actualRequest = (SetIamPolicyRequest) actualRequests.get(0); Assert.assertEquals(Objects.toString(resource), Objects.toString(actualRequest.getResource())); Assert.assertEquals(policy, actualRequest.getPolicy()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
.setRequestMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.iam.v1.SetIamPolicyRequest.getDefaultInstance())) .setResponseMarshaller( io.grpc.protobuf.ProtoUtils.marshaller(
@Test @SuppressWarnings("all") public void setIamPolicyTest() { int version = 351608024; ByteString etag = ByteString.copyFromUtf8("21"); Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build(); mockCloudTasks.addResponse(expectedResponse); QueueName resource = QueueName.of("[PROJECT]", "[LOCATION]", "[QUEUE]"); Policy policy = Policy.newBuilder().build(); Policy actualResponse = client.setIamPolicy(resource, policy); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockCloudTasks.getRequests(); Assert.assertEquals(1, actualRequests.size()); SetIamPolicyRequest actualRequest = (SetIamPolicyRequest) actualRequests.get(0); Assert.assertEquals(Objects.toString(resource), Objects.toString(actualRequest.getResource())); Assert.assertEquals(policy, actualRequest.getPolicy()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
SetIamPolicyRequest.newBuilder() .setResource(resource == null ? null : resource.toString()) .setPolicy(policy)
.setRequestMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.iam.v1.SetIamPolicyRequest.getDefaultInstance())) .setResponseMarshaller( io.grpc.protobuf.ProtoUtils.marshaller(
@Override public Map<String, String> extract(SetIamPolicyRequest request) { ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); params.put("resource", String.valueOf(request.getResource())); return params.build(); } })
@Test @SuppressWarnings("all") public void setIamPolicyTest() { int version = 351608024; ByteString etag = ByteString.copyFromUtf8("21"); Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build(); mockDeviceManager.addResponse(expectedResponse); RegistryName resource = RegistryName.of("[PROJECT]", "[LOCATION]", "[REGISTRY]"); Policy policy = Policy.newBuilder().build(); Policy actualResponse = client.setIamPolicy(resource, policy); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockDeviceManager.getRequests(); Assert.assertEquals(1, actualRequests.size()); SetIamPolicyRequest actualRequest = (SetIamPolicyRequest) actualRequests.get(0); Assert.assertEquals(Objects.toString(resource), Objects.toString(actualRequest.getResource())); Assert.assertEquals(policy, actualRequest.getPolicy()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
/** * 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); }
private static io.grpc.MethodDescriptor< com.google.iam.v1.SetIamPolicyRequest, com.google.iam.v1.Policy> getSetIamPolicyMethodHelper() { io.grpc.MethodDescriptor<com.google.iam.v1.SetIamPolicyRequest, com.google.iam.v1.Policy> getSetIamPolicyMethod; if ((getSetIamPolicyMethod = CloudTasksGrpc.getSetIamPolicyMethod) == null) { synchronized (CloudTasksGrpc.class) { if ((getSetIamPolicyMethod = CloudTasksGrpc.getSetIamPolicyMethod) == null) { CloudTasksGrpc.getSetIamPolicyMethod = getSetIamPolicyMethod = io.grpc.MethodDescriptor .<com.google.iam.v1.SetIamPolicyRequest, com.google.iam.v1.Policy>newBuilder() .setType(io.grpc.MethodDescriptor.MethodType.UNARY) .setFullMethodName( generateFullMethodName( "google.cloud.tasks.v2beta2.CloudTasks", "SetIamPolicy")) .setSampledToLocalTracing(true) .setRequestMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.iam.v1.SetIamPolicyRequest.getDefaultInstance())) .setResponseMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.iam.v1.Policy.getDefaultInstance())) .setSchemaDescriptor(new CloudTasksMethodDescriptorSupplier("SetIamPolicy")) .build(); } } } return getSetIamPolicyMethod; }
@Override public Map<String, String> extract(SetIamPolicyRequest request) { ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); params.put("resource", String.valueOf(request.getResource())); return params.build(); } })
@Test @SuppressWarnings("all") public void setIamPolicyTest() { int version = 351608024; ByteString etag = ByteString.copyFromUtf8("21"); Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build(); mockIAMPolicy.addResponse(expectedResponse); String formattedResource = ProjectSubscriptionName.format("[PROJECT]", "[SUBSCRIPTION]"); Policy policy = Policy.newBuilder().build(); Policy actualResponse = client.setIamPolicy(formattedResource, policy); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockIAMPolicy.getRequests(); Assert.assertEquals(1, actualRequests.size()); SetIamPolicyRequest actualRequest = (SetIamPolicyRequest) actualRequests.get(0); Assert.assertEquals(formattedResource, actualRequest.getResource()); Assert.assertEquals(policy, actualRequest.getPolicy()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
/** * 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); }
.setRequestMarshaller( io.grpc.protobuf.ProtoUtils.marshaller( com.google.iam.v1.SetIamPolicyRequest.getDefaultInstance())) .setResponseMarshaller( io.grpc.protobuf.ProtoUtils.marshaller(
@Override public Map<String, String> extract(SetIamPolicyRequest request) { ImmutableMap.Builder<String, String> params = ImmutableMap.builder(); params.put("resource", String.valueOf(request.getResource())); return params.build(); } })
@Test @SuppressWarnings("all") public void setIamPolicyTest() { int version = 351608024; ByteString etag = ByteString.copyFromUtf8("21"); Policy expectedResponse = Policy.newBuilder().setVersion(version).setEtag(etag).build(); mockInstanceAdmin.addResponse(expectedResponse); String formattedResource = InstanceName.format("[PROJECT]", "[INSTANCE]"); Policy policy = Policy.newBuilder().build(); Policy actualResponse = client.setIamPolicy(formattedResource, policy); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockInstanceAdmin.getRequests(); Assert.assertEquals(1, actualRequests.size()); SetIamPolicyRequest actualRequest = (SetIamPolicyRequest) actualRequests.get(0); Assert.assertEquals(formattedResource, actualRequest.getResource()); Assert.assertEquals(policy, actualRequest.getPolicy()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
/** * 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); }