2023-04-11 06:07:26 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
import ApplicationAdapter from '../application';
|
2023-05-23 23:05:15 +00:00
|
|
|
import { encodePath } from 'vault/utils/path-encoding-helpers';
|
2023-04-11 06:07:26 +00:00
|
|
|
|
|
|
|
export default class PkiTidyAdapter extends ApplicationAdapter {
|
|
|
|
namespace = 'v1';
|
|
|
|
|
2023-05-23 23:05:15 +00:00
|
|
|
_baseUrl(backend) {
|
|
|
|
return `${this.buildURL()}/${encodePath(backend)}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
// single tidy operations (manual) are always a new record
|
|
|
|
createRecord(store, type, snapshot) {
|
2023-04-11 06:07:26 +00:00
|
|
|
const { backend } = snapshot.record;
|
|
|
|
const { tidyType } = snapshot.adapterOptions;
|
2023-05-23 23:05:15 +00:00
|
|
|
if (tidyType === 'auto') {
|
|
|
|
throw new Error('Auto tidy type models are never new, please use findRecord');
|
2023-04-11 06:07:26 +00:00
|
|
|
}
|
|
|
|
|
2023-05-23 23:05:15 +00:00
|
|
|
const url = `${this._baseUrl(backend)}/tidy`;
|
|
|
|
return this.ajax(url, 'POST', { data: this.serialize(snapshot, tidyType) });
|
|
|
|
}
|
2023-04-11 06:07:26 +00:00
|
|
|
|
2023-05-23 23:05:15 +00:00
|
|
|
// saving auto-tidy config POST requests will always update
|
|
|
|
updateRecord(store, type, snapshot) {
|
|
|
|
const backend = snapshot.record.id;
|
|
|
|
const { tidyType } = snapshot.adapterOptions;
|
|
|
|
if (tidyType === 'manual') {
|
|
|
|
throw new Error('Manual tidy type models are always new, please use createRecord');
|
2023-04-11 06:07:26 +00:00
|
|
|
}
|
2023-05-23 23:05:15 +00:00
|
|
|
|
|
|
|
const url = `${this._baseUrl(backend)}/config/auto-tidy`;
|
|
|
|
return this.ajax(url, 'POST', { data: this.serialize(snapshot, tidyType) });
|
2023-04-11 06:07:26 +00:00
|
|
|
}
|
|
|
|
|
2023-05-23 23:05:15 +00:00
|
|
|
findRecord(store, type, backend) {
|
|
|
|
// only auto-tidy will ever be read, no need to pass the type here
|
|
|
|
return this.ajax(`${this._baseUrl(backend)}/config/auto-tidy`, 'GET').then((resp) => {
|
|
|
|
return resp.data;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
cancelTidy(backend) {
|
|
|
|
const url = `${this._baseUrl(backend)}`;
|
|
|
|
return this.ajax(`${url}/tidy-cancel`, 'POST');
|
2023-04-11 06:07:26 +00:00
|
|
|
}
|
|
|
|
}
|