open-vault/ui/app/adapters/pki/key.js
claire bontempo 424e7439dc
ui: add ability to edit pki key (#18490)
* add edit form

* refactor readonly field

* refactor conditional in key form

* remove model validations from edit form

* update namespace reminder opy
2022-12-20 23:23:55 +00:00

44 lines
1.3 KiB
JavaScript

import ApplicationAdapter from '../application';
import { encodePath } from 'vault/utils/path-encoding-helpers';
export default class PkiKeyAdapter extends ApplicationAdapter {
namespace = 'v1';
createRecord(store, type, snapshot) {
const { record } = snapshot;
const url = this.getUrl(record.backend) + '/generate/' + record.type;
return this.ajax(url, 'POST', { data: this.serialize(snapshot) }).then((resp) => {
return resp;
});
}
updateRecord(store, type, snapshot) {
const { record } = snapshot;
const { key_name } = this.serialize(snapshot);
const url = this.getUrl(record.backend, record.id);
return this.ajax(url, 'POST', { data: { key_name } });
}
getUrl(backend, id) {
const url = `${this.buildURL()}/${encodePath(backend)}`;
if (id) {
return url + '/key/' + encodePath(id);
}
return url + '/keys';
}
query(store, type, query) {
const { backend } = query;
return this.ajax(this.getUrl(backend), 'GET', { data: { list: true } });
}
queryRecord(store, type, query) {
const { backend, id } = query;
return this.ajax(this.getUrl(backend, id), 'GET');
}
deleteRecord(store, type, snapshot) {
const { id, record } = snapshot;
return this.ajax(this.getUrl(record.backend, id), 'DELETE');
}
}