Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pub/Sub SPI: Adding IAM methods and auto-generated unit tests #1219

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion google-cloud-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-common-protos</artifactId>
<version>0.0.7</version>
<version>0.0.9</version>
</dependency>
</dependencies>
</project>
2 changes: 1 addition & 1 deletion google-cloud-pubsub/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-pubsub-v1</artifactId>
<version>0.0.7</version>
<version>0.0.9</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
import com.google.api.gax.core.PageAccessor;
import com.google.api.gax.grpc.ApiCallable;
import com.google.api.gax.protobuf.PathTemplate;
import com.google.iam.v1.GetIamPolicyRequest;
import com.google.iam.v1.Policy;
import com.google.iam.v1.SetIamPolicyRequest;
import com.google.iam.v1.TestIamPermissionsRequest;
import com.google.iam.v1.TestIamPermissionsResponse;
import com.google.protobuf.ByteString;
import com.google.protobuf.Empty;
import com.google.pubsub.v1.DeleteTopicRequest;
Expand Down Expand Up @@ -105,6 +110,10 @@ public class PublisherApi implements AutoCloseable {
private final ApiCallable<ListTopicSubscriptionsRequest, PageAccessor<String>>
listTopicSubscriptionsPagedCallable;
private final ApiCallable<DeleteTopicRequest, Empty> deleteTopicCallable;
private final ApiCallable<SetIamPolicyRequest, Policy> setIamPolicyCallable;
private final ApiCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable;
private final ApiCallable<TestIamPermissionsRequest, TestIamPermissionsResponse>
testIamPermissionsCallable;

public final PublisherSettings getSettings() {
return settings;
Expand Down Expand Up @@ -204,6 +213,12 @@ protected PublisherApi(PublisherSettings settings) throws IOException {
settings.listTopicSubscriptionsSettings(), this.channel, this.executor);
this.deleteTopicCallable =
ApiCallable.create(settings.deleteTopicSettings(), this.channel, this.executor);
this.setIamPolicyCallable =
ApiCallable.create(settings.setIamPolicySettings(), this.channel, this.executor);
this.getIamPolicyCallable =
ApiCallable.create(settings.getIamPolicySettings(), this.channel, this.executor);
this.testIamPermissionsCallable =
ApiCallable.create(settings.testIamPermissionsSettings(), this.channel, this.executor);

if (settings.getChannelProvider().shouldAutoClose()) {
closeables.add(
Expand Down Expand Up @@ -726,6 +741,230 @@ public final ApiCallable<DeleteTopicRequest, Empty> deleteTopicCallable() {
return deleteTopicCallable;
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Sets the access control policy on the specified resource. Replaces any
* existing policy.
*
* Sample code:
* <pre><code>
* try (PublisherApi publisherApi = PublisherApi.create()) {
* String formattedResource = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
* Policy policy = Policy.newBuilder().build();
* Policy response = publisherApi.setIamPolicy(formattedResource, policy);
* }
* </code></pre>
*
* @param resource REQUIRED: The resource for which policy is being specified.
* Resource is usually specified as a path, such as,
* projects/{project}/zones/{zone}/disks/{disk}.
* @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 in general a
* valid policy but certain services (like Projects) might reject them.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final Policy setIamPolicy(String resource, Policy policy) {
TOPIC_PATH_TEMPLATE.validate(resource, "setIamPolicy");
SetIamPolicyRequest request =
SetIamPolicyRequest.newBuilder().setResource(resource).setPolicy(policy).build();
return setIamPolicy(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Sets the access control policy on the specified resource. Replaces any
* existing policy.
*
* Sample code:
* <pre><code>
* try (PublisherApi publisherApi = PublisherApi.create()) {
* String formattedResource = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
* Policy policy = Policy.newBuilder().build();
* SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
* .setResource(formattedResource)
* .setPolicy(policy)
* .build();
* Policy response = publisherApi.setIamPolicy(request);
* }
* </code></pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final Policy setIamPolicy(SetIamPolicyRequest request) {
return setIamPolicyCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Sets the access control policy on the specified resource. Replaces any
* existing policy.
*
* Sample code:
* <pre><code>
* try (PublisherApi publisherApi = PublisherApi.create()) {
* String formattedResource = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
* Policy policy = Policy.newBuilder().build();
* SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder()
* .setResource(formattedResource)
* .setPolicy(policy)
* .build();
* ListenableFuture&lt;Policy&gt; future = publisherApi.setIamPolicyCallable().futureCall(request);
* // Do something
* Policy response = future.get();
* }
* </code></pre>
*/
public final ApiCallable<SetIamPolicyRequest, Policy> setIamPolicyCallable() {
return setIamPolicyCallable;
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Gets the access control policy for a resource. Is empty if the
* policy or the resource does not exist.
*
* Sample code:
* <pre><code>
* try (PublisherApi publisherApi = PublisherApi.create()) {
* String formattedResource = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
* Policy response = publisherApi.getIamPolicy(formattedResource);
* }
* </code></pre>
*
* @param resource REQUIRED: The resource for which policy is being requested. Resource
* is usually specified as a path, such as, projects/{project}.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final Policy getIamPolicy(String resource) {
TOPIC_PATH_TEMPLATE.validate(resource, "getIamPolicy");
GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder().setResource(resource).build();
return getIamPolicy(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Gets the access control policy for a resource. Is empty if the
* policy or the resource does not exist.
*
* Sample code:
* <pre><code>
* try (PublisherApi publisherApi = PublisherApi.create()) {
* String formattedResource = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
* GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
* .setResource(formattedResource)
* .build();
* Policy response = publisherApi.getIamPolicy(request);
* }
* </code></pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
private final Policy getIamPolicy(GetIamPolicyRequest request) {
return getIamPolicyCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Gets the access control policy for a resource. Is empty if the
* policy or the resource does not exist.
*
* Sample code:
* <pre><code>
* try (PublisherApi publisherApi = PublisherApi.create()) {
* String formattedResource = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
* GetIamPolicyRequest request = GetIamPolicyRequest.newBuilder()
* .setResource(formattedResource)
* .build();
* ListenableFuture&lt;Policy&gt; future = publisherApi.getIamPolicyCallable().futureCall(request);
* // Do something
* Policy response = future.get();
* }
* </code></pre>
*/
public final ApiCallable<GetIamPolicyRequest, Policy> getIamPolicyCallable() {
return getIamPolicyCallable;
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Returns permissions that a caller has on the specified resource.
*
* Sample code:
* <pre><code>
* try (PublisherApi publisherApi = PublisherApi.create()) {
* String formattedResource = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
* List&lt;String&gt; permissions = new ArrayList&lt;&gt;();
* TestIamPermissionsResponse response = publisherApi.testIamPermissions(formattedResource, permissions);
* }
* </code></pre>
*
* @param resource REQUIRED: The resource for which policy detail is being requested.
* Resource is usually specified as a path, such as, projects/{project}.
* @param permissions The set of permissions to check for the 'resource'. Permissions with
* wildcards (such as '&ast;' or 'storage.&ast;') are not allowed.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final TestIamPermissionsResponse testIamPermissions(
String resource, List<String> permissions) {
TOPIC_PATH_TEMPLATE.validate(resource, "testIamPermissions");
TestIamPermissionsRequest request =
TestIamPermissionsRequest.newBuilder()
.setResource(resource)
.addAllPermissions(permissions)
.build();
return testIamPermissions(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Returns permissions that a caller has on the specified resource.
*
* Sample code:
* <pre><code>
* try (PublisherApi publisherApi = PublisherApi.create()) {
* String formattedResource = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
* List&lt;String&gt; permissions = new ArrayList&lt;&gt;();
* TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
* .setResource(formattedResource)
* .addAllPermissions(permissions)
* .build();
* TestIamPermissionsResponse response = publisherApi.testIamPermissions(request);
* }
* </code></pre>
*
* @param request The request object containing all of the parameters for the API call.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final TestIamPermissionsResponse testIamPermissions(TestIamPermissionsRequest request) {
return testIamPermissionsCallable().call(request);
}

// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Returns permissions that a caller has on the specified resource.
*
* Sample code:
* <pre><code>
* try (PublisherApi publisherApi = PublisherApi.create()) {
* String formattedResource = PublisherApi.formatTopicName("[PROJECT]", "[TOPIC]");
* List&lt;String&gt; permissions = new ArrayList&lt;&gt;();
* TestIamPermissionsRequest request = TestIamPermissionsRequest.newBuilder()
* .setResource(formattedResource)
* .addAllPermissions(permissions)
* .build();
* ListenableFuture&lt;TestIamPermissionsResponse&gt; future = publisherApi.testIamPermissionsCallable().futureCall(request);
* // Do something
* TestIamPermissionsResponse response = future.get();
* }
* </code></pre>
*/
public final ApiCallable<TestIamPermissionsRequest, TestIamPermissionsResponse>
testIamPermissionsCallable() {
return testIamPermissionsCallable;
}

/**
* Initiates an orderly shutdown in which preexisting calls continue but new calls are immediately
* cancelled.
Expand Down
Loading