Skip to content
This repository has been archived by the owner on May 8, 2020. It is now read-only.

Commit

Permalink
feat(remote cli): Implement basic remote passthrough of credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
zakhenry committed Jul 20, 2016
1 parent e94b2f4 commit 15a8095
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 18 deletions.
34 changes: 17 additions & 17 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"test": "u test -s",
"coveralls": "u coveralls",
"build": "u build",
"preparepublish": "cp -r lib/* .",
"preparepublish": "u build && cp -r lib/* .",
"postpublish": "u changelog && u doc build && u deploy docs"
},
"repository": {
Expand All @@ -35,6 +35,20 @@
"@angular/router": "3.0.0-beta.2",
"@angular/router-deprecated": "2.0.0-rc.2",
"@angular/upgrade": "2.0.0-rc.4",
"@types/chalk": "^0.4.28",
"@types/chance": "^0.7.28",
"@types/dotenv": "^2.0.17",
"@types/express": "^4.0.29",
"@types/express-serve-static-core": "^4.0.29",
"@types/hapi": "^13.0.28",
"@types/jasmine": "^2.2.29",
"@types/lodash": "0.0.27",
"@types/moment": "^2.11.28",
"@types/node": "^4.0.29",
"@types/proxyquire": "^1.3.26",
"@types/socket.io": "^1.4.26",
"@types/validator": "^4.5.26",
"@xiphiaz/vantage": "^1.7.1",
"chalk": "^1.1.3",
"chance": "^1.0.3",
"class-validator": "^0.4.0-alpha.3",
Expand All @@ -52,21 +66,7 @@
"table": "^3.7.8",
"timestamp": "0.0.1",
"typeorm": "0.0.2-alpha.43",
"vantage": "^1.7.0",
"zone.js": "^0.6.12",
"@types/chalk": "^0.4.28",
"@types/chance": "^0.7.28",
"@types/dotenv": "^2.0.17",
"@types/express": "^4.0.29",
"@types/express-serve-static-core": "^4.0.29",
"@types/hapi": "^13.0.28",
"@types/jasmine": "^2.2.29",
"@types/lodash": "0.0.27",
"@types/moment": "^2.11.28",
"@types/node": "^4.0.29",
"@types/proxyquire": "^1.3.26",
"@types/socket.io": "^1.4.26",
"@types/validator": "^4.5.26"
"zone.js": "^0.6.12"
},
"devDependencies": {
"@ubiquits/toolchain": "^0.2.2",
Expand All @@ -75,4 +75,4 @@
"directories": {
"doc": "docs"
}
}
}
25 changes: 24 additions & 1 deletion src/server/services/remoteCli.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { Server, RouteConfig } from '../servers/abstract.server';
import * as chalk from 'chalk';
import { Response } from '../controllers/response';
import { PromiseFactory } from '../../common/util/serialPromise';
import * as Vantage from 'vantage';
import * as Vantage from '@xiphiaz/vantage';
import { Service } from '../../common/registry/decorators';
import { AbstractService } from '../../common/services/service';

Expand Down Expand Up @@ -103,6 +103,8 @@ export class RemoteCli extends AbstractService {

this.vantage.delimiter('ubiquits-runtime~$');

this.registerAuthenticationStrategy();

let displayBanner = `Welcome to Ubiquits runtime cli. Type 'help' for commands`;
if ((<any>process.stdout).columns > 68) {
displayBanner = `${banner}\n${displayBanner}`;
Expand Down Expand Up @@ -164,6 +166,8 @@ export class RemoteCli extends AbstractService {
};
}

this.logger.debug('Auth function', this.vantage._authFn);

this.vantage.listen(port, callback);
this.logger.info(`Vantage server started on ${port}`);

Expand All @@ -181,4 +185,23 @@ export class RemoteCli extends AbstractService {
return table(data, config);
}

protected registerAuthenticationStrategy(): void {

this.vantage.auth((vantage: any, options: any) => {
return (args: any, cb: Function) => {
try {
if (args.client && args.client.auth == 'zak:password'){
return cb('Ok', true);
}

return cb("Credentials are incorrect", false);
} catch (e){
this.logger.error('Authentication error', e);
cb(null, false);
}
}
});

this.logger.debug('Registered vantage authentication strategy');
}
}
4 changes: 4 additions & 0 deletions src/server/services/vantage.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ declare module 'vantage' {
import alias = require('~vantage/index');
export = alias;
}
declare module '@xiphiaz/vantage' {
import alias = require('~vantage/index');
export = alias;
}

0 comments on commit 15a8095

Please sign in to comment.