2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2018-09-25 16:28:26 +00:00
|
|
|
import { assign } from '@ember/polyfills';
|
2022-06-14 16:18:06 +00:00
|
|
|
import Adapter from '../pki';
|
2018-04-03 14:16:57 +00:00
|
|
|
|
|
|
|
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) {
|
2022-11-09 23:15:31 +00:00
|
|
|
const data = {};
|
2018-04-03 14:16:57 +00:00
|
|
|
if (!id) {
|
|
|
|
data['list'] = true;
|
|
|
|
}
|
|
|
|
return { data };
|
|
|
|
},
|
|
|
|
|
|
|
|
fetchByQuery(store, query) {
|
|
|
|
const { backend, id } = query;
|
2021-12-17 03:44:29 +00:00
|
|
|
return this.ajax(this.urlFor(backend, id), 'GET', this.optionsForQuery(id)).then((resp) => {
|
2018-04-03 14:16:57 +00:00
|
|
|
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,
|
|
|
|
};
|
2021-12-17 03:44:29 +00:00
|
|
|
return this.ajax(`${this.buildURL()}/${backend}/revoke`, 'POST', { data }).then((resp) => {
|
2018-04-03 14:16:57 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
},
|
|
|
|
});
|