rotate cert modal

This commit is contained in:
Nancy Butler 2021-05-28 05:38:16 -07:00 committed by Neil MacDougall
parent 4dc6c07ff5
commit ed217320bf
6 changed files with 177 additions and 1 deletions

View File

@ -1048,6 +1048,12 @@ cluster:
machinePools: Machine Pools machinePools: Machine Pools
registry: Private Registry registry: Private Registry
upgrade: Upgrade Strategy upgrade: Upgrade Strategy
rotateCertificates:
label: Rotate Certificates
modalTitle: Rotate Cluster Certificates
services: Services
allServices: Rotate all service certificates
selectService: Rotate an individual service
clusterIndexPage: clusterIndexPage:
hardwareResourceGauge: hardwareResourceGauge:

View File

@ -0,0 +1,135 @@
<script>
import LabeledSelect from '@/components/form/LabeledSelect';
import Card from '@/components/Card';
import AsyncButton from '@/components/AsyncButton';
import RadioGroup from '@/components/form/RadioGroup';
import { get } from '@/utils/object';
import { mapState } from 'vuex';
export default {
components: {
LabeledSelect,
RadioGroup,
Card,
AsyncButton
},
data() {
return {
selectedService: '', allServices: true, errors: []
};
},
computed: {
...mapState('action-menu', ['showPromptRotate', 'toRotate']),
serviceOptions() {
const schema = this.$store.getters['rancher/schemaFor']('rotatecertificateinput');
return get(schema, 'resourceFields.services.options') || '';
},
actionParams() {
if (this.allServices) {
return {
services: null,
caCertificates: false,
};
} else {
return {
services: this.selectedService,
caCertificates: false,
};
}
}
},
watch: {
showPromptRotate(show) {
if (show) {
this.$modal.show('rotate-certs');
} else {
this.$modal.hide('rotate-certs');
}
}
},
methods: {
close() {
this.$store.commit('action-menu/togglePromptRotate');
},
rotate(btnCB) {
const cluster = this.toRotate.mgmt || {};
if (!cluster?.actions?.rotateCertificates) {
btnCB(false);
} else {
const params = this.actionParams;
cluster.doAction('rotateCertificates', cluster, { params }).then((res) => {
if (res._status === 200) {
btnCB(true);
this.errors = [];
this.close();
} else {
this.errors.push(res._statusText);
btnCB(false);
}
});
}
},
}
};
</script>
<template>
<modal class="rotate-modal" name="rotate-certs" @closed="close">
<Card :style="{'height':'100%'}">
<template #title>
<h3>{{ t('cluster.rotateCertificates.modalTitle') }}</h3>
</template>
<template #body>
<div v-for="error in errors" :key="error" class="row mb-20 text-error">
{{ error }}
</div>
<div class="row">
<div class="col span-6">
<RadioGroup v-model="allServices" name="service-mode" :options="[{value: true,label:t('cluster.rotateCertificates.allServices')}, {value: false, label:t('cluster.rotateCertificates.selectService')}]" />
</div>
<div class="col span-6">
<LabeledSelect v-if="!allServices" v-model="selectedService" :options="serviceOptions" :label="t('cluster.rotateCertificates.services')" />
</div>
</div>
</template>
<template #actions>
<button class="btn role-secondary mr-20" @click="close">
{{ t('generic.cancel') }}
</button>
<AsyncButton @click="rotate" />
</template>
</Card>
</modal>
</template>
<style lang='scss' scoped>
.rotate-modal ::v-deep.v--modal-box{
border:none;
& .card-container{
margin: 0;
& .card-wrap {
display:flex;
flex-direction:column;
}
& .card-body {
flex: 1;
}
& .card-actions{
align-self: center
};
}
}
</style>

View File

@ -1,12 +1,15 @@
<script> <script>
import ResourceTable from '@/components/ResourceTable'; import ResourceTable from '@/components/ResourceTable';
import Masthead from '@/components/ResourceList/Masthead'; import Masthead from '@/components/ResourceList/Masthead';
import RotateCertificates from '@/components/RotateCertificates';
import { allHash } from '@/utils/promise'; import { allHash } from '@/utils/promise';
import { CAPI, MANAGEMENT } from '@/config/types'; import { CAPI, MANAGEMENT } from '@/config/types';
import { MODE, _IMPORT } from '@/config/query-params'; import { MODE, _IMPORT } from '@/config/query-params';
export default { export default {
components: { ResourceTable, Masthead }, components: {
ResourceTable, Masthead, RotateCertificates
},
async fetch() { async fetch() {
const hash = await allHash({ const hash = await allHash({
@ -104,5 +107,6 @@ export default {
</button> </button>
</template> </template>
</ResourceTable> </ResourceTable>
<RotateCertificates />
</div> </div>
</template> </template>

View File

@ -45,6 +45,15 @@ export default {
enabled: this.$rootGetters['isRancher'], enabled: this.$rootGetters['isRancher'],
}); });
if (this.mgmt.actions['rotateCertificates']) {
insertAt(out, 1, {
action: 'toggleRotateCertificates',
label: 'Rotate Certificates',
icon: 'icon icon-backup',
bulkable: true,
});
}
const canSaveAsTemplate = this.isRke1 && this.mgmt.status.driver === 'rancherKubernetesEngine' && !this.mgmt.spec.clusterTemplateName && this.hasLink('update'); const canSaveAsTemplate = this.isRke1 && this.mgmt.status.driver === 'rancherKubernetesEngine' && !this.mgmt.spec.clusterTemplateName && this.hasLink('update');
const canRotateEncryptionKey = this.isRke1 && this.mgmt?.hasAction('rotateEncryptionKey'); const canRotateEncryptionKey = this.isRke1 && this.mgmt?.hasAction('rotateEncryptionKey');
@ -303,6 +312,12 @@ export default {
}; };
}, },
toggleRotateCertificates() {
return () => {
this.$dispatch('promptRotate', this);
};
},
etcdSnapshots() { etcdSnapshots() {
return (this.status?.etcdSnapshots || []).map((x) => { return (this.status?.etcdSnapshots || []).map((x) => {
x.id = x.name || x._name; x.id = x.name || x._name;

View File

@ -403,6 +403,10 @@ export default {
commit('action-menu/togglePromptModal', data, { root: true }); commit('action-menu/togglePromptModal', data, { root: true });
}, },
promptRotate({ commit, state }, cluster ) {
commit('action-menu/togglePromptRotate', cluster, { root: true });
},
async resourceAction({ getters, dispatch }, { async resourceAction({ getters, dispatch }, {
resource, actionName, body, opt, resource, actionName, body, opt,
}) { }) {

View File

@ -13,6 +13,7 @@ export const state = function() {
showPromptRestore: false, showPromptRestore: false,
showAssignTo: false, showAssignTo: false,
showPromptUpdate: false, showPromptUpdate: false,
showPromptRotate: false,
showModal: false, showModal: false,
toMove: [], toMove: [],
toRemove: [], toRemove: [],
@ -20,6 +21,7 @@ export const state = function() {
toAssign: [], toAssign: [],
toUpdate: [], toUpdate: [],
modalData: {}, modalData: {},
toRotate: {}
}; };
}; };
@ -148,6 +150,16 @@ export const mutations = {
} }
state.modalData = data; state.modalData = data;
},
togglePromptRotate(state, cluster) {
if (!cluster) {
state.showPromptRotate = false;
} else {
state.showPromptRotate = !state.showPromptRotate;
}
state.toRotate = cluster;
} }
}; };