2018-09-25 16:28:26 +00:00
|
|
|
import { isEmpty } from '@ember/utils';
|
2018-04-03 14:16:57 +00:00
|
|
|
import ApplicationAdapter from './application';
|
2019-03-01 16:08:30 +00:00
|
|
|
import { encodePath } from 'vault/utils/path-encoding-helpers';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
export default ApplicationAdapter.extend({
|
|
|
|
namespace: 'v1',
|
|
|
|
|
|
|
|
createOrUpdate(store, type, snapshot) {
|
|
|
|
const serializer = store.serializerFor(type.modelName);
|
|
|
|
const data = serializer.serialize(snapshot);
|
|
|
|
const { id } = snapshot;
|
|
|
|
|
2018-04-20 02:26:25 +00:00
|
|
|
return this.ajax(this.urlForSecret(snapshot.attr('backend'), id), 'POST', { data });
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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');
|
|
|
|
},
|
|
|
|
|
2018-04-20 02:26:25 +00:00
|
|
|
urlForSecret(backend, id) {
|
2019-03-01 16:08:30 +00:00
|
|
|
let url = `${this.buildURL()}/${encodePath(backend)}/`;
|
2018-09-25 16:28:26 +00:00
|
|
|
if (!isEmpty(id)) {
|
2019-03-01 16:08:30 +00:00
|
|
|
url = url + encodePath(id);
|
2018-04-03 14:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return url;
|
|
|
|
},
|
|
|
|
|
2019-02-14 18:52:34 +00:00
|
|
|
pathForType() {
|
|
|
|
return 'mounts';
|
|
|
|
},
|
|
|
|
|
2018-11-12 16:27:06 +00:00
|
|
|
optionsForQuery(id, action, wrapTTL) {
|
2018-04-03 14:16:57 +00:00
|
|
|
let data = {};
|
|
|
|
if (action === 'query') {
|
2018-11-12 16:27:06 +00:00
|
|
|
data.list = true;
|
|
|
|
}
|
|
|
|
if (wrapTTL) {
|
|
|
|
return { data, wrapTTL };
|
2018-04-03 14:16:57 +00:00
|
|
|
}
|
|
|
|
return { data };
|
|
|
|
},
|
|
|
|
|
2018-04-20 02:26:25 +00:00
|
|
|
fetchByQuery(query, action) {
|
2018-11-12 16:27:06 +00:00
|
|
|
const { id, backend, wrapTTL } = query;
|
|
|
|
return this.ajax(this.urlForSecret(backend, id), 'GET', this.optionsForQuery(id, action, wrapTTL)).then(
|
|
|
|
resp => {
|
|
|
|
if (wrapTTL) {
|
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
resp.id = id;
|
|
|
|
resp.backend = backend;
|
|
|
|
return resp;
|
|
|
|
}
|
|
|
|
);
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
query(store, type, query) {
|
2018-04-20 02:26:25 +00:00
|
|
|
return this.fetchByQuery(query, 'query');
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
queryRecord(store, type, query) {
|
2018-04-20 02:26:25 +00:00
|
|
|
return this.fetchByQuery(query, 'queryRecord');
|
2018-04-03 14:16:57 +00:00
|
|
|
},
|
|
|
|
});
|