7f4dbe3fd2
* remove header used for backwards compatibility in KV mounts, and use v1 paths for v1, v2 paths for v2 * make the model hook always run * simplify adapter & serializer code for secrets * update tests * fix lease tests * address review feedback
62 lines
1.4 KiB
JavaScript
62 lines
1.4 KiB
JavaScript
import Ember from 'ember';
|
|
import ApplicationAdapter from './application';
|
|
|
|
export default ApplicationAdapter.extend({
|
|
namespace: 'v1',
|
|
|
|
createOrUpdate(store, type, snapshot) {
|
|
const serializer = store.serializerFor(type.modelName);
|
|
const data = serializer.serialize(snapshot);
|
|
const { id } = snapshot;
|
|
|
|
return this.ajax(this.urlForSecret(snapshot.attr('backend'), id), 'POST', { data });
|
|
},
|
|
|
|
createRecord() {
|
|
return this.createOrUpdate(...arguments);
|
|
},
|
|
|
|
updateRecord() {
|
|
return this.createOrUpdate(...arguments);
|
|
},
|
|
|
|
deleteRecord(store, type, snapshot) {
|
|
const { id } = snapshot;
|
|
return this.ajax(this.urlForSecret(snapshot.attr('backend'), id), 'DELETE');
|
|
},
|
|
|
|
urlForSecret(backend, id) {
|
|
let url = `${this.buildURL()}/${backend}/`;
|
|
if (!Ember.isEmpty(id)) {
|
|
url = url + id;
|
|
}
|
|
|
|
return url;
|
|
},
|
|
|
|
optionsForQuery(id, action) {
|
|
let data = {};
|
|
if (action === 'query') {
|
|
data['list'] = true;
|
|
}
|
|
|
|
return { data };
|
|
},
|
|
|
|
fetchByQuery(query, action) {
|
|
const { id, backend } = query;
|
|
return this.ajax(this.urlForSecret(backend, id), 'GET', this.optionsForQuery(id, action)).then(resp => {
|
|
resp.id = id;
|
|
return resp;
|
|
});
|
|
},
|
|
|
|
query(store, type, query) {
|
|
return this.fetchByQuery(query, 'query');
|
|
},
|
|
|
|
queryRecord(store, type, query) {
|
|
return this.fetchByQuery(query, 'queryRecord');
|
|
},
|
|
});
|