Skip to content

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

Closed
wants to merge 24 commits into from

Conversation

rmanyari
Copy link

Support for custom endpoints at service instantiation. This first PR covers the following services:

  • bigquery
  • bigtable
  • gce
  • datastore
  • dns
  • language

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]

@googlebot googlebot added the cla: no This human has *not* signed the Contributor License Agreement. label Aug 21, 2017
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.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor

Thank you very, very much for this!

@rmanyari
Copy link
Author

I signed it!

@stephenplusplus
Copy link
Contributor

stephenplusplus commented Aug 21, 2017

googlebot is pretty feature-incomplete. @lukesneeringer can you make sure this is okay with the CLA? (re: #2548 (comment))

@lukesneeringer
Copy link
Contributor

Yea, I can check on googlebot while you two get tests working. :-)

@lukesneeringer
Copy link
Contributor

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 (git config user.email).

If you need more help, let us know and I will try to get you in touch with someone who can help more.

@rmanyari
Copy link
Author

rmanyari commented Aug 25, 2017

(Update) - Nevermind, googlebot clarified things ;)
@lukesneeringer - I looked again at that link, it looks like I'm already covered by a corporate agreement from Two Sigma. I also just signed an individual one using my twosigma.com address. If it's not too much to ask, can you check again if I'm still not covered. Me too I have no interested whatsoever in long email threads with lawyers...

@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Aug 25, 2017
@@ -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.

@googleapis googleapis deleted a comment from googlebot Aug 28, 2017
Copy link
Contributor

@stephenplusplus stephenplusplus left a 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 the Service tests are sufficient and we know that we properly called it from the API constructor

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.

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.

assert.strictEqual(bq.customEndpoint, false);
});

it('should use options.apiEndpoint if defined', function() {

This comment was marked as spam.

assert.strictEqual(bq.customEndpoint, true);
});

it('should use GOOGLE_CLOUD_BIGQUERY_ENDPOINT if defined', function() {

This comment was marked as spam.

protosDir: path.resolve(__dirname, '../protos'),
protoServices: {
Bigtable: {
baseUrl: baseUrl,
baseUrl: defaultApiEndpoint,

This comment was marked as spam.

});
});

it('should trim the protocol in custom endpoint', function() {

This comment was marked as spam.

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

This comment was marked as spam.

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

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

This comment was marked as spam.

* @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.

This comment was marked as spam.

@@ -52,9 +57,20 @@ function Service(config, options) {
email: options.email
});

if (!config.baseUrl) {

This comment was marked as spam.

@rmanyari
Copy link
Author

I wrapped up the remaining services and grpcServices. What's left are the services that use gapic:

  • dlp
  • language (partially done)
  • logging-*
  • monitoring
  • spanner (partially done)
  • speech
  • video-intelligence
  • vision

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?

@stephenplusplus
Copy link
Contributor

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 options.sslCreds (which is honored here: https://github.com/googleapis/gax-nodejs/blob/e5059c7eb652cbff29cbdc12556946a32a5b7e1a/lib/grpc.js#L83):

optionsForGax.sslCreds = grpc.credentials.createInsecure();

@rmanyari
Copy link
Author

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.

@rmanyari
Copy link
Author

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.

HEAD is now at 1aa782a... speech @ 0.9.4 tagged.
/home/rodrigo/dev/google-cloud-node/scripts/docs/builder.js:316
    throw e;
    ^

Error: Unable to generate docs for file: speech/src/index.js. Reason: ENOENT: no such file or directory, open 'packages/speech/src/helpers

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.

var extend = require('extend');
var gapic = {
v2beta1: require('./v2beta1')
};
var grpc = require('grpc');

This comment was marked as spam.

* 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.

* @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.

This comment was marked as spam.

@stephenplusplus
Copy link
Contributor

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.

@rmanyari
Copy link
Author

rmanyari commented Oct 1, 2017

Hey guys, any updates in this? Is there anything I can do to help pushing this forward?

@rmanyari
Copy link
Author

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!

@lukesneeringer
Copy link
Contributor

@stephenplusplus What's the situation on this item?

@stephenplusplus
Copy link
Contributor

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.

@stephenplusplus
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This human has signed the Contributor License Agreement. core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants