open-vault/ui/app/adapters/secret-engine.js

140 lines
4.7 KiB
JavaScript
Raw Normal View History

import { assign } from '@ember/polyfills';
2018-04-03 14:16:57 +00:00
import ApplicationAdapter from './application';
import { encodePath } from 'vault/utils/path-encoding-helpers';
import { splitObject } from 'vault/helpers/split-object';
2018-04-03 14:16:57 +00:00
export default ApplicationAdapter.extend({
url(path) {
const url = `${this.buildURL()}/mounts`;
return path ? url + '/' + encodePath(path) : url;
2018-04-03 14:16:57 +00:00
},
urlForConfig(path) {
return `/v1/${path}/config`;
},
2019-02-14 18:52:34 +00:00
internalURL(path) {
let url = `/${this.urlPrefix()}/internal/ui/mounts`;
if (path) {
url = `${url}/${encodePath(path)}`;
2019-02-14 18:52:34 +00:00
}
return url;
},
pathForType() {
return 'mounts';
2018-04-03 14:16:57 +00:00
},
async query(store, type, query) {
let mountModel, configModel;
try {
mountModel = await this.ajax(this.internalURL(query.path), 'GET');
// if kv2 then add the config data to the mountModel
// version comes in as a string
if (mountModel?.data?.type === 'kv' && mountModel?.data?.options?.version === '2') {
configModel = await this.ajax(this.urlForConfig(query.path), 'GET');
mountModel.data = { ...mountModel.data, ...configModel.data };
}
} catch (error) {
// no path means this was an error on listing
if (!query.path) {
throw error;
}
// control groups will throw a 403 permission denied error. If this happens return the mountModel
// error is handled on routing
}
return mountModel;
2018-04-03 14:16:57 +00:00
},
async createRecord(store, type, snapshot) {
2018-04-03 14:16:57 +00:00
const serializer = store.serializerFor(type.modelName);
let data = serializer.serialize(snapshot);
2018-04-03 14:16:57 +00:00
const path = snapshot.attr('path');
// for kv2 we make two network requests
if (data.type === 'kv' && data.options.version === 2) {
// data has both data for sys mount and the config, we need to separate them
let splitObjects = splitObject(data, ['max_versions', 'delete_version_after', 'cas_required']);
let configData;
[configData, data] = splitObjects;
if (!data.id) {
data.id = path;
}
// first create the engine
await this.ajax(this.url(path), 'POST', { data });
// second post to config
try {
await this.ajax(this.urlForConfig(path), 'POST', { data: configData });
} catch (e) {
// error here means you do not have update capabilities to config endpoint. If that's the case we show a flash message in the component and continue with the transition.
// the error is handled by mount-backend-form component which checks capabilities before hitting the save to the adapter.
// we do not handle the error here because we want the secret-engine to mount successfully and to continue the flow.
}
return {
data: assign({}, data, { path: path + '/', id: path }),
};
} else {
return this.ajax(this.url(path), 'POST', { data }).then(() => {
// ember data doesn't like 204s if it's not a DELETE
return {
data: assign({}, data, { path: path + '/', id: path }),
};
});
}
2018-04-03 14:16:57 +00:00
},
findRecord(store, type, path, snapshot) {
if (snapshot.attr('type') === 'ssh') {
return this.ajax(`/v1/${encodePath(path)}/config/ca`, 'GET');
2018-04-03 14:16:57 +00:00
}
return;
},
queryRecord(store, type, query) {
if (query.type === 'aws') {
Ember Upgrade to 3.24 (#13443) * Update browserslist * Add browserslistrc * ember-cli-update --to 3.26, fix conflicts * Run codemodes that start with ember-* * More codemods - before cp* * More codemods (curly data-test-*) * WIP ember-basic-dropdown template errors * updates ember-basic-dropdown and related deps to fix build issues * updates basic dropdown instances to new version API * updates more deps -- ember-template-lint is working again * runs no-implicit-this codemod * creates and runs no-quoteless-attributes codemod * runs angle brackets codemod * updates lint:hbs globs to only touch hbs files * removes yield only templates * creates and runs deprecated args transform * supresses lint error for invokeAction on LinkTo component * resolves remaining ambiguous path lint errors * resolves simple-unless lint errors * adds warnings for deprecated tagName arg on LinkTo components * adds warnings for remaining curly component invocation * updates global template lint rules * resolves remaining template lint errors * disables some ember specfic lint rules that target pre octane patterns * js lint fix run * resolves remaining js lint errors * fixes test run * adds npm-run-all dep * fixes test attribute issues * fixes console acceptance tests * fixes tests * adds yield only wizard/tutorial-active template * fixes more tests * attempts to fix more flaky tests * removes commented out settled in transit test * updates deprecations workflow and adds initializer to filter by version * updates flaky policies acl old test * updates to flaky transit test * bumps ember deps down to LTS version * runs linters after main merge * fixes client count tests after bad merge conflict fixes * fixes client count history test * more updates to lint config * another round of hbs lint fixes after extending stylistic rule * updates lint-staged commands * removes indent eslint rule since it seems to break things * fixes bad attribute in transform-edit-form template * test fixes * fixes enterprise tests * adds changelog * removes deprecated ember-concurrency-test-waiters dep and adds @ember/test-waiters * flaky test fix Co-authored-by: hashishaw <cshaw@hashicorp.com>
2021-12-17 03:44:29 +00:00
return this.ajax(`/v1/${encodePath(query.backend)}/config/lease`, 'GET').then((resp) => {
2018-04-03 14:16:57 +00:00
resp.path = query.backend + '/';
return resp;
});
}
return;
},
updateRecord(store, type, snapshot) {
const { apiPath, options, adapterMethod } = snapshot.adapterOptions;
if (adapterMethod) {
return this[adapterMethod](...arguments);
}
if (apiPath) {
const serializer = store.serializerFor(type.modelName);
const data = serializer.serialize(snapshot);
const path = encodePath(snapshot.id);
2018-04-03 14:16:57 +00:00
return this.ajax(`/v1/${path}/${apiPath}`, options.isDelete ? 'DELETE' : 'POST', { data });
}
},
saveAWSRoot(store, type, snapshot) {
let { data } = snapshot.adapterOptions;
const path = encodePath(snapshot.id);
2018-04-03 14:16:57 +00:00
return this.ajax(`/v1/${path}/config/root`, 'POST', { data });
},
saveAWSLease(store, type, snapshot) {
let { data } = snapshot.adapterOptions;
const path = encodePath(snapshot.id);
2018-04-03 14:16:57 +00:00
return this.ajax(`/v1/${path}/config/lease`, 'POST', { data });
},
saveZeroAddressConfig(store, type, snapshot) {
const path = encodePath(snapshot.id);
Ember Upgrade to 3.24 (#13443) * Update browserslist * Add browserslistrc * ember-cli-update --to 3.26, fix conflicts * Run codemodes that start with ember-* * More codemods - before cp* * More codemods (curly data-test-*) * WIP ember-basic-dropdown template errors * updates ember-basic-dropdown and related deps to fix build issues * updates basic dropdown instances to new version API * updates more deps -- ember-template-lint is working again * runs no-implicit-this codemod * creates and runs no-quoteless-attributes codemod * runs angle brackets codemod * updates lint:hbs globs to only touch hbs files * removes yield only templates * creates and runs deprecated args transform * supresses lint error for invokeAction on LinkTo component * resolves remaining ambiguous path lint errors * resolves simple-unless lint errors * adds warnings for deprecated tagName arg on LinkTo components * adds warnings for remaining curly component invocation * updates global template lint rules * resolves remaining template lint errors * disables some ember specfic lint rules that target pre octane patterns * js lint fix run * resolves remaining js lint errors * fixes test run * adds npm-run-all dep * fixes test attribute issues * fixes console acceptance tests * fixes tests * adds yield only wizard/tutorial-active template * fixes more tests * attempts to fix more flaky tests * removes commented out settled in transit test * updates deprecations workflow and adds initializer to filter by version * updates flaky policies acl old test * updates to flaky transit test * bumps ember deps down to LTS version * runs linters after main merge * fixes client count tests after bad merge conflict fixes * fixes client count history test * more updates to lint config * another round of hbs lint fixes after extending stylistic rule * updates lint-staged commands * removes indent eslint rule since it seems to break things * fixes bad attribute in transform-edit-form template * test fixes * fixes enterprise tests * adds changelog * removes deprecated ember-concurrency-test-waiters dep and adds @ember/test-waiters * flaky test fix Co-authored-by: hashishaw <cshaw@hashicorp.com>
2021-12-17 03:44:29 +00:00
const roles = store.peekAll('role-ssh').filterBy('zeroAddress').mapBy('id').join(',');
2018-04-03 14:16:57 +00:00
const url = `/v1/${path}/config/zeroaddress`;
const data = { roles };
if (roles === '') {
return this.ajax(url, 'DELETE');
}
return this.ajax(url, 'POST', { data });
},
});