vvauth 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +11 -13
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -14,9 +14,11 @@ const SSHAgent = require('ssh-agent-js/client');
14
14
  const trim = require('mout/string/trim');
15
15
  const get = require('mout/object/get');
16
16
  const eachLimit = require('nyks/async/eachLimit');
17
+ const walk = require('nyks/object/walk');
17
18
 
18
19
  const request = require('nyks/http/request');
19
20
  const drain = require('nyks/stream/drain');
21
+ const replaceEnv = require('nyks/string/replaceEnv');
20
22
 
21
23
  const debug = require('debug');
22
24
 
@@ -29,7 +31,7 @@ const logger = {
29
31
 
30
32
  const VAUTH_RC = ".vauthrc";
31
33
  const FUNCTION_NAME = "vauth";
32
- const FUNCTION_DECL = "function vauth() { source <(/usr/bin/env vauth --source $*); }";
34
+ const FUNCTION_DECL = "function vauth() { source <(/usr/bin/env vvauth --source $*); }";
33
35
 
34
36
  class vvauth {
35
37
  constructor(rc = null) {
@@ -39,9 +41,13 @@ class vvauth {
39
41
  } else {
40
42
  if(fs.existsSync(VAUTH_RC)) {
41
43
  let body = fs.readFileSync(VAUTH_RC, 'utf8');
42
- this.rc = parse(body);
44
+ this.rc = walk(parse(body), v => replaceEnv(v, { env : process.env}));
43
45
  }
44
46
  }
47
+ let {vault_addr} = this.rc;
48
+ if(!vault_addr)
49
+ throw `Invalid vault remote`;
50
+ console.error("vauth bound to '%s'", vault_addr);
45
51
  }
46
52
 
47
53
  async _get_token() {
@@ -58,20 +64,13 @@ class vvauth {
58
64
  return token;
59
65
  }
60
66
 
61
- async login(publish = true) {
62
- if(!dict['source'] && publish) {
63
- console.error(`echo please use "${FUNCTION_NAME} login"`);
64
- process.exit(1);
65
- }
66
-
67
- let {vault_addr} = this.rc;
68
- console.error("Connecting to %s", vault_addr);
69
-
67
+ async login(source = false) {
70
68
 
71
69
  let VAULT_TOKEN = await this._get_token();
72
- if(publish) {
70
+ if(source) {
73
71
  let env = {VAULT_TOKEN};
74
72
  this._publish_env(env);
73
+ process.exit();
75
74
  }
76
75
  return VAULT_TOKEN;
77
76
  }
@@ -83,7 +82,6 @@ class vvauth {
83
82
  cmds.push(`echo export ${k}=[redacted] >&2`);
84
83
  }
85
84
  process.stdout.write(cmds.join("\n") + "\n");
86
- process.exit();
87
85
  }
88
86
 
89
87
  async _login_vault_ssh({vault_addr, path = 'ssh', role}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vvauth",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "description": "Vault Auth helper",
5
5
  "main": "index.js",
6
6
  "bin": {