vvauth 0.3.2 → 0.3.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 +15 -11
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -56,13 +56,13 @@ class vvauth {
56
56
  }
57
57
  }
58
58
 
59
- this.vault_addr = this.rc.vault_addr;
59
+ this.VAULT_ADDR = this.rc.vault_addr;
60
60
 
61
- if(!this.vault_addr)
61
+ if(!this.VAULT_ADDR)
62
62
  throw `Invalid vault remote`;
63
63
 
64
64
  this.VAULT_TOKEN = process.env.VAULT_TOKEN;
65
- console.error("vauth bound to '%s'", this.vault_addr);
65
+ console.error("vauth bound to '%s'", this.VAULT_ADDR);
66
66
  }
67
67
 
68
68
  async connect() {
@@ -90,7 +90,7 @@ class vvauth {
90
90
  _publish_env(env) {
91
91
  let cmds = [];
92
92
  for(let [k, v] of Object.entries(env)) {
93
- cmds.push(`export ${k}="${v}"`);
93
+ cmds.push(`export ${k}=${shellEscape(v)}`);
94
94
  cmds.push(`echo export ${k}=[redacted] >&2`);
95
95
  }
96
96
  process.stdout.write(cmds.join("\n") + "\n");
@@ -136,7 +136,7 @@ class vvauth {
136
136
  async env(source = false) {
137
137
  let {profile} = await this._get_profile();
138
138
 
139
- let env = {VAULT_TOKEN : this.VAULT_TOKEN}, secrets = {},
139
+ let env = {VAULT_TOKEN : this.VAULT_TOKEN, VAULT_ADDR : this.VAULT_ADDR}, secrets = {},
140
140
  {git, map = {}, paths, path : mount = "secrets"} = this.rc.env || {};
141
141
 
142
142
  if(git) {
@@ -166,7 +166,7 @@ class vvauth {
166
166
 
167
167
 
168
168
  async _read(mount, secret_path) {
169
- let remote_url = `${trim(this.vault_addr, '/')}/v1/${mount}/data/${trim(secret_path, '/')}`;
169
+ let remote_url = `${trim(this.VAULT_ADDR, '/')}/v1/${mount}/data/${trim(secret_path, '/')}`;
170
170
  let query = {...url.parse(remote_url), headers : {'x-vault-token' : this.VAULT_TOKEN}, expect : 200};
171
171
  let res = await request(query);
172
172
  return get(JSON.parse(String(await drain(res))), 'data.data');
@@ -184,7 +184,7 @@ class vvauth {
184
184
  if(token)
185
185
  return;
186
186
 
187
- let remote_url = `${trim(this.vault_addr, '/')}/v1/auth/${path}/nonce`;
187
+ let remote_url = `${trim(this.VAULT_ADDR, '/')}/v1/auth/${path}/nonce`;
188
188
  let query = {...url.parse(remote_url), json : true};
189
189
  let res = await request(query);
190
190
  let {data : {nonce}} = JSON.parse(String(await drain(res)));
@@ -227,7 +227,7 @@ class vvauth {
227
227
  }
228
228
 
229
229
  async _lookup_token(token) {
230
- let remote_url = `${trim(this.vault_addr, '/')}/v1/auth/token/lookup-self`;
230
+ let remote_url = `${trim(this.VAULT_ADDR, '/')}/v1/auth/token/lookup-self`;
231
231
  let query = {...url.parse(remote_url), headers : {'x-vault-token' : token}, expect : 200};
232
232
  let res = await request(query);
233
233
  let response = JSON.parse(await drain(res)).data;
@@ -235,14 +235,14 @@ class vvauth {
235
235
  }
236
236
 
237
237
  async _lookup_identity(token, id) {
238
- let remote_url = `${trim(this.vault_addr, '/')}/v1/identity/entity/id/${id}`;
238
+ let remote_url = `${trim(this.VAULT_ADDR, '/')}/v1/identity/entity/id/${id}`;
239
239
  let query = {...url.parse(remote_url), headers : {'x-vault-token' : token}, expect : 200};
240
240
  let res = await request(query);
241
241
  return JSON.parse(String(await drain(res))).data;
242
242
  }
243
243
 
244
244
  async _update_identity(token, id, payload) {
245
- let remote_url = `${trim(this.vault_addr, '/')}/v1/identity/entity/id/${id}`;
245
+ let remote_url = `${trim(this.VAULT_ADDR, '/')}/v1/identity/entity/id/${id}`;
246
246
  let query = {...url.parse(remote_url), headers : {'x-vault-token' : token}, expect : 204, json : true};
247
247
  await request(query, payload);
248
248
  return payload;
@@ -251,7 +251,7 @@ class vvauth {
251
251
 
252
252
 
253
253
  async _login_vault(path, payload) {
254
- let remote_url = `${trim(this.vault_addr, '/')}/v1/auth/${path}/login`;
254
+ let remote_url = `${trim(this.VAULT_ADDR, '/')}/v1/auth/${path}/login`;
255
255
  let query = {...url.parse(remote_url), json : true};
256
256
  let res = await request(query, payload);
257
257
  let response = String(await drain(res));
@@ -266,6 +266,10 @@ class vvauth {
266
266
 
267
267
  }
268
268
 
269
+ const shellEscape = (arg) => {
270
+ return arg.replace(/([$!'"();`*?{}[\]<>&%#~@\\ ])/g, '\\$1');
271
+ };
272
+
269
273
  //ensure module is called directly, i.e. not required
270
274
  if(module.parent === null)
271
275
  require('cnyks/lib/bundle')(vvauth);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vvauth",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Vault Auth helper",
5
5
  "main": "index.js",
6
6
  "bin": {