vvauth 0.1.2 → 0.1.4
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.
- package/index.js +10 -24
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -9,7 +9,6 @@ const net = require('net');
|
|
|
9
9
|
const {spawn} = require('child_process');
|
|
10
10
|
|
|
11
11
|
const {parse} = require('yaml');
|
|
12
|
-
const {args, dict} = require('nyks/process/parseArgs')();
|
|
13
12
|
const SSHAgent = require('ssh-agent-js/client');
|
|
14
13
|
const trim = require('mout/string/trim');
|
|
15
14
|
const get = require('mout/object/get');
|
|
@@ -31,7 +30,7 @@ const logger = {
|
|
|
31
30
|
|
|
32
31
|
const VAUTH_RC = ".vauthrc";
|
|
33
32
|
const FUNCTION_NAME = "vauth";
|
|
34
|
-
const FUNCTION_DECL = "function vauth() { source <(/usr/bin/env
|
|
33
|
+
const FUNCTION_DECL = "function vauth() { source <(/usr/bin/env vvauth --ir://raw --source --ir://run=$1 \"${@:2}\"); }";
|
|
35
34
|
|
|
36
35
|
class vvauth {
|
|
37
36
|
constructor(rc = null) {
|
|
@@ -44,6 +43,11 @@ class vvauth {
|
|
|
44
43
|
this.rc = walk(parse(body), v => replaceEnv(v, { env : process.env}));
|
|
45
44
|
}
|
|
46
45
|
}
|
|
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);
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
async _get_token() {
|
|
@@ -60,18 +64,10 @@ class vvauth {
|
|
|
60
64
|
return token;
|
|
61
65
|
}
|
|
62
66
|
|
|
63
|
-
async login(
|
|
64
|
-
if(!dict['source'] && publish) {
|
|
65
|
-
console.error(`echo please use "${FUNCTION_NAME} login"`);
|
|
66
|
-
process.exit(1);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
let {vault_addr} = this.rc;
|
|
70
|
-
console.error("Connecting to %s", vault_addr);
|
|
71
|
-
|
|
67
|
+
async login(source = false) {
|
|
72
68
|
|
|
73
69
|
let VAULT_TOKEN = await this._get_token();
|
|
74
|
-
if(
|
|
70
|
+
if(source) {
|
|
75
71
|
let env = {VAULT_TOKEN};
|
|
76
72
|
this._publish_env(env);
|
|
77
73
|
process.exit();
|
|
@@ -159,18 +155,8 @@ class vvauth {
|
|
|
159
155
|
}
|
|
160
156
|
|
|
161
157
|
//ensure module is called directly, i.e. not required
|
|
162
|
-
if(module.parent === null)
|
|
163
|
-
|
|
164
|
-
if(cmd && i != -1)
|
|
165
|
-
process.argv.splice(i, 1);
|
|
166
|
-
|
|
167
|
-
if(dict['source'] && !cmd) {
|
|
168
|
-
console.error(`please use "${FUNCTION_NAME} login"`);
|
|
169
|
-
process.exit(1);
|
|
170
|
-
}
|
|
171
|
-
let run = cmd ? [`--ir://raw`, `--ir://run=${cmd}`] : [];
|
|
172
|
-
require('cnyks/lib/bundle')(vvauth, null, run);
|
|
173
|
-
}
|
|
158
|
+
if(module.parent === null)
|
|
159
|
+
require('cnyks/lib/bundle')(vvauth);
|
|
174
160
|
|
|
175
161
|
|
|
176
162
|
module.exports = vvauth;
|