2023-03-15 16:00:52 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*/
|
|
|
|
|
2018-04-03 14:16:57 +00:00
|
|
|
import ApplicationAdapter from './application';
|
|
|
|
|
|
|
|
const WRAPPING_ENDPOINTS = ['lookup', 'wrap', 'unwrap', 'rewrap'];
|
|
|
|
const TOOLS_ENDPOINTS = ['random', 'hash'];
|
|
|
|
|
|
|
|
export default ApplicationAdapter.extend({
|
|
|
|
toolUrlFor(action) {
|
|
|
|
const isWrapping = WRAPPING_ENDPOINTS.includes(action);
|
|
|
|
const isTool = TOOLS_ENDPOINTS.includes(action);
|
|
|
|
const prefix = isWrapping ? 'wrapping' : 'tools';
|
|
|
|
if (!isWrapping && !isTool) {
|
|
|
|
throw new Error(`Calls to a ${action} endpoint are not currently allowed in the tool adapter`);
|
|
|
|
}
|
|
|
|
return `${this.buildURL()}/${prefix}/${action}`;
|
|
|
|
},
|
|
|
|
|
|
|
|
toolAction(action, data, options = {}) {
|
2018-07-05 18:28:12 +00:00
|
|
|
const { wrapTTL, clientToken } = options;
|
2018-04-03 14:16:57 +00:00
|
|
|
const url = this.toolUrlFor(action);
|
2018-07-05 18:28:12 +00:00
|
|
|
const ajaxOptions = wrapTTL ? { data, wrapTTL, clientToken } : { data, clientToken };
|
2018-04-03 14:16:57 +00:00
|
|
|
return this.ajax(url, 'POST', ajaxOptions);
|
|
|
|
},
|
|
|
|
});
|