Repository navigation
Working Google Auth example with PubSub API ListTopics for a project ID and a markdown file - GOOGLE_AUTH_EXAMPLE.md - #5162
Conversation
|
|
||
| - [Json serialization](src/main/java/io/grpc/examples/advanced) | ||
|
|
||
| - [Google Authentication](GOOGLE_AUTH_EXAMPLE.md) |
There was a problem hiding this comment.
As this pulls in pub-sub and Google Cloud account as dependency, it might be better to move it from Basic Examples section to Other Examples section, and move the code to a separate project, in parallel with tls, alts, android, kotlin.
There was a problem hiding this comment.
Yes, good point. Let me look into it
| deps = [":route_guide_java_proto"], | ||
| ) | ||
|
|
||
| proto_library( |
There was a problem hiding this comment.
I believe you can depend on the canonical build defs:
I think you need to add this to the WORKSPACE file, and then reference it below.
There was a problem hiding this comment.
@carl-mastrangelo with the changes I made does this still apply? I have been able to get it to build without WORKSPACE file changes.
| */ | ||
| public GoogleAuthClient(String host, int port, CallCredentials callCredentials) { | ||
| // Google API invocation requires a secure channel. Channels are secure by default (SSL/TLS) | ||
| this(ManagedChannelBuilder.forAddress(host, port) |
There was a problem hiding this comment.
I believe this can fit on a single line. Also, we typically break lines at the highest semantic level, which would imply keeping the entire argument to this() on a single line. The this( and ) can be on separate lines though, if needed.
| // credentials must be refreshed before the access token is available | ||
| credentials.refreshIfExpired(); | ||
| credentials.getAccessToken(); | ||
| GoogleAuthClient client = new GoogleAuthClient("pubsub.googleapis.com", 443, |
There was a problem hiding this comment.
same comment here. Prefer to break at new GoogleAuthClient( or on =, to keep as much of the pieces together.
Added another MD file for GOOGLE_AUTH_EXAMPLE
68dfcbb to
ae7084b
Compare
ae7084b to
7dbe6b6
Compare
…f a conflict with grpc-auth
|
@carl-mastrangelo @dapengzhang0 pls review and approve as appropriate |
| from a maven repository. But if you need the latest SNAPSHOT binaries you will need to follow | ||
| [COMPILING](../COMPILING.md) to build these. | ||
|
|
||
| The source code is [here](src/main/java/io/grpc/examples/googleAuth). Please follow the |
There was a problem hiding this comment.
No need to point to the source code. The current directory contains only this example.
| ``` | ||
|
|
||
| ## Maven | ||
| If you prefer to use Maven follow these [steps](../README.md#maven). You can run the example as follows: |
There was a problem hiding this comment.
As the [steps] is only a few lines, copy them directly here might be more straightforward for the readers than a link
If you prefer to use Maven:
1. **[Install gRPC Java library SNAPSHOT locally, including code generation plugin](../../COMPILING.md) (Only need this step for non-released versions, e.g. master HEAD).**
2. Run in this directory
```
$ mvn verify| (With Bazel v0.8.0 or above.) | ||
| $ bazel build :google-auth-client | ||
| $ # Run the client | ||
| $ ../bazel-bin/google-auth-client /path/to/JSON/file projects/xyz123 |
There was a problem hiding this comment.
$ bazel-bin/google-auth-client /path/to/JSON/file projects/xyz123
There was a problem hiding this comment.
@dapengzhang0 ../bazel-bin is correct. I don't see bazel-bin created in the current directory but in ... Same is true for example-tls so that readme also needs to be fixed?
There was a problem hiding this comment.
You're right. I should also fix example-tls.
|
|
||
| proto_library( | ||
| name = "pubsub_proto", | ||
| srcs = ["src/main/proto/pubsub.proto"], |
There was a problem hiding this comment.
I agree with @carl-mastrangelo 's comment to add an artifact in examples/WORKSPACE for pubsub proto, instead of copying their proto.
And in build.gradle and pom.xml add dependency com.google.api.grpc:grpc-google-cloud-pubsub-v1
And remove pubsub.proto.
| import com.google.pubsub.v1.ListTopicsResponse; | ||
| import com.google.pubsub.v1.ListTopicsRequest; | ||
|
|
||
| import java.io.FileInputStream; |
There was a problem hiding this comment.
Here's our style guide http://go/java-style
Imports should be sorted and no line break here.
| * | ||
| * Also @see <a href="https://cloud.google.com/pubsub/docs/reference/rpc/">Google Cloud Pubsub via gRPC</a> | ||
| * | ||
| */ |
| * the project ID for the project you created. | ||
| */ | ||
| public void getTopics(String projectID) { | ||
| logger.info("Will try to get topics for poroject " + projectID + " ..."); |
There was a problem hiding this comment.
nit: use logger.log(Level.INFO, "{}", ) pattern to avoid string concat if logging level is higher than INFO.
| logger.log(Level.WARNING, "RPC failed: {0}", e.getStatus()); | ||
| return; | ||
| } | ||
| logger.info("Topics list:\n" + response.getTopicsList()); |
carl-mastrangelo
left a comment
There was a problem hiding this comment.
Code and comments generally LGTM. I would still prefer you link using the bazel WORKSPACE file, but if it proves difficult then don't spend too much time on it.
|
close and reopen to rerun tests |
|
reopen |
|
close->reopen to test |
|
reopen to test |
|
@sanjaypujare You can add the "kokoro:force-run" label to retrigger the CI. |
|
@carl-mastrangelo thanks - will keep that in mind. BTW I am unable to merge because of unrelated errors below. Do you know what the issue is and how I can resolve it?
|
|
We can work around this specific problem, but do file a bug to https://github.com/bazelbuild/bazel and include the full stack trace of the error. |
0ef8aa8 to
e27aa04
Compare
@carl-mastrangelo @dapengzhang0 pls review.