-
Notifications
You must be signed in to change notification settings - Fork 620
Feature custom endpoint #2548
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
Feature custom endpoint #2548
Conversation
packages/bigquery/src/index.js
Outdated
var config = { | ||
baseUrl: 'https://www.googleapis.com/bigquery/v2', | ||
baseUrl: baseInfo.apiEndpoint + basePath, | ||
customEndpoint: baseInfo.customEndpoint, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Thank you very, very much for this! |
I signed it! |
googlebot is pretty feature-incomplete. @lukesneeringer can you make sure this is okay with the CLA? (re: #2548 (comment)) |
Yea, I can check on googlebot while you two get tests working. :-) |
Update: @rmanyari, our system still thinks you have not signed the CLA, and in the interest of my not being swarmed by mobs of angry lawyers, this is a prerequisite. The link is here: https://cla.developers.google.com/ If you are pretty sure you already signed it, the most likely problem is that the email address you used to do so does not match the email address on your commits ( If you need more help, let us know and I will try to get you in touch with someone who can help more. |
(Update) - Nevermind, googlebot clarified things ;) |
CLAs look good, thanks! |
@@ -202,11 +221,14 @@ function GrpcService(config, options) { | |||
|
|||
Object.keys(protoServices).forEach(function(name) { | |||
var protoConfig = protoServices[name]; | |||
var service = self.loadProtoFile_(protoConfig, config); | |||
var service = GrpcService.prototype.loadProtoFile_ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall, it's perfect. I have just two overall thoughts:
- I think we should wait until all APIs can adopt the new style before merging
- The tests in each API to be sure
Service
is working isn't necessary as long as theService
tests are sufficient and we know that we properly called it from the API constructor
packages/bigquery/test/index.js
Outdated
var baseUrl = 'https://www.googleapis.com/bigquery/v2'; | ||
assert.strictEqual(calledWith.baseUrl, baseUrl); | ||
assert.strictEqual(bq.baseUrl, baseUrl); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/bigquery/test/index.js
Outdated
assert.deepEqual(calledWith.scopes, [ | ||
'https://www.googleapis.com/auth/bigquery' | ||
]); | ||
assert.deepEqual(calledWith.packageJson, require('../package.json')); | ||
}); | ||
|
||
it('should not be considered custom endpoint if default', function() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/bigquery/test/index.js
Outdated
assert.strictEqual(bq.customEndpoint, false); | ||
}); | ||
|
||
it('should use options.apiEndpoint if defined', function() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/bigquery/test/index.js
Outdated
assert.strictEqual(bq.customEndpoint, true); | ||
}); | ||
|
||
it('should use GOOGLE_CLOUD_BIGQUERY_ENDPOINT if defined', function() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/bigtable/src/index.js
Outdated
protosDir: path.resolve(__dirname, '../protos'), | ||
protoServices: { | ||
Bigtable: { | ||
baseUrl: baseUrl, | ||
baseUrl: defaultApiEndpoint, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/bigtable/test/index.js
Outdated
}); | ||
}); | ||
|
||
it('should trim the protocol in custom endpoint', function() { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/common/src/service.js
Outdated
@@ -52,9 +62,24 @@ function Service(config, options) { | |||
email: options.email | |||
}); | |||
|
|||
// Some services have not been moved to the |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
@@ -202,11 +221,14 @@ function GrpcService(config, options) { | |||
|
|||
Object.keys(protoServices).forEach(function(name) { | |||
var protoConfig = protoServices[name]; | |||
var service = self.loadProtoFile_(protoConfig, config); | |||
var service = GrpcService.prototype.loadProtoFile_ |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/common-grpc/src/service.js
Outdated
@@ -168,6 +176,17 @@ function GrpcService(config, options) { | |||
return global.GCLOUD_SANDBOX_ENV; | |||
} | |||
|
|||
if (config.defaultApiEndpoint) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/common/src/util.js
Outdated
* @return {object=} base - Object containg the baseUrl and a boolean | ||
* property indicating whether the baseUrl is a customEndpoint or not. | ||
* */ | ||
function determineBaseUrl(options, environmentVariables, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
packages/common/src/service.js
Outdated
@@ -52,9 +57,20 @@ function Service(config, options) { | |||
email: options.email | |||
}); | |||
|
|||
if (!config.baseUrl) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
I wrapped up the remaining services and grpcServices. What's left are the services that use gapic:
To properly support custom endpoint in those services, gax-nodejs needs to have the notion of insecureCrendentials, the same way it's done in commonGrpc. At the moment it forces the calls to go do the auth roundtrip which is inconsistent with how we're doing things everywhere else (why would you want Google auth when going to a custom endpoint?!). I can open a PR in gax-nodejs to get that fixed and then wrap this up. If we really want this done I can override _getCredentials but that's just looking for trouble. Thoughts? |
Thanks for all of your help on this. The issue with gax is actually resolved. It originally popped up in this PR where I am converting Datastore to gax. Basically, we need to provide optionsForGax.sslCreds = grpc.credentials.createInsecure(); |
Fantastic, I'll go ahead and make the changes to the remaining services. |
@@ -55,7 +69,7 @@ function speechV1(options) { | |||
|
|||
// Create the speech client with the provided options. | |||
var client = gapic.v1(options).speechClient(options); | |||
Object.assign(client.constructor.prototype, helpers()); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Sorry this took forever... Now it has a bunch of conflicts with upstream, lmk if it looks fine and I'll try to fix the conflicts. Also, for some reason I'm no longer able to build the docs.
Not sure why it's looking at commits hashes, can someone explain what's going on here? packages/speech/src/helpers exists locally but it might (?) not be looking for that |
@@ -73,7 +73,7 @@ function visionV1(opts) { | |||
// Create the image annotator client with the provided options. | |||
var client = gapic.v1(opts).imageAnnotatorClient(opts); | |||
if (is.undefined(client.annotateImage)) { | |||
Object.assign(client.constructor.prototype, helpers('v1')); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
var extend = require('extend'); | ||
var gapic = { | ||
v2beta1: require('./v2beta1') | ||
}; | ||
var grpc = require('grpc'); |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
* these credentials will be used if the api endpoint is considered | ||
* to be a custom endpoint | ||
* */ | ||
function resolveGapicOptions(options, environmentVariables, |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
* @param {object=} options - [Configuration object](#/docs). | ||
* @param {number=} options.port - The port on which to connect to | ||
* the remote host. | ||
* @param {string=} options.servicePath - The domain name of the | ||
* API remote host. | ||
*/ | ||
function dlpV2beta1(options) { | ||
options = common.util.resolveGapicOptions( |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Thanks again for all of the work on this. It's getting a bit hairy when we're mixing in with files that are generated (speech, for example). I don't maintain the generator, so I've asked @landrito to take a look where those edits have been made. If the generator can take it on, we also wouldn't need the new tests-- it would handle that as well. |
Hey guys, any updates in this? Is there anything I can do to help pushing this forward? |
Any luck this gets allocated some time? It would be nice to know if there's still a slim chance that this makes it to master or if I should just forget about it. Thanks! |
@stephenplusplus What's the situation on this item? |
We got stalled on an issue where edits were required to the generated files: #2548 (comment) After the repo dissection is complete, we need to go back to the drawing board with this (hopefully not too far), and re-wire this code into each new code base. I'll take on this work, given the above and beyond efforts by @rmanyari already. |
I'm going to close the PR and let #1630 track the request for the feature. Sorry that we got caught up in the repo split. I thought we could get these changes in, but other priorities got in the way, which greatly complicated this. Thank you for all of your work and patience. |
Support for custom endpoints at service instantiation. This first PR covers the following services:
Custom enpoints can be defined using environment variables: GOOGLE_CLOUD_[SERVICE_NAME]_ENDPOINT or the options.{apiEndpoint,servicePath} options
Issue: #1630
Signed-off-by: Rodrigo Manyari [email protected]