open-vault/ui/app/adapters/policy.js
Hamid Ghaf 27bb03bbc0
adding copyright header (#19555)
* adding copyright header

* fix fmt and a test
2023-03-15 09:00:52 -07:00

43 lines
1.1 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { assign } from '@ember/polyfills';
import ApplicationAdapter from './application';
export default ApplicationAdapter.extend({
namespace: 'v1/sys',
pathForType(type) {
const path = type.replace('policy', 'policies');
return path;
},
createOrUpdate(store, type, snapshot) {
const serializer = store.serializerFor('policy');
const data = serializer.serialize(snapshot);
const name = snapshot.attr('name');
return this.ajax(this.buildURL(type.modelName, name), 'PUT', { data }).then(() => {
// doing this to make it like a Vault response - ember data doesn't like 204s if it's not a DELETE
return {
data: assign({}, this.serialize(snapshot), { id: name }),
};
});
},
createRecord() {
return this.createOrUpdate(...arguments);
},
updateRecord() {
return this.createOrUpdate(...arguments);
},
query(store, type) {
return this.ajax(this.buildURL(type.modelName), 'GET', {
data: { list: true },
});
},
});