Skip to content

Commit

Permalink
move createGoogleDefaultCredentials from grpc-js to grpc-js-xds
Browse files Browse the repository at this point in the history
  • Loading branch information
murgatroid99 committed Feb 25, 2021
1 parent 43eb668 commit 60eb600
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
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

0 comments on commit 60eb600

Please sign in to comment.