open-vault/ui/app/adapters/secret-v2.js
Matthew Irish 7f4dbe3fd2
Ui kv v2 redux (#4393)
* 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
2018-04-19 21:26:25 -05:00

35 lines
917 B
JavaScript

import Ember from 'ember';
import SecretAdapter from './secret';
export default SecretAdapter.extend({
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 },
});
},
urlForSecret(backend, id, infix = 'data') {
let url = `${this.buildURL()}/${backend}/${infix}/`;
if (!Ember.isEmpty(id)) {
url = url + id;
}
return url;
},
fetchByQuery(query, methodCall) {
let { id, backend } = query;
let args = [backend, id];
if (methodCall === 'query') {
args.push('metadata');
}
return this.ajax(this.urlForSecret(...args), 'GET', this.optionsForQuery(id, methodCall)).then(resp => {
resp.id = id;
return resp;
});
},
});