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