Mark some methods of ChannelCredentials as internal

This commit is contained in:
murgatroid99 2018-08-23 13:56:59 -07:00
parent 93733081e7
commit 8d37d2321e
4 changed files with 17 additions and 17 deletions

View File

@ -38,7 +38,7 @@ export class CallCredentialsFilterFactory implements
FilterFactory<CallCredentialsFilter> { FilterFactory<CallCredentialsFilter> {
private readonly credentials: CallCredentials; private readonly credentials: CallCredentials;
constructor(channel: Http2Channel) { constructor(channel: Http2Channel) {
this.credentials = channel.credentials.getCallCredentials(); this.credentials = channel.credentials._getCallCredentials();
} }
createFilter(callStream: Call): CallCredentialsFilter { createFilter(callStream: Call): CallCredentialsFilter {

View File

@ -61,7 +61,7 @@ export abstract class ChannelCredentials {
/** /**
* Gets the set of per-call credentials associated with this instance. * Gets the set of per-call credentials associated with this instance.
*/ */
getCallCredentials(): CallCredentials { _getCallCredentials(): CallCredentials {
return this.callCredentials; return this.callCredentials;
} }
@ -70,12 +70,12 @@ export abstract class ChannelCredentials {
* instance was created with createSsl, or null if this instance was created * instance was created with createSsl, or null if this instance was created
* with createInsecure. * with createInsecure.
*/ */
abstract getConnectionOptions(): ConnectionOptions|null; abstract _getConnectionOptions(): ConnectionOptions|null;
/** /**
* Indicates whether this credentials object creates a secure channel. * Indicates whether this credentials object creates a secure channel.
*/ */
abstract isSecure(): boolean; abstract _isSecure(): boolean;
/** /**
* Return a new ChannelCredentials instance with a given set of credentials. * Return a new ChannelCredentials instance with a given set of credentials.
@ -132,10 +132,10 @@ class InsecureChannelCredentialsImpl extends ChannelCredentials {
throw new Error('Cannot compose insecure credentials'); throw new Error('Cannot compose insecure credentials');
} }
getConnectionOptions(): ConnectionOptions|null { _getConnectionOptions(): ConnectionOptions|null {
return null; return null;
} }
isSecure(): boolean { _isSecure(): boolean {
return false; return false;
} }
} }
@ -155,10 +155,10 @@ class SecureChannelCredentialsImpl extends ChannelCredentials {
this.connectionOptions, combinedCallCredentials); this.connectionOptions, combinedCallCredentials);
} }
getConnectionOptions(): ConnectionOptions|null { _getConnectionOptions(): ConnectionOptions|null {
return this.connectionOptions; return this.connectionOptions;
} }
isSecure(): boolean { _isSecure(): boolean {
return true; return true;
} }
} }

View File

@ -177,7 +177,7 @@ export class Http2Channel extends EventEmitter implements Channel {
} }
private startConnecting(): void { private startConnecting(): void {
let connectionOptions: http2.SecureClientSessionOptions = this.credentials.getConnectionOptions() || {}; let connectionOptions: http2.SecureClientSessionOptions = this.credentials._getConnectionOptions() || {};
if (connectionOptions.secureContext !== null) { if (connectionOptions.secureContext !== null) {
// If provided, the value of grpc.ssl_target_name_override should be used // If provided, the value of grpc.ssl_target_name_override should be used
// to override the target hostname when checking server identity. // to override the target hostname when checking server identity.
@ -233,7 +233,7 @@ export class Http2Channel extends EventEmitter implements Channel {
} }
} }
} }
if (credentials.isSecure()) { if (credentials._isSecure()) {
this.target = new url.URL(`https://${address}`); this.target = new url.URL(`https://${address}`);
} else { } else {
this.target = new url.URL(`http://${address}`); this.target = new url.URL(`http://${address}`);

View File

@ -48,7 +48,7 @@ describe('ChannelCredentials Implementation', () => {
() => { () => {
const creds = assert2.noThrowAndReturn( const creds = assert2.noThrowAndReturn(
() => ChannelCredentials.createInsecure()); () => ChannelCredentials.createInsecure());
assert.ok(!creds.getConnectionOptions()); assert.ok(!creds._getConnectionOptions());
}); });
}); });
@ -56,28 +56,28 @@ describe('ChannelCredentials Implementation', () => {
it('should work when given no arguments', () => { it('should work when given no arguments', () => {
const creds: ChannelCredentials = const creds: ChannelCredentials =
assert2.noThrowAndReturn(() => ChannelCredentials.createSsl()); assert2.noThrowAndReturn(() => ChannelCredentials.createSsl());
assert.ok(!!creds.getConnectionOptions()); assert.ok(!!creds._getConnectionOptions());
}); });
it('should work with just a CA override', async () => { it('should work with just a CA override', async () => {
const {ca} = await pFixtures; const {ca} = await pFixtures;
const creds = const creds =
assert2.noThrowAndReturn(() => ChannelCredentials.createSsl(ca)); assert2.noThrowAndReturn(() => ChannelCredentials.createSsl(ca));
assert.ok(!!creds.getConnectionOptions()); assert.ok(!!creds._getConnectionOptions());
}); });
it('should work with just a private key and cert chain', async () => { it('should work with just a private key and cert chain', async () => {
const {key, cert} = await pFixtures; const {key, cert} = await pFixtures;
const creds = assert2.noThrowAndReturn( const creds = assert2.noThrowAndReturn(
() => ChannelCredentials.createSsl(null, key, cert)); () => ChannelCredentials.createSsl(null, key, cert));
assert.ok(!!creds.getConnectionOptions()); assert.ok(!!creds._getConnectionOptions());
}); });
it('should work with three parameters specified', async () => { it('should work with three parameters specified', async () => {
const {ca, key, cert} = await pFixtures; const {ca, key, cert} = await pFixtures;
const creds = assert2.noThrowAndReturn( const creds = assert2.noThrowAndReturn(
() => ChannelCredentials.createSsl(ca, key, cert)); () => ChannelCredentials.createSsl(ca, key, cert));
assert.ok(!!creds.getConnectionOptions()); assert.ok(!!creds._getConnectionOptions());
}); });
it('should throw if just one of private key and cert chain are missing', it('should throw if just one of private key and cert chain are missing',
@ -97,7 +97,7 @@ describe('ChannelCredentials Implementation', () => {
const channelCreds = ChannelCredentials.createSsl(); const channelCreds = ChannelCredentials.createSsl();
const callCreds = new CallCredentialsMock(); const callCreds = new CallCredentialsMock();
const composedChannelCreds = channelCreds.compose(callCreds); const composedChannelCreds = channelCreds.compose(callCreds);
assert.strictEqual(composedChannelCreds.getCallCredentials(), callCreds); assert.strictEqual(composedChannelCreds._getCallCredentials(), callCreds);
}); });
it('should be chainable', () => { it('should be chainable', () => {
@ -110,7 +110,7 @@ describe('ChannelCredentials Implementation', () => {
// Build a mock object that should be an identical copy // Build a mock object that should be an identical copy
const composedCallCreds = callCreds1.compose(callCreds2); const composedCallCreds = callCreds1.compose(callCreds2);
assert.ok(composedCallCreds.isEqual( assert.ok(composedCallCreds.isEqual(
composedChannelCreds.getCallCredentials() as CallCredentialsMock)); composedChannelCreds._getCallCredentials() as CallCredentialsMock));
}); });
}); });
}); });