vault/ui/app/adapters/secret.js
Matthew Irish 222b540c56
Update ui to reflect config changes for kv. versioned -> version (#4310)
* update ui to reflect config changes for kv. versioned -> version
* options not config
* tweak version display in the ui
2018-04-09 16:49:52 -05:00

87 lines
1.9 KiB
JavaScript

import Ember from 'ember';
import ApplicationAdapter from './application';
const { computed } = Ember;
export default ApplicationAdapter.extend({
namespace: 'v1',
headers: computed(function() {
return {
'X-Vault-Kv-Client': 'v2',
};
}),
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: { 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, infix = 'data') {
let url = `${this.buildURL()}/${backend}/${infix}/`;
if (!Ember.isEmpty(id)) {
url = url + id;
}
return url;
},
optionsForQuery(id, action) {
let data = {};
if (action === 'query') {
data['list'] = true;
}
return { data };
},
urlForQuery(query) {
let { id, backend } = query;
return this.urlForSecret(backend, id, 'metadata');
},
urlForQueryRecord(query) {
let { id, backend } = query;
return this.urlForSecret(backend, id);
},
query(store, type, query) {
return this.ajax(
this.urlForQuery(query, type.modelName),
'GET',
this.optionsForQuery(query.id, 'query')
).then(resp => {
resp.id = query.id;
return resp;
});
},
queryRecord(store, type, query) {
return this.ajax(
this.urlForQueryRecord(query, type.modelName),
'GET',
this.optionsForQuery(query.id, 'queryRecord')
).then(resp => {
resp.id = query.id;
return resp;
});
},
});