Skip to content

Working Google Auth example with PubSub API ListTopics for a project ID and a markdown file - GOOGLE_AUTH_EXAMPLE.md - #5162

Merged
sanjaypujare merged 6 commits into
grpc:masterfrom
sanjaypujare:google-auth-example
Dec 19, 2018
Merged

sanjaypujare merged 6 commits into
grpc:masterfrom
sanjaypujare:google-auth-example

Conversation

@sanjaypujare

Copy link
Copy Markdown
Contributor

@dapengzhang0 dapengzhang0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

Comment thread examples/README.md Outdated

- [Json serialization](src/main/java/io/grpc/examples/advanced)

- [Google Authentication](GOOGLE_AUTH_EXAMPLE.md)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point. Let me look into it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved

Comment thread examples/BUILD.bazel Outdated
deps = [":route_guide_java_proto"],
)

proto_library(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you can depend on the canonical build defs:

https://github.com/googleapis/googleapis/blob/master/google/pubsub/v1/BUILD.bazel

I think you need to add this to the WORKSPACE file, and then reference it below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment here. Prefer to break at new GoogleAuthClient( or on =, to keep as much of the pieces together.

@sanjaypujare

Copy link
Copy Markdown
Contributor Author

@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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$ bazel-bin/google-auth-client /path/to/JSON/file projects/xyz123

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I should also fix example-tls.

Comment thread examples/example-gauth/BUILD.bazel Outdated

proto_library(
name = "pubsub_proto",
srcs = ["src/main/proto/pubsub.proto"],

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*
* Also @see <a href="https://cloud.google.com/pubsub/docs/reference/rpc/">Google Cloud Pubsub via gRPC</a>
*
*/

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: empty line

* the project ID for the project you created.
*/
public void getTopics(String projectID) {
logger.info("Will try to get topics for poroject " + projectID + " ...");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Dito.

@carl-mastrangelo carl-mastrangelo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@dapengzhang0 dapengzhang0 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sanjaypujare

Copy link
Copy Markdown
Contributor Author

close and reopen to rerun tests

@sanjaypujare

Copy link
Copy Markdown
Contributor Author

reopen

@sanjaypujare sanjaypujare reopened this Dec 15, 2018
@sanjaypujare

Copy link
Copy Markdown
Contributor Author

close->reopen to test

@sanjaypujare

Copy link
Copy Markdown
Contributor Author

reopen to test

@sanjaypujare sanjaypujare reopened this Dec 16, 2018
@carl-mastrangelo

Copy link
Copy Markdown
Contributor

@sanjaypujare You can add the "kokoro:force-run" label to retrigger the CI.

@sanjaypujare

Copy link
Copy Markdown
Contributor Author

@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?

  • cd github/grpc-java
  • bazel build ...
    Starting local Bazel server and connecting to it...
    INFO: Invocation ID: 79e7719a-8eb4-4a80-bb70-93cdeef481ac
    Loading:
    Loading: 0 packages loaded
    Loading: 18 packages loaded
    Analyzing: 68 targets (19 packages loaded)
    Analyzing: 68 targets (20 packages loaded, 0 targets configured)
    Internal error thrown during build. Printing stack trace: java.lang.RuntimeException: Unrecoverable error while evaluating node 'REPOSITORY_DIRECTORY:@com_google_protobuf' (requested by nodes 'REPOSITORY:@com_google_protobuf')
    at com.google.devtools.build.skyframe.AbstractParallelEvaluator$Evaluate.run(AbstractParallelEvaluator.java:499)
    at com.google.devtools.build.lib.concurrent.AbstractQueueVisitor$WrappedRunnable.run(AbstractQueueVisitor.java:368)

@carl-mastrangelo

Copy link
Copy Markdown
Contributor

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.

@sanjaypujare sanjaypujare added the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Dec 19, 2018
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Dec 19, 2018
@sanjaypujare sanjaypujare added the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Dec 19, 2018
@kokoro-team kokoro-team removed the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Dec 19, 2018
@sanjaypujare
sanjaypujare merged commit 847eae8 into grpc:master Dec 19, 2018
@lock lock Bot locked as resolved and limited conversation to collaborators Mar 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants