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

63 lines
1.4 KiB
JavaScript
Raw Normal View History

import { isEmpty } from '@ember/utils';
2018-04-03 14:16:57 +00:00
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 });
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');
},
urlForSecret(backend, id) {
let url = `${this.buildURL()}/${backend}/`;
if (!isEmpty(id)) {
2018-04-03 14:16:57 +00:00
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;
resp.backend = backend;
return resp;
});
2018-04-03 14:16:57 +00:00
},
query(store, type, query) {
return this.fetchByQuery(query, 'query');
2018-04-03 14:16:57 +00:00
},
queryRecord(store, type, query) {
return this.fetchByQuery(query, 'queryRecord');
2018-04-03 14:16:57 +00:00
},
});