Skip to content

Commit

Permalink
Removing username/password adding token
Browse files Browse the repository at this point in the history
  • Loading branch information
srz09 committed Apr 10, 2018
1 parent 1bb881b commit 6b2b40f
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 78 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "@hapiness/consul",
"version": "1.0.0",
"version": "1.0.1",
"description": "Hapiness module for consul",
"main": "commonjs/index.js",
"types": "index.d.ts",
Expand Down
3 changes: 1 addition & 2 deletions src/module/interfaces/hapiness.client.options.interface.ts
Expand Up @@ -2,8 +2,7 @@ export interface HapinessConsulClientOptions {
scheme?: string;
host?: string;
port?: number;
username?: string;
password?: string;
token?: string;
ca?: string;
baseUrl?: string;
}
24 changes: 6 additions & 18 deletions src/module/managers/consul.manager.ts
@@ -1,6 +1,6 @@
import * as consul from 'consul';

import { bindObservable, appendAuthStringToUrl } from '../utils';
import { bindObservable } from '../utils';
import { HapinessConsulClientOptions } from '../interfaces';

export class ConsulClientManager {
Expand All @@ -18,27 +18,15 @@ export class ConsulClientManager {
scheme: config.scheme || 'http',
host: config.host || '127.0.0.1',
port: config.port || 8500,
username: config.username,
password: config.password,
token: config.token,
ca: config.ca,
baseUrl: config.baseUrl
};

const authString = _config.username && _config.password ?
`${_config.username}:${_config.password}` : '';

if (!!authString.length) {
if (_config.baseUrl) {
_config.baseUrl = appendAuthStringToUrl(authString, _config.baseUrl);
} else {
// If there is no baseUrl provided, make it point to the /v1 (as it is done in consul module)
const baseUrl = `${_config.scheme}://${_config.host}:${_config.port}/v1`;
_config.baseUrl = appendAuthStringToUrl(authString, baseUrl);
}

_config.scheme = undefined;
_config.host = undefined;
_config.port = undefined;
if (_config.baseUrl) {
delete _config.scheme;
delete _config.host;
delete _config.port;
}

return Object.keys(_config).reduce((finalConf, prop) => {
Expand Down
17 changes: 0 additions & 17 deletions src/module/utils/append.authstring.to.url.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/module/utils/index.ts
@@ -1,2 +1 @@
export * from './append.authstring.to.url';
export * from './bind.observable';
22 changes: 0 additions & 22 deletions test/append.authstring.to.url.test.ts

This file was deleted.

20 changes: 3 additions & 17 deletions test/consul.client.manager.test.ts
Expand Up @@ -18,25 +18,11 @@ export class ConsulClientManagerTest {
}
);

const managerWithAuth = new ConsulClientManager({ username: 'user1', password: 'passwd' });
const managerWithAuth = new ConsulClientManager({ token: 'user1-token', baseUrl: 'http://my_base_url:8500/v1' });
unit.object(managerWithAuth.config).is(
{
username: 'user1',
password: 'passwd',
baseUrl: 'http://user1:passwd@127.0.0.1:8500/v1'
}
);

const managerWithAuthAndBaseUrl = new ConsulClientManager({
baseUrl: 'https://thisisatest.com:4444',
username: 'user1',
password: 'passwd'
});
unit.object(managerWithAuthAndBaseUrl.config).is(
{
username: 'user1',
password: 'passwd',
baseUrl: 'https://user1:passwd@thisisatest.com:4444'
token: 'user1-token',
baseUrl: 'http://my_base_url:8500/v1'
}
);
}
Expand Down

0 comments on commit 6b2b40f

Please sign in to comment.