-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathkey.js
53 lines (46 loc) · 1.48 KB
/
key.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: BUSL-1.1
*/
import ApplicationAdapter from '../application';
import { encodePath } from 'vault/utils/path-encoding-helpers';
export default class PkiKeyAdapter extends ApplicationAdapter {
namespace = 'v1';
_baseUrl(backend, id) {
const url = `${this.buildURL()}/${encodePath(backend)}`;
if (id) {
return url + '/key/' + encodePath(id);
}
return url + '/keys';
}
createRecord(store, type, snapshot) {
const { record, adapterOptions } = snapshot;
let url = this._baseUrl(record.backend);
if (adapterOptions.import) {
url = `${url}/import`;
} else {
url = `${url}/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._baseUrl(record.backend, record.id);
return this.ajax(url, 'POST', { data: { key_name } });
}
query(store, type, query) {
const { backend } = query;
return this.ajax(this._baseUrl(backend), 'GET', { data: { list: true } });
}
queryRecord(store, type, query) {
const { backend, id } = query;
return this.ajax(this._baseUrl(backend, id), 'GET');
}
deleteRecord(store, type, snapshot) {
const { id, record } = snapshot;
return this.ajax(this._baseUrl(record.backend, id), 'DELETE');
}
}