2018-09-25 16:28:26 +00:00
|
|
|
import { assign } from '@ember/polyfills';
|
2018-04-03 14:16:57 +00:00
|
|
|
import Adapter from './pki';
|
|
|
|
|
|
|
|
export default Adapter.extend({
|
|
|
|
url(role) {
|
|
|
|
return `/v1/${role.backend}/issue/${role.name}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
urlFor(backend, id) {
|
|
|
|
let url = `${this.buildURL()}/${backend}/certs`;
|
|
|
|
if (id) {
|
|
|
|
url = `${this.buildURL()}/${backend}/cert/${id}`;
|
|
|
|
}
|
|
|
|
return url;
|
|
|
|
},
|
|
|
|
|
|
|
|
optionsForQuery(id) {
|
|
|
|
let data = {};
|
|
|
|
if (!id) {
|
|
|
|
data['list'] = true;
|
|
|
|
}
|
|
|
|
return { data };
|
|
|
|
},
|
|
|
|
|
|
|
|
fetchByQuery(store, query) {
|
|
|
|
const { backend, id } = query;
|
|
|
|
return this.ajax(this.urlFor(backend, id), 'GET', this.optionsForQuery(id)).then(resp => {
|
|
|
|
const data = {
|
|
|
|
backend,
|
|
|
|
};
|
|
|
|
if (id) {
|
|
|
|
data.serial_number = id;
|
|
|
|
data.id = id;
|
|
|
|
data.id_for_nav = `cert/${id}`;
|
|
|
|
}
|
2018-09-25 16:28:26 +00:00
|
|
|
return assign({}, resp, data);
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
query(store, type, query) {
|
|
|
|
return this.fetchByQuery(store, query);
|
|
|
|
},
|
|
|
|
|
|
|
|
queryRecord(store, type, query) {
|
|
|
|
return this.fetchByQuery(store, query);
|
|
|
|
},
|
|
|
|
|
|
|
|
updateRecord(store, type, snapshot) {
|
|
|
|
if (snapshot.adapterOptions.method !== 'revoke') {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const id = snapshot.id;
|
|
|
|
const backend = snapshot.record.get('backend');
|
|
|
|
const data = {
|
|
|
|
serial_number: id,
|
|
|
|
};
|
|
|
|
return this.ajax(`${this.buildURL()}/${backend}/revoke`, 'POST', { data }).then(resp => {
|
|
|
|
const data = {
|
|
|
|
id,
|
|
|
|
serial_number: id,
|
|
|
|
backend,
|
|
|
|
};
|
2018-09-25 16:28:26 +00:00
|
|
|
return assign({}, resp, data);
|
2018-04-03 14:16:57 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|