d56f0ccb72
* wait for all hash promises to be settled * skeleton tests with policies for write without read * adjust what gets returned from the model hook * refactor secret-edit model hook to use async/await * return a stub version if we can't read secret data * return a stub model for v1 kv * tweak tests to make re-runs friendlier * allow write without CAS if both v2 models cannot be read * show warnings on edit pages for different write without read scenarios * add no read empty states on secret show pages * review feedback * make message language consistent * use version models from metadata if we can read it * refresh route on delete / undelete / destroy * hide controls in the toolbar when you can't read the secret data * show deleted / destroyed messaging over cannot read messaging on the show page * fix test with model stub * refactor large model hook into several functions * comment clarifications
90 lines
2.6 KiB
JavaScript
90 lines
2.6 KiB
JavaScript
/* eslint-disable */
|
|
import { isEmpty } from '@ember/utils';
|
|
import { get } from '@ember/object';
|
|
import ApplicationAdapter from './application';
|
|
import DS from 'ember-data';
|
|
import { encodePath } from 'vault/utils/path-encoding-helpers';
|
|
|
|
export default ApplicationAdapter.extend({
|
|
namespace: 'v1',
|
|
_url(backend, id, infix = 'data') {
|
|
let url = `${this.buildURL()}/${encodePath(backend)}/${infix}/`;
|
|
if (!isEmpty(id)) {
|
|
url = url + encodePath(id);
|
|
}
|
|
return url;
|
|
},
|
|
|
|
urlForFindRecord(id) {
|
|
let [backend, path, version] = JSON.parse(id);
|
|
let base = this._url(backend, path);
|
|
return version ? base + `?version=${version}` : base;
|
|
},
|
|
|
|
urlForQueryRecord(id) {
|
|
return this.urlForFindRecord(id);
|
|
},
|
|
|
|
findRecord() {
|
|
return this._super(...arguments).catch(errorOrModel => {
|
|
// if it's a real 404, this will be an error, if not
|
|
// it will be the body of a deleted / destroyed version
|
|
if (errorOrModel instanceof DS.AdapterError) {
|
|
throw errorOrModel;
|
|
}
|
|
return errorOrModel;
|
|
});
|
|
},
|
|
|
|
queryRecord(id, options) {
|
|
return this.ajax(this.urlForQueryRecord(id), 'GET', options).then(resp => {
|
|
if (options.wrapTTL) {
|
|
return resp;
|
|
}
|
|
resp.id = id;
|
|
resp.backend = backend;
|
|
return resp;
|
|
});
|
|
},
|
|
|
|
urlForCreateRecord(modelName, snapshot) {
|
|
let backend = snapshot.belongsTo('secret').belongsTo('engine').id;
|
|
let path = snapshot.attr('path');
|
|
return this._url(backend, path);
|
|
},
|
|
|
|
createRecord(store, modelName, snapshot) {
|
|
let backend = snapshot.belongsTo('secret').belongsTo('engine').id;
|
|
let path = snapshot.attr('path');
|
|
return this._super(...arguments).then(resp => {
|
|
resp.id = JSON.stringify([backend, path, resp.version]);
|
|
return resp;
|
|
});
|
|
},
|
|
|
|
urlForUpdateRecord(id) {
|
|
let [backend, path] = JSON.parse(id);
|
|
return this._url(backend, path);
|
|
},
|
|
|
|
v2DeleteOperation(store, id, deleteType = 'delete') {
|
|
let [backend, path, version] = JSON.parse(id);
|
|
|
|
// deleteType should be 'delete', 'destroy', 'undelete'
|
|
return this.ajax(this._url(backend, path, deleteType), 'POST', { data: { versions: [version] } }).then(
|
|
() => {
|
|
let model = store.peekRecord('secret-v2-version', id);
|
|
return model && model.rollbackAttributes() && model.reload();
|
|
}
|
|
);
|
|
},
|
|
|
|
handleResponse(status, headers, payload, requestData) {
|
|
// the body of the 404 will have some relevant information
|
|
if (status === 404 && get(payload, 'data.metadata')) {
|
|
return this._super(200, headers, payload, requestData);
|
|
}
|
|
return this._super(...arguments);
|
|
},
|
|
});
|