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

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

79 lines
1.7 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import { inject as service } from '@ember/service';
import Component from '@ember/component';
import { get } from '@ember/object';
export default Component.extend({
classNames: 'config-pki',
flashMessages: service(),
errors: null,
/*
*
* @param String
* @public
* String corresponding to the route parameter for the current section
*
*/
section: null,
/*
* @param DS.Model
* @public
*
* a `pki-config` model - passed in in the component usage
*
*/
config: null,
/*
* @param Function
* @public
*
* function that gets called to refresh the config model
*
*/
onRefresh() {},
loading: false,
actions: {
handleCrlTtl({ enabled, goSafeTimeString }) {
this.config.disable = !enabled; // when TTL enabled, config disable=false
this.config.expiry = goSafeTimeString;
},
save(section) {
this.set('loading', true);
const config = this.config;
config
.save({
adapterOptions: {
method: section,
fields: get(config, `${section}Attrs`).map((attr) => attr.name),
},
})
.then(() => {
this.flashMessages.success(`The ${section} config for this backend has been updated.`);
// attrs aren't persistent for Tidy
if (section === 'tidy') {
config.rollbackAttributes();
}
this.send('refresh');
})
.catch((e) => {
this.set('errors', e.errors);
})
.finally(() => {
this.set('loading', false);
});
},
refresh() {
this.onRefresh();
},
},
});