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