5c2a08de6d
* 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>
147 lines
4.9 KiB
JavaScript
147 lines
4.9 KiB
JavaScript
import { assign } from '@ember/polyfills';
|
|
import ApplicationAdapter from './application';
|
|
import { encodePath } from 'vault/utils/path-encoding-helpers';
|
|
import { splitObject } from 'vault/helpers/split-object';
|
|
|
|
export default ApplicationAdapter.extend({
|
|
url(path) {
|
|
const url = `${this.buildURL()}/mounts`;
|
|
return path ? url + '/' + encodePath(path) : url;
|
|
},
|
|
|
|
urlForConfig(path) {
|
|
return `/v1/${path}/config`;
|
|
},
|
|
|
|
internalURL(path) {
|
|
let url = `/${this.urlPrefix()}/internal/ui/mounts`;
|
|
if (path) {
|
|
url = `${url}/${encodePath(path)}`;
|
|
}
|
|
return url;
|
|
},
|
|
|
|
pathForType() {
|
|
return 'mounts';
|
|
},
|
|
|
|
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;
|
|
},
|
|
|
|
async createRecord(store, type, snapshot) {
|
|
const serializer = store.serializerFor(type.modelName);
|
|
let data = serializer.serialize(snapshot);
|
|
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
|
|
try {
|
|
await this.ajax(this.url(path), 'POST', { data });
|
|
} catch (e) {
|
|
// if error determine if path duplicate or permissions
|
|
if (e.httpStatus === 400) {
|
|
throw new Error('samePath');
|
|
}
|
|
throw new Error('mountIssue');
|
|
}
|
|
// 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 }),
|
|
};
|
|
});
|
|
}
|
|
},
|
|
|
|
findRecord(store, type, path, snapshot) {
|
|
if (snapshot.attr('type') === 'ssh') {
|
|
return this.ajax(`/v1/${encodePath(path)}/config/ca`, 'GET');
|
|
}
|
|
return;
|
|
},
|
|
|
|
queryRecord(store, type, query) {
|
|
if (query.type === 'aws') {
|
|
return this.ajax(`/v1/${encodePath(query.backend)}/config/lease`, 'GET').then((resp) => {
|
|
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);
|
|
return this.ajax(`/v1/${path}/${apiPath}`, options.isDelete ? 'DELETE' : 'POST', { data });
|
|
}
|
|
},
|
|
|
|
saveAWSRoot(store, type, snapshot) {
|
|
let { data } = snapshot.adapterOptions;
|
|
const path = encodePath(snapshot.id);
|
|
return this.ajax(`/v1/${path}/config/root`, 'POST', { data });
|
|
},
|
|
|
|
saveAWSLease(store, type, snapshot) {
|
|
let { data } = snapshot.adapterOptions;
|
|
const path = encodePath(snapshot.id);
|
|
return this.ajax(`/v1/${path}/config/lease`, 'POST', { data });
|
|
},
|
|
|
|
saveZeroAddressConfig(store, type, snapshot) {
|
|
const path = encodePath(snapshot.id);
|
|
const roles = store.peekAll('role-ssh').filterBy('zeroAddress').mapBy('id').join(',');
|
|
const url = `/v1/${path}/config/zeroaddress`;
|
|
const data = { roles };
|
|
if (roles === '') {
|
|
return this.ajax(url, 'DELETE');
|
|
}
|
|
return this.ajax(url, 'POST', { data });
|
|
},
|
|
});
|