Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 1 | <template> |
Yoshie Muranaka | 3111b6f | 2020-04-21 19:48:38 -0700 | [diff] [blame] | 2 | <b-container fluid="xl"> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 3 | <page-title /> |
| 4 | <b-row> |
Yoshie Muranaka | 3111b6f | 2020-04-21 19:48:38 -0700 | [diff] [blame] | 5 | <b-col xl="11"> |
Yoshie Muranaka | e45f54b | 2020-03-26 15:23:34 -0700 | [diff] [blame] | 6 | <!-- Expired certificates banner --> |
| 7 | <alert :show="expiredCertificateTypes.length > 0" variant="danger"> |
| 8 | <template v-if="expiredCertificateTypes.length > 1"> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 9 | {{ $t('pageCertificates.alert.certificatesExpiredMessage') }} |
Yoshie Muranaka | e45f54b | 2020-03-26 15:23:34 -0700 | [diff] [blame] | 10 | </template> |
| 11 | <template v-else> |
| 12 | {{ |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 13 | $t('pageCertificates.alert.certificateExpiredMessage', { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 14 | certificate: expiredCertificateTypes[0], |
Yoshie Muranaka | e45f54b | 2020-03-26 15:23:34 -0700 | [diff] [blame] | 15 | }) |
| 16 | }} |
| 17 | </template> |
| 18 | </alert> |
| 19 | <!-- Expiring certificates banner --> |
| 20 | <alert :show="expiringCertificateTypes.length > 0" variant="warning"> |
| 21 | <template v-if="expiringCertificateTypes.length > 1"> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 22 | {{ $t('pageCertificates.alert.certificatesExpiringMessage') }} |
Yoshie Muranaka | e45f54b | 2020-03-26 15:23:34 -0700 | [diff] [blame] | 23 | </template> |
| 24 | <template v-else> |
| 25 | {{ |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 26 | $t('pageCertificates.alert.certificateExpiringMessage', { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 27 | certificate: expiringCertificateTypes[0], |
Yoshie Muranaka | e45f54b | 2020-03-26 15:23:34 -0700 | [diff] [blame] | 28 | }) |
| 29 | }} |
| 30 | </template> |
| 31 | </alert> |
| 32 | </b-col> |
| 33 | </b-row> |
| 34 | <b-row> |
Yoshie Muranaka | 3111b6f | 2020-04-21 19:48:38 -0700 | [diff] [blame] | 35 | <b-col xl="11" class="text-right"> |
SurenNeware | d0df7d2 | 2020-07-22 16:41:20 +0530 | [diff] [blame] | 36 | <b-button |
| 37 | v-b-modal.generate-csr |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 38 | data-test-id="certificates-button-generateCsr" |
SurenNeware | d0df7d2 | 2020-07-22 16:41:20 +0530 | [diff] [blame] | 39 | variant="link" |
| 40 | > |
Yoshie Muranaka | 532a4b0 | 2020-03-27 11:00:50 -0700 | [diff] [blame] | 41 | <icon-add /> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 42 | {{ $t('pageCertificates.generateCsr') }} |
Yoshie Muranaka | 532a4b0 | 2020-03-27 11:00:50 -0700 | [diff] [blame] | 43 | </b-button> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 44 | <b-button |
| 45 | variant="primary" |
| 46 | :disabled="certificatesForUpload.length === 0" |
| 47 | @click="initModalUploadCertificate(null)" |
| 48 | > |
| 49 | <icon-add /> |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 50 | {{ $t('pageCertificates.addNewCertificate') }} |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 51 | </b-button> |
| 52 | </b-col> |
| 53 | </b-row> |
| 54 | <b-row> |
Yoshie Muranaka | 3111b6f | 2020-04-21 19:48:38 -0700 | [diff] [blame] | 55 | <b-col xl="11"> |
SurenNeware | 307382e | 2020-07-27 20:45:14 +0530 | [diff] [blame] | 56 | <b-table |
| 57 | responsive="md" |
| 58 | show-empty |
Sukanya Pandey | fde429e | 2020-09-14 20:48:39 +0530 | [diff] [blame] | 59 | hover |
Kenneth Fullbright | 4105785 | 2021-12-27 16:19:37 -0600 | [diff] [blame] | 60 | :busy="isBusy" |
SurenNeware | 307382e | 2020-07-27 20:45:14 +0530 | [diff] [blame] | 61 | :fields="fields" |
| 62 | :items="tableItems" |
| 63 | :empty-text="$t('global.table.emptyMessage')" |
| 64 | > |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 65 | <template #cell(validFrom)="{ value }"> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 66 | {{ value | formatDate }} |
| 67 | </template> |
| 68 | |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 69 | <template #cell(validUntil)="{ value }"> |
Yoshie Muranaka | e45f54b | 2020-03-26 15:23:34 -0700 | [diff] [blame] | 70 | <status-icon |
| 71 | v-if="getDaysUntilExpired(value) < 31" |
| 72 | :status="getIconStatus(value)" |
| 73 | /> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 74 | {{ value | formatDate }} |
| 75 | </template> |
| 76 | |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 77 | <template #cell(actions)="{ value, item }"> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 78 | <table-row-action |
| 79 | v-for="(action, index) in value" |
| 80 | :key="index" |
| 81 | :value="action.value" |
| 82 | :title="action.title" |
| 83 | :enabled="action.enabled" |
Sukanya Pandey | edb8a77 | 2020-10-29 11:33:42 +0530 | [diff] [blame] | 84 | @click-table-action="onTableRowAction($event, item)" |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 85 | > |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 86 | <template #icon> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 87 | <icon-replace v-if="action.value === 'replace'" /> |
| 88 | <icon-trashcan v-if="action.value === 'delete'" /> |
| 89 | </template> |
| 90 | </table-row-action> |
| 91 | </template> |
| 92 | </b-table> |
| 93 | </b-col> |
| 94 | </b-row> |
| 95 | |
| 96 | <!-- Modals --> |
| 97 | <modal-upload-certificate :certificate="modalCertificate" @ok="onModalOk" /> |
Yoshie Muranaka | 532a4b0 | 2020-03-27 11:00:50 -0700 | [diff] [blame] | 98 | <modal-generate-csr /> |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 99 | </b-container> |
| 100 | </template> |
| 101 | |
| 102 | <script> |
| 103 | import IconAdd from '@carbon/icons-vue/es/add--alt/20'; |
| 104 | import IconReplace from '@carbon/icons-vue/es/renew/20'; |
| 105 | import IconTrashcan from '@carbon/icons-vue/es/trash-can/20'; |
| 106 | |
Yoshie Muranaka | 532a4b0 | 2020-03-27 11:00:50 -0700 | [diff] [blame] | 107 | import ModalGenerateCsr from './ModalGenerateCsr'; |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 108 | import ModalUploadCertificate from './ModalUploadCertificate'; |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 109 | import PageTitle from '@/components/Global/PageTitle'; |
| 110 | import TableRowAction from '@/components/Global/TableRowAction'; |
| 111 | import StatusIcon from '@/components/Global/StatusIcon'; |
| 112 | import Alert from '@/components/Global/Alert'; |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 113 | |
SurenNeware | 5e25e28 | 2020-07-08 15:57:23 +0530 | [diff] [blame] | 114 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
Yoshie Muranaka | e5be9ba | 2020-04-30 10:13:40 -0700 | [diff] [blame] | 115 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 116 | |
| 117 | export default { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 118 | name: 'Certificates', |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 119 | components: { |
Yoshie Muranaka | e45f54b | 2020-03-26 15:23:34 -0700 | [diff] [blame] | 120 | Alert, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 121 | IconAdd, |
| 122 | IconReplace, |
| 123 | IconTrashcan, |
Yoshie Muranaka | 532a4b0 | 2020-03-27 11:00:50 -0700 | [diff] [blame] | 124 | ModalGenerateCsr, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 125 | ModalUploadCertificate, |
| 126 | PageTitle, |
Yoshie Muranaka | e45f54b | 2020-03-26 15:23:34 -0700 | [diff] [blame] | 127 | StatusIcon, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 128 | TableRowAction, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 129 | }, |
Yoshie Muranaka | e5be9ba | 2020-04-30 10:13:40 -0700 | [diff] [blame] | 130 | mixins: [BVToastMixin, LoadingBarMixin], |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 131 | beforeRouteLeave(to, from, next) { |
| 132 | this.hideLoader(); |
| 133 | next(); |
| 134 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 135 | data() { |
| 136 | return { |
Kenneth Fullbright | 4105785 | 2021-12-27 16:19:37 -0600 | [diff] [blame] | 137 | isBusy: true, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 138 | modalCertificate: null, |
Damian Celico | 31fb2b9 | 2022-06-27 16:43:21 +0200 | [diff] [blame] | 139 | fileTypeCorrect: undefined, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 140 | fields: [ |
| 141 | { |
| 142 | key: 'certificate', |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 143 | label: this.$t('pageCertificates.table.certificate'), |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 144 | }, |
| 145 | { |
| 146 | key: 'issuedBy', |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 147 | label: this.$t('pageCertificates.table.issuedBy'), |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 148 | }, |
| 149 | { |
| 150 | key: 'issuedTo', |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 151 | label: this.$t('pageCertificates.table.issuedTo'), |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 152 | }, |
| 153 | { |
| 154 | key: 'validFrom', |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 155 | label: this.$t('pageCertificates.table.validFrom'), |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 156 | }, |
| 157 | { |
| 158 | key: 'validUntil', |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 159 | label: this.$t('pageCertificates.table.validUntil'), |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 160 | }, |
| 161 | { |
| 162 | key: 'actions', |
| 163 | label: '', |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 164 | tdClass: 'text-right text-nowrap', |
| 165 | }, |
| 166 | ], |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 167 | }; |
| 168 | }, |
| 169 | computed: { |
| 170 | certificates() { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 171 | return this.$store.getters['certificates/allCertificates']; |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 172 | }, |
| 173 | tableItems() { |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 174 | return this.certificates.map((certificate) => { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 175 | return { |
| 176 | ...certificate, |
| 177 | actions: [ |
| 178 | { |
| 179 | value: 'replace', |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 180 | title: this.$t('pageCertificates.replaceCertificate'), |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 181 | }, |
| 182 | { |
| 183 | value: 'delete', |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 184 | title: this.$t('pageCertificates.deleteCertificate'), |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 185 | enabled: |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 186 | certificate.type === 'TrustStore Certificate' ? true : false, |
| 187 | }, |
| 188 | ], |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 189 | }; |
| 190 | }); |
| 191 | }, |
| 192 | certificatesForUpload() { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 193 | return this.$store.getters['certificates/availableUploadTypes']; |
Yoshie Muranaka | e45f54b | 2020-03-26 15:23:34 -0700 | [diff] [blame] | 194 | }, |
| 195 | bmcTime() { |
| 196 | return this.$store.getters['global/bmcTime']; |
| 197 | }, |
| 198 | expiredCertificateTypes() { |
| 199 | return this.certificates.reduce((acc, val) => { |
| 200 | const daysUntilExpired = this.getDaysUntilExpired(val.validUntil); |
| 201 | if (daysUntilExpired < 1) { |
| 202 | acc.push(val.certificate); |
| 203 | } |
| 204 | return acc; |
| 205 | }, []); |
| 206 | }, |
| 207 | expiringCertificateTypes() { |
| 208 | return this.certificates.reduce((acc, val) => { |
| 209 | const daysUntilExpired = this.getDaysUntilExpired(val.validUntil); |
| 210 | if (daysUntilExpired < 31 && daysUntilExpired > 0) { |
| 211 | acc.push(val.certificate); |
| 212 | } |
| 213 | return acc; |
| 214 | }, []); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 215 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 216 | }, |
Yoshie Muranaka | e5be9ba | 2020-04-30 10:13:40 -0700 | [diff] [blame] | 217 | async created() { |
| 218 | this.startLoader(); |
| 219 | await this.$store.dispatch('global/getBmcTime'); |
Kenneth Fullbright | 4105785 | 2021-12-27 16:19:37 -0600 | [diff] [blame] | 220 | this.$store.dispatch('certificates/getCertificates').finally(() => { |
| 221 | this.endLoader(); |
| 222 | this.isBusy = false; |
| 223 | }); |
Yoshie Muranaka | e5be9ba | 2020-04-30 10:13:40 -0700 | [diff] [blame] | 224 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 225 | methods: { |
| 226 | onTableRowAction(event, rowItem) { |
| 227 | switch (event) { |
| 228 | case 'replace': |
| 229 | this.initModalUploadCertificate(rowItem); |
| 230 | break; |
| 231 | case 'delete': |
| 232 | this.initModalDeleteCertificate(rowItem); |
| 233 | break; |
| 234 | default: |
| 235 | break; |
| 236 | } |
| 237 | }, |
| 238 | initModalUploadCertificate(certificate = null) { |
| 239 | this.modalCertificate = certificate; |
| 240 | this.$bvModal.show('upload-certificate'); |
| 241 | }, |
| 242 | initModalDeleteCertificate(certificate) { |
| 243 | this.$bvModal |
| 244 | .msgBoxConfirm( |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 245 | this.$t('pageCertificates.modal.deleteConfirmMessage', { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 246 | issuedBy: certificate.issuedBy, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 247 | certificate: certificate.certificate, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 248 | }), |
| 249 | { |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 250 | title: this.$t('pageCertificates.deleteCertificate'), |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 251 | okTitle: this.$t('global.action.delete'), |
Sukanya Pandey | 3835713 | 2020-12-22 13:40:59 +0530 | [diff] [blame] | 252 | cancelTitle: this.$t('global.action.cancel'), |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 253 | } |
| 254 | ) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 255 | .then((deleteConfirmed) => { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 256 | if (deleteConfirmed) this.deleteCertificate(certificate); |
| 257 | }); |
| 258 | }, |
| 259 | onModalOk({ addNew, file, type, location }) { |
| 260 | if (addNew) { |
| 261 | // Upload a new certificate |
Damian Celico | 31fb2b9 | 2022-06-27 16:43:21 +0200 | [diff] [blame] | 262 | this.fileTypeCorrect = this.getIsFileTypeCorrect(file); |
| 263 | if (this.fileTypeCorrect) { |
| 264 | this.addNewCertificate(file, type); |
Damian Celico | 713dae0 | 2022-11-14 23:06:55 +0100 | [diff] [blame^] | 265 | } else { |
| 266 | this.errorToast( |
| 267 | this.$t('pageCertificates.alert.incorrectCertificateFileType'), |
| 268 | { |
| 269 | title: this.$t('pageCertificates.toast.errorAddCertificate'), |
| 270 | } |
| 271 | ); |
Damian Celico | 31fb2b9 | 2022-06-27 16:43:21 +0200 | [diff] [blame] | 272 | } |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 273 | } else { |
| 274 | // Replace an existing certificate |
| 275 | this.replaceCertificate(file, type, location); |
| 276 | } |
| 277 | }, |
| 278 | addNewCertificate(file, type) { |
Damian Celico | 31fb2b9 | 2022-06-27 16:43:21 +0200 | [diff] [blame] | 279 | if (this.fileTypeCorrect === true) { |
| 280 | this.startLoader(); |
| 281 | this.$store |
| 282 | .dispatch('certificates/addNewCertificate', { file, type }) |
| 283 | .then((success) => this.successToast(success)) |
| 284 | .catch(({ message }) => this.errorToast(message)) |
| 285 | .finally(() => this.endLoader()); |
| 286 | } |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 287 | }, |
| 288 | replaceCertificate(file, type, location) { |
Yoshie Muranaka | e5be9ba | 2020-04-30 10:13:40 -0700 | [diff] [blame] | 289 | this.startLoader(); |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 290 | const reader = new FileReader(); |
| 291 | reader.readAsBinaryString(file); |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 292 | reader.onloadend = (event) => { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 293 | const certificateString = event.target.result; |
| 294 | this.$store |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 295 | .dispatch('certificates/replaceCertificate', { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 296 | certificateString, |
| 297 | type, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 298 | location, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 299 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 300 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e5be9ba | 2020-04-30 10:13:40 -0700 | [diff] [blame] | 301 | .catch(({ message }) => this.errorToast(message)) |
| 302 | .finally(() => this.endLoader()); |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 303 | }; |
| 304 | }, |
| 305 | deleteCertificate({ type, location }) { |
Yoshie Muranaka | e5be9ba | 2020-04-30 10:13:40 -0700 | [diff] [blame] | 306 | this.startLoader(); |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 307 | this.$store |
Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 308 | .dispatch('certificates/deleteCertificate', { |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 309 | type, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 310 | location, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 311 | }) |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 312 | .then((success) => this.successToast(success)) |
Yoshie Muranaka | e5be9ba | 2020-04-30 10:13:40 -0700 | [diff] [blame] | 313 | .catch(({ message }) => this.errorToast(message)) |
| 314 | .finally(() => this.endLoader()); |
Yoshie Muranaka | e45f54b | 2020-03-26 15:23:34 -0700 | [diff] [blame] | 315 | }, |
| 316 | getDaysUntilExpired(date) { |
| 317 | if (this.bmcTime) { |
| 318 | const validUntilMs = date.getTime(); |
| 319 | const currentBmcTimeMs = this.bmcTime.getTime(); |
| 320 | const oneDayInMs = 24 * 60 * 60 * 1000; |
| 321 | return Math.round((validUntilMs - currentBmcTimeMs) / oneDayInMs); |
| 322 | } |
Yoshie Muranaka | e5be9ba | 2020-04-30 10:13:40 -0700 | [diff] [blame] | 323 | return new Date(); |
Yoshie Muranaka | e45f54b | 2020-03-26 15:23:34 -0700 | [diff] [blame] | 324 | }, |
| 325 | getIconStatus(date) { |
| 326 | const daysUntilExpired = this.getDaysUntilExpired(date); |
| 327 | if (daysUntilExpired < 1) { |
| 328 | return 'danger'; |
| 329 | } else if (daysUntilExpired < 31) { |
| 330 | return 'warning'; |
| 331 | } |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 332 | }, |
Damian Celico | 31fb2b9 | 2022-06-27 16:43:21 +0200 | [diff] [blame] | 333 | getIsFileTypeCorrect(file) { |
| 334 | const fileTypeExtension = file.name.split('.').pop(); |
| 335 | return fileTypeExtension === 'pem'; |
| 336 | }, |
Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 337 | }, |
Yoshie Muranaka | 3739381 | 2020-03-24 15:25:24 -0700 | [diff] [blame] | 338 | }; |
| 339 | </script> |