зеркало из https://github.com/microsoft/etcd3.git
feat: allow apply call options to authentication token exchange
Fixes #111
This commit is contained in:
Родитель
0ac0697373
Коммит
d50fb8a270
|
@ -8,7 +8,8 @@
|
|||
Thank you to [@pauliusuza](https://github.com/pauliusuza) for his help updating everything
|
||||
|
||||
- **feat**: add `SingleRangeBuilder.exists()` that returns if the given key exists
|
||||
- **fix**: errors when creating watchers not being handled correctly (see [114](https://github.com/microsoft/etcd3/issues/114))
|
||||
- **fix**: errors when creating watchers not being handled correctly (see [#114](https://github.com/microsoft/etcd3/issues/114))
|
||||
- **feat**: allow apply call options to authentication token exchange (see [#111](https://github.com/microsoft/etcd3/issues/111))
|
||||
|
||||
## 0.2.13 2019-07-03
|
||||
|
||||
|
|
|
@ -104,7 +104,13 @@ class Authenticator {
|
|||
|
||||
const meta = new grpc.Metadata();
|
||||
const host = removeProtocolPrefix(hosts[index]);
|
||||
return this.getCredentialsFromHost(host, auth.username, auth.password, this.credentials)
|
||||
return this.getCredentialsFromHost(
|
||||
host,
|
||||
auth.username,
|
||||
auth.password,
|
||||
auth.callOptions,
|
||||
this.credentials,
|
||||
)
|
||||
.then(token => {
|
||||
meta.set('token', token);
|
||||
return meta;
|
||||
|
@ -122,12 +128,13 @@ class Authenticator {
|
|||
address: string,
|
||||
name: string,
|
||||
password: string,
|
||||
callOptions: grpc.CallOptions | undefined,
|
||||
credentials: grpc.ChannelCredentials,
|
||||
): Promise<string> {
|
||||
return runServiceCall(
|
||||
new etcdserverpb.Auth(address, credentials),
|
||||
new grpc.Metadata(),
|
||||
undefined,
|
||||
callOptions,
|
||||
'authenticate',
|
||||
{ name, password },
|
||||
).then(res => res.token);
|
||||
|
|
|
@ -214,6 +214,7 @@ const grpcMessageToError = new Map<string, IErrorCtor>([
|
|||
['Channel Disconnected', GRPCConnectFailedError],
|
||||
['No connection established', GRPCConnectFailedError],
|
||||
['failed to connect to all addresses', GRPCConnectFailedError],
|
||||
['DEADLINE_EXCEEDED', GRPCDeadlineExceededError],
|
||||
['Endpoint read failed', GRPCProtocolError],
|
||||
['Got config after disconnection', GRPCProtocolError],
|
||||
['Failed to create subchannel', GRPCProtocolError],
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* Copyright (C) Microsoft Corporation. All rights reserved.
|
||||
*--------------------------------------------------------*/
|
||||
import { ChannelOptions } from '@grpc/grpc-js/build/src/channel-options';
|
||||
import { CallOptions } from '@grpc/grpc-js';
|
||||
|
||||
import { IBackoffStrategy } from './backoff/backoff';
|
||||
|
||||
|
@ -45,6 +46,11 @@ export interface IOptions {
|
|||
auth?: {
|
||||
username: string;
|
||||
password: string;
|
||||
|
||||
/**
|
||||
* Call options to use for the password-to-token exchange.
|
||||
*/
|
||||
callOptions?: CallOptions;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,6 +23,7 @@ import {
|
|||
setupAuth,
|
||||
removeAuth,
|
||||
} from './util';
|
||||
import { GRPCDeadlineExceededError } from '../errors';
|
||||
|
||||
function wipeAll(things: Promise<Array<{ delete(): any }>>) {
|
||||
return things.then(items => Promise.all(items.map(item => item.delete())));
|
||||
|
@ -157,6 +158,23 @@ describe('roles and auth', () => {
|
|||
authedClient.close();
|
||||
});
|
||||
|
||||
it('applies call options', async () => {
|
||||
const authedClient = new Etcd3(
|
||||
getOptions({
|
||||
auth: {
|
||||
username: 'connor',
|
||||
password: 'password',
|
||||
callOptions: { deadline: new Date(0) },
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(authedClient.put('foo').value('bar')).to.be.rejectedWith(
|
||||
GRPCDeadlineExceededError,
|
||||
);
|
||||
authedClient.close();
|
||||
});
|
||||
|
||||
it('rejects modifying a key the client has no access to', async () => {
|
||||
const authedClient = new Etcd3(
|
||||
getOptions({
|
||||
|
|
Загрузка…
Ссылка в новой задаче