Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 1.2.1: parse web CLI input as shell input #7252

Merged
merged 1 commit into from
Aug 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions ui/app/lib/console-helpers.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import keys from 'vault/lib/keycodes';
import argTokenizer from 'yargs-parser/lib/tokenize-arg-string.js';
import { parse } from 'shell-quote';

const supportedCommands = ['read', 'write', 'list', 'delete'];
const uiCommands = ['api', 'clearall', 'clear', 'fullscreen', 'refresh'];
Expand Down Expand Up @@ -45,7 +46,7 @@ export function executeUICommand(command, logAndOutput, commandFns) {
}

export function parseCommand(command, shouldThrow) {
let args = argTokenizer(command);
let args = argTokenizer(parse(command));
if (args[0] === 'vault') {
args.shift();
}
Expand All @@ -63,8 +64,6 @@ export function parseCommand(command, shouldThrow) {
let strippedArg = arg
// we'll have arg=something or arg="lol I need spaces", so need to split on the first =
.split(/=(.+)/)
// remove matched wrapping " or ' from each item
.map(item => item.replace(/^("|')(.+)(\1)$/, '$2'))
// if there were quotes, there's an empty string as the last member in the array that we don't want,
// so filter it out
.filter(str => str !== '')
Expand Down
2 changes: 0 additions & 2 deletions ui/app/services/path-help.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ import Service from '@ember/service';
import DS from 'ember-data';
import { encodePath } from 'vault/utils/path-encoding-helpers';
import { getOwner } from '@ember/application';
import { capitalize } from '@ember/string';
import { assign } from '@ember/polyfills';
import { expandOpenApiProps, combineAttributes } from 'vault/utils/openapi-to-attrs';
import { supportedAuthBackends } from 'vault/helpers/supported-auth-backends';
import fieldToAttrs from 'vault/utils/field-to-attrs';
import { resolve } from 'rsvp';
import { debug } from '@ember/debug';
Expand Down
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@
"qunit-dom": "^0.7.1",
"route-recognizer": "^0.3.4",
"sass-svg-uri": "^1.0.0",
"shell-quote": "^1.6.1",
"string.prototype.endswith": "^0.2.0",
"string.prototype.startswith": "^0.2.0",
"swagger-ui-dist": "^3.22.3",
Expand Down
4 changes: 2 additions & 2 deletions ui/tests/acceptance/secrets/backend/kv/secret-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ module('Acceptance | secrets/secret/create', function(hooks) {
let paths = [
'(',
')',
//'"',
'"',
//"'",
'!',
'#',
Expand All @@ -276,7 +276,7 @@ module('Acceptance | secrets/secret/create', function(hooks) {
].map(char => `${char}some`);
assert.expect(paths.length * 2);
let secretName = '2';
let commands = paths.map(path => `write ${backend}/${path}/${secretName} 3=4`);
let commands = paths.map(path => `write '${backend}/${path}/${secretName}' 3=4`);
await consoleComponent.runCommands(['write sys/mounts/kv type=kv', ...commands]);
for (let path of paths) {
await listPage.visit({ backend, id: path });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import EmberObject, { computed } from '@ember/object';
import Service from '@ember/service';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import { click, find, render, settled } from '@ember/test-helpers';
import { click, render, settled } from '@ember/test-helpers';
import hbs from 'htmlbars-inline-precompile';
import sinon from 'sinon';
import engineResolverFor from 'ember-engines/test-support/engine-resolver-for';
Expand Down
20 changes: 19 additions & 1 deletion ui/tests/unit/lib/console-helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,28 @@ module('Unit | Lib | console helpers', function() {
name: 'write with unmatched quotes',
command: `vault write \
auth/token/create \
policies='foo
policies="'foo"
`,
expected: ['write', [], 'auth/token/create', ["policies='foo"]],
},
{
name: 'write with shell characters',
/* eslint-disable no-useless-escape */
command: `vault write database/roles/api-prod db_name=apiprod creation_statements="CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; GRANT SELECT ON ALL TABLES IN SCHEMA public TO \"{{name}}\";" default_ttl=1h max_ttl=24h
`,
expected: [
'write',
[],
'database/roles/api-prod',
[
'db_name=apiprod',
`creation_statements=CREATE ROLE {{name}} WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}'; GRANT SELECT ON ALL TABLES IN SCHEMA public TO {{name}};`,
'default_ttl=1h',
'max_ttl=24h',
],
],
},

{
name: 'read with field',
command: `vault read -field=access_key aws/creds/my-role`,
Expand Down
2 changes: 1 addition & 1 deletion ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -16697,7 +16697,7 @@ shebang-regex@^1.0.0:
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3"
integrity sha1-2kL0l0DAtC2yypcoVxyxkMmO/qM=

[email protected]:
[email protected], shell-quote@^1.6.1:
version "1.6.1"
resolved "https://registry.yarnpkg.com/shell-quote/-/shell-quote-1.6.1.tgz#f4781949cce402697127430ea3b3c5476f481767"
integrity sha1-9HgZSczkAmlxJ0MOo7PFR29IF2c=
Expand Down