Skip to content
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

Move createGoogleDefaultCredentials from grpc-js to grpc-js-xds #1703

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/grpc-js-xds/package.json
Expand Up @@ -42,7 +42,8 @@
"yargs": "^15.4.1"
},
"dependencies": {
"@grpc/proto-loader": "^0.6.0-pre14"
"@grpc/proto-loader": "^0.6.0-pre14",
"google-auth-library": "^7.0.2"
},
"peerDependencies": {
"@grpc/grpc-js": "~1.2.2"
Expand Down
27 changes: 27 additions & 0 deletions packages/grpc-js-xds/src/google-default-credentials.ts
@@ -0,0 +1,27 @@
/*
* Copyright 2021 gRPC authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


import { GoogleAuth } from 'google-auth-library';
import { ChannelCredentials, CallCredentials } from '@grpc/grpc-js';

export function createGoogleDefaultCredentials(): ChannelCredentials {
const sslCreds = ChannelCredentials.createSsl();
const googleAuthCreds = CallCredentials.createFromGoogleCredential(
new GoogleAuth()
);
return sslCreds.compose(googleAuthCreds);
}
2 changes: 1 addition & 1 deletion packages/grpc-js-xds/src/xds-client.ts
Expand Up @@ -48,7 +48,7 @@ import { RouteConfiguration__Output } from './generated/envoy/api/v2/RouteConfig
import { Any__Output } from './generated/google/protobuf/Any';
import BackoffTimeout = experimental.BackoffTimeout;
import ServiceConfig = experimental.ServiceConfig;
import createGoogleDefaultCredentials = experimental.createGoogleDefaultCredentials;
import { createGoogleDefaultCredentials } from './google-default-credentials';
import { CdsLoadBalancingConfig } from './load-balancer-cds';

const TRACER_NAME = 'xds_client';
Expand Down
1 change: 0 additions & 1 deletion packages/grpc-js/package.json
Expand Up @@ -58,7 +58,6 @@
},
"dependencies": {
"@types/node": "^12.12.47",
"google-auth-library": "^6.1.1",
"semver": "^6.2.0"
},
"files": [
Expand Down
11 changes: 0 additions & 11 deletions packages/grpc-js/src/channel-credentials.ts
Expand Up @@ -19,7 +19,6 @@ import { ConnectionOptions, createSecureContext, PeerCertificate } from 'tls';

import { CallCredentials } from './call-credentials';
import { CIPHER_SUITES, getDefaultRootsData } from './tls-helpers';
import { GoogleAuth as GoogleAuthType } from 'google-auth-library';

// eslint-disable-next-line @typescript-eslint/no-explicit-any
function verifyIsBufferOrNull(obj: any, friendlyName: string): void {
Expand Down Expand Up @@ -279,13 +278,3 @@ class ComposedChannelCredentialsImpl extends ChannelCredentials {
}
}
}

export function createGoogleDefaultCredentials(): ChannelCredentials {
const GoogleAuth = require('google-auth-library')
.GoogleAuth as typeof GoogleAuthType;
const sslCreds = ChannelCredentials.createSsl();
const googleAuthCreds = CallCredentials.createFromGoogleCredential(
new GoogleAuth()
);
return sslCreds.compose(googleAuthCreds);
}
1 change: 0 additions & 1 deletion packages/grpc-js/src/experimental.ts
Expand Up @@ -2,7 +2,6 @@ export { trace } from './logging';
export { Resolver, ResolverListener, registerResolver } from './resolver';
export { GrpcUri, uriToString } from './uri-parser';
export { ServiceConfig } from './service-config';
export { createGoogleDefaultCredentials } from './channel-credentials';
export { BackoffTimeout } from './backoff-timeout';
export { LoadBalancer, LoadBalancingConfig, ChannelControlHelper, registerLoadBalancerType, getFirstUsableConfig, validateLoadBalancingConfig } from './load-balancer';
export { SubchannelAddress, subchannelAddressToString } from './subchannel';
Expand Down