Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Move CredentialProvider up to ClientSettings #305

Merged
merged 8 commits into from
May 22, 2017
Merged

Move CredentialProvider up to ClientSettings #305

merged 8 commits into from
May 22, 2017

Conversation

pongad
Copy link
Contributor

@pongad pongad commented May 8, 2017

Updates googleapis/google-cloud-java#2034.

This commit should resolve the first 3 bullets in the
linked issue.

The generated code needs to be updated to take advantage
of this added functionality.

Updates googleapis/google-cloud-java#2034.

This commit should resolve the first 3 bullets in the
linked issue.

The generated code needs to be updated to take advantage
of this added functionality.
@codecov-io
Copy link

codecov-io commented May 8, 2017

Codecov Report

Merging #305 into master will decrease coverage by 1.04%.
The diff coverage is 61.53%.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #305      +/-   ##
============================================
- Coverage     70.98%   69.93%   -1.05%     
- Complexity      350      352       +2     
============================================
  Files            69       72       +3     
  Lines          1844     1906      +62     
  Branches        154      155       +1     
============================================
+ Hits           1309     1333      +24     
- Misses          469      506      +37     
- Partials         66       67       +1
Impacted Files Coverage Δ Complexity Δ
.../com/google/longrunning/PagedResponseWrappers.java 83.33% <ø> (ø) 0 <0> (ø) ⬇️
...va/com/google/api/gax/grpc/ChannelAndExecutor.java 0% <ø> (-75%) 0 <0> (-3)
...gle/api/gax/grpc/InstantiatingChannelProvider.java 47.95% <ø> (ø) 9 <0> (ø) ⬇️
...com/google/api/gax/grpc/OperationCallSettings.java 0% <0%> (ø) 0 <0> (ø) ⬇️
...com/google/api/gax/core/NoCredentialsProvider.java 0% <0%> (ø) 0 <0> (?)
.../com/google/api/gax/grpc/BatchingCallSettings.java 76.47% <0%> (-2.32%) 3 <0> (ø)
.../java/com/google/longrunning/OperationsClient.java 95.45% <100%> (+2.59%) 17 <0> (ø) ⬇️
...ava/com/google/api/gax/grpc/PagedCallSettings.java 91.66% <100%> (ø) 5 <2> (ø) ⬇️
...om/google/api/gax/grpc/UnaryCallSettingsTyped.java 90% <100%> (+1.11%) 3 <0> (ø) ⬇️
...va/com/google/api/gax/grpc/SimpleCallSettings.java 100% <100%> (ø) 4 <1> (ø) ⬇️
... and 11 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ab7aa82...994737d. Read the comment docs.

@@ -328,4 +329,8 @@ public ResponseT call(RequestT request) {
return new UnaryCallable<>(
new BatchingCallable<>(callable, batchingDescriptor, batcherFactory), channel, settings);
}

UnaryCallable<RequestT, ResponseT> auth(CallCredentials credentials) {

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

import com.google.common.base.Preconditions;
import io.grpc.CallCredentials;

class AuthCallable<RequestT, ResponseT> implements FutureCallable<RequestT, ResponseT> {

This comment was marked as spam.

This comment was marked as spam.

@@ -328,4 +329,8 @@ public ResponseT call(RequestT request) {
return new UnaryCallable<>(
new BatchingCallable<>(callable, batchingDescriptor, batcherFactory), channel, settings);
}

UnaryCallable<RequestT, ResponseT> auth(CallCredentials credentials) {

This comment was marked as spam.

Copy link
Member

@garrettjonesgoogle garrettjonesgoogle left a comment

Choose a reason for hiding this comment

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

I think we should see how this looks in the generated code before submitting this PR.

@@ -0,0 +1,52 @@
/*
* Copyright 2016, Google Inc. All rights reserved.

This comment was marked as spam.

This comment was marked as spam.

@@ -328,4 +329,8 @@ public ResponseT call(RequestT request) {
return new UnaryCallable<>(
new BatchingCallable<>(callable, batchingDescriptor, batcherFactory), channel, settings);
}

UnaryCallable<RequestT, ResponseT> auth(CallCredentials credentials) {

This comment was marked as spam.

@@ -328,4 +329,8 @@ public ResponseT call(RequestT request) {
return new UnaryCallable<>(
new BatchingCallable<>(callable, batchingDescriptor, batcherFactory), channel, settings);
}

UnaryCallable<RequestT, ResponseT> auth(CallCredentials credentials) {

This comment was marked as spam.

This comment was marked as spam.

@pongad
Copy link
Contributor Author

pongad commented May 8, 2017

@garrettjonesgoogle @shinfan PTAL.

@garrettjonesgoogle
Copy link
Member

LGTM pending how generated code looks

@pongad
Copy link
Contributor Author

pongad commented May 9, 2017

@shinfan @garrettjonesgoogle Sorry this is actually a lot bigger than I thought. PTAL.

Due to how much this touches the callable stack, I think this deserves a smoke-test session to verify. I didn't have time to do this today, but the code should be close enough to review.

Major changes are:
- ClientContext is added to pull together channel, executor, and credentials,
  which are often needed together.
  This change will also simplify future work if more ClientSettings are added.
- The above change requires a corresponding change in toolkit.
  OperationsClient is updated using the new toolkit.
@@ -0,0 +1,73 @@
/*
* Copyright 2016, Google Inc. All rights reserved.

This comment was marked as spam.

This comment was marked as spam.

* <p>Unlike {@link ClientSettings} which allows users to configure the client, {@code
* ClientInitContext} gathers members to simplify initialization later on.
*
* <p>It it intended to be used in generated code. Most users will not need to use it.

This comment was marked as spam.

This comment was marked as spam.

.setExecutor(this.executor)
.setChannel(this.channel)
.setCallCredentials(callCredentials)
.build();

This comment was marked as spam.

This comment was marked as spam.

@@ -472,6 +475,9 @@ public void callSettingsTimeoutNoRetries() throws IOException {
.setMaxRpcTimeout(timeout));
FakeSettings settingsB = builderB.build();

System.err.println(builderA);
System.err.println(builderB);

This comment was marked as spam.

This comment was marked as spam.

public abstract ScheduledExecutorService getExecutor();

@Nullable
public abstract CallCredentials getCallCredentials();

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@pongad
Copy link
Contributor Author

pongad commented May 12, 2017

@garrettjonesgoogle PTAL

}
});
}
closeables.addAll(clientContext.getCloseables());

This comment was marked as spam.

public abstract ScheduledExecutorService getExecutor();

@Nullable
public abstract CallCredentials getCallCredentials();

This comment was marked as spam.

*/
@BetaApi
@AutoValue
public abstract class ClientInitContext {

This comment was marked as spam.

This comment was marked as spam.

return new AutoValue_ClientInitContext.Builder();
}

public static ClientInitContext initialize(ClientSettings settings) throws IOException {

This comment was marked as spam.

This comment was marked as spam.

@@ -48,77 +48,76 @@
@BetaApi
public final class OperationCallable<RequestT, ResponseT extends Message> {
private final UnaryCallable<RequestT, Operation> initialCallable;
private final Channel channel;
private final ScheduledExecutorService executor;
private final ClientInitContext clientContext;

This comment was marked as spam.

@pongad
Copy link
Contributor Author

pongad commented May 15, 2017

@garrettjonesgoogle PTAL

return this;
}
return new UnaryCallable<>(
new AuthCallable<>(callable, MoreCallCredentials.from(credentials)), channel, settings);

This comment was marked as spam.

This comment was marked as spam.

import javax.annotation.Nullable;

/**
* Encapsulates data used to initialize a client.

This comment was marked as spam.

This comment was marked as spam.

* Encapsulates data used to initialize a client.
*
* <p>Unlike {@link ClientSettings} which allows users to configure the client, {@code
* ClientContext} gathers members to simplify initialization later on.

This comment was marked as spam.

This comment was marked as spam.

@@ -261,12 +263,14 @@ public Builder setExecutorProvider(ExecutorProvider executorProvider) {
* Sets the CredentialsProvider which will acquire the credentials for making calls to the
* service. Credentials will not be acquired until they are required.
*/
@Deprecated
public Builder setCredentialsProvider(CredentialsProvider credentialsProvider) {

This comment was marked as spam.

This comment was marked as spam.

@@ -106,11 +103,9 @@
* </pre>
*/
@Generated("by GAPIC")
@ExperimentalApi
@BetaApi

This comment was marked as spam.

This comment was marked as spam.

@pongad
Copy link
Contributor Author

pongad commented May 18, 2017

@garrettjonesgoogle PTAL. I just realized streaming callable will require its own callable stack. Since this commit is backward-compatible, do you want to commit it first? Working in a separate branch is OK too, but I want to avoid the PR from getting too large.

Copy link
Member

@garrettjonesgoogle garrettjonesgoogle left a comment

Choose a reason for hiding this comment

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

LGTM after the minor whitespace thing.

I think we should commit this without bringing streaming callable into it, and do that as a follow-on (before doing any releases).

Don't submit until you submit the corresponding toolkit change that goes along with this.

import com.google.common.base.Preconditions;
import io.grpc.CallCredentials;
import io.grpc.auth.MoreCallCredentials;
/**

This comment was marked as spam.

This comment was marked as spam.

@pongad
Copy link
Contributor Author

pongad commented May 18, 2017

@garrettjonesgoogle The toolkit change is up for review at googleapis/gapic-generator#1251 .

Are you OK with merging toolkit without regenerating GCJ?

@garrettjonesgoogle
Copy link
Member

Yes I am ok with that since the change is non-breaking, but I do want the toolkit change updated given changes in the present PR (the toolkit one is out of date)

@pongad
Copy link
Contributor Author

pongad commented May 19, 2017

It is up to date except I forgot to update the baseline. Done.

pongad added a commit to googleapis/gapic-generator that referenced this pull request May 22, 2017
@pongad pongad merged commit 5830ace into googleapis:master May 22, 2017
@pongad pongad deleted the mv-cred branch May 22, 2017 01:34
pongad added a commit that referenced this pull request May 24, 2017
This fixes a bug introduced in #305.
UnaryCallable uses ClientContext to pass values.
To ease transition, old surfaces are marked deprecated
but reimplemented using ClientContext.

These old surfaces did not populate closeables,
so ClientContext cannot be initialized.
This PR side steps this problem by initializing closeables
to empty list.
garrettjonesgoogle added a commit to googleapis/gapic-generator that referenced this pull request May 27, 2017
* Fix JSON pretty print in Ruby sample (#1254)

* Ruby: README Overhaul (feat. examples) (#1245)

* go: use new metadata methods (#1262)

Updates googleapis/google-cloud-go#624.

metadata.FromContext and metdata.NewContext
are replaced by metadata.{New,From}{Incoming,Outgoing}Context.

Generated unit tests now verify that x-goog-api-client header
is inserted.

Additionally, clients now save a string slice containing x-goog-api-client
header value instead of the value by itself.
This is a small optimization so that we don't create a new slice every time.

* Change media body from an object to a string (#1256)

Samples fail before sending a request if the media body is an object.

* Fix NONE auth Go sample (#1261)

* Change Node.js unit test require. (#1264)

* Ruby: Allow doc gapic generation to generate tests. (#1266)

* Ruby: Remove aliasing from method samples and tests (#1253)

* Ruby: Fix broken baselines from aliasing fix (#1269)

* Remove unused code (#1270)

* Python: README overhaul. (#1263)

* Ruby: Update gemspec and add useful metadata files (#1258)

* Ruby: Update gemspec and add useful metadata files

* Specify HTTP client when constructing client (#1275)

If a HTTP client is not passed to `build`, the Google API Python client
will create a default one and attempt to authenticate it. This causes
failures in environments where ADC auth is not available (Travis).

In any case, it's not useful to access any auth code in the mock tests.
This commit removes that possibility.

* Fix JSON print in Ruby (#1274)

It turns out that `to_h` is not a method available on every object
returned by the samples at the moment. Also, there's some kind of
decoding bug showing up in certain samples where the JSON module is
unable to unparse the response.

It's troublesome to have so much boilerplate just to pretty print. This
commit removes the pretty calls in favor of the vanilla `to_json` method
implemented by the base model class in the Ruby client. In the future,
once the bugs w.r.t `pretty_generate` have been resolved, we can revert.

* NodeJS: Update version index to support partial veneers (#1267)

* NodeJS: Updates to package.json (#1268)

* Migrate import disambiguation to Python MVVM (#1243)

* Fix Node package.json (#1282)

* go: use time.UnixNano instead of testutil.UIDSpace (#1279)

Since generated code should be testable from api-client-staging repo,
we want to reduce dependency on other cloud.google.com/go packages,
especially internal ones.

Clients will still depend on testutil for ProjID and TokenSource.
This is OK, since they can be easily reimplemented in google-client-staging
repo itself.

* Update Java grpc metadata for new staging structure (#1265)

* PHP: share credentials with operations client (#1283)

* java: move CredentialProvider up to ClientSettings (#1251)

This implements the client side changes to support
googleapis/gax-java#305.

* NodeJS: generate readme. (#1240)

* NodeJS: Small additions to the package.json (#1289)

* NodeJS: Use fileheader for copyright lines. (#1293)

* NodeJS: Use correct casing for partial veneers (#1295)

* NodeJS: Small readme fix from GCN reviews (#1294)

* go: make longrunning methods use generated longrunning client (#1288)

The cloud.google.com/go/longrunning package will need to change
slightly to accomodate this change.

xGoogHeader is now gone from the generated longrunnging types,
as the header will be automatically inserted by LROClient itself.

* NodeJS: Update partial veneer surface to add api documentation. (#1296)

* NodeJS: Metadata updates. (#1298)

* Readme: Update readme templates to add api summaries. (#1299)

* Add PHP Exception tests (#951)

* Add exception tests
* Remove unnecessary checks in exception tests

* Process markdown cloud links for PHP (#1091)

* Process markdown cloud links for PHP
* Restructure comment formatting

* go: return error creating LRO client instead of panicking (#1300)
andreamlin added a commit to googleapis/gapic-generator that referenced this pull request Jun 5, 2017
* merge master to Discogapic (#1304)

* Fix JSON pretty print in Ruby sample (#1254)

* Ruby: README Overhaul (feat. examples) (#1245)

* go: use new metadata methods (#1262)

Updates googleapis/google-cloud-go#624.

metadata.FromContext and metdata.NewContext
are replaced by metadata.{New,From}{Incoming,Outgoing}Context.

Generated unit tests now verify that x-goog-api-client header
is inserted.

Additionally, clients now save a string slice containing x-goog-api-client
header value instead of the value by itself.
This is a small optimization so that we don't create a new slice every time.

* Change media body from an object to a string (#1256)

Samples fail before sending a request if the media body is an object.

* Fix NONE auth Go sample (#1261)

* Change Node.js unit test require. (#1264)

* Ruby: Allow doc gapic generation to generate tests. (#1266)

* Ruby: Remove aliasing from method samples and tests (#1253)

* Ruby: Fix broken baselines from aliasing fix (#1269)

* Remove unused code (#1270)

* Python: README overhaul. (#1263)

* Ruby: Update gemspec and add useful metadata files (#1258)

* Ruby: Update gemspec and add useful metadata files

* Specify HTTP client when constructing client (#1275)

If a HTTP client is not passed to `build`, the Google API Python client
will create a default one and attempt to authenticate it. This causes
failures in environments where ADC auth is not available (Travis).

In any case, it's not useful to access any auth code in the mock tests.
This commit removes that possibility.

* Fix JSON print in Ruby (#1274)

It turns out that `to_h` is not a method available on every object
returned by the samples at the moment. Also, there's some kind of
decoding bug showing up in certain samples where the JSON module is
unable to unparse the response.

It's troublesome to have so much boilerplate just to pretty print. This
commit removes the pretty calls in favor of the vanilla `to_json` method
implemented by the base model class in the Ruby client. In the future,
once the bugs w.r.t `pretty_generate` have been resolved, we can revert.

* NodeJS: Update version index to support partial veneers (#1267)

* NodeJS: Updates to package.json (#1268)

* Migrate import disambiguation to Python MVVM (#1243)

* Fix Node package.json (#1282)

* go: use time.UnixNano instead of testutil.UIDSpace (#1279)

Since generated code should be testable from api-client-staging repo,
we want to reduce dependency on other cloud.google.com/go packages,
especially internal ones.

Clients will still depend on testutil for ProjID and TokenSource.
This is OK, since they can be easily reimplemented in google-client-staging
repo itself.

* Update Java grpc metadata for new staging structure (#1265)

* PHP: share credentials with operations client (#1283)

* java: move CredentialProvider up to ClientSettings (#1251)

This implements the client side changes to support
googleapis/gax-java#305.

* NodeJS: generate readme. (#1240)

* NodeJS: Small additions to the package.json (#1289)

* NodeJS: Use fileheader for copyright lines. (#1293)

* NodeJS: Use correct casing for partial veneers (#1295)

* NodeJS: Small readme fix from GCN reviews (#1294)

* go: make longrunning methods use generated longrunning client (#1288)

The cloud.google.com/go/longrunning package will need to change
slightly to accomodate this change.

xGoogHeader is now gone from the generated longrunnging types,
as the header will be automatically inserted by LROClient itself.

* NodeJS: Update partial veneer surface to add api documentation. (#1296)

* NodeJS: Metadata updates. (#1298)

* Readme: Update readme templates to add api summaries. (#1299)

* Add PHP Exception tests (#951)

* Add exception tests
* Remove unnecessary checks in exception tests

* Process markdown cloud links for PHP (#1091)

* Process markdown cloud links for PHP
* Restructure comment formatting

* go: return error creating LRO client instead of panicking (#1300)

* fails b/c Node.empty() uses null params

* one test passes

* all current tests pass

* tests for Node parent()

* Test

* removed Method.empty():

* reordering methods for convention

* made Node.from(Node, path) methods package private

* removed path() from Document, Schema, and Method

* removed static constructors with empty parent node
@joaoandremartins
Copy link

Would be nice to point users somewhere in the Javadoc where the new way of providing credentials is explained.
Right now, I see that InstantiatingChannelProvider.Builder.setCredentialsProvider() is deprecated, but I have no idea how to pass credentials correctly.

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.

5 participants