blob: 53364de2c4e4678ab7578f668158ddea968ba3fb [file] [log] [blame]
Yoshie Muranaka532a4b02020-03-27 11:00:50 -07001<template>
2 <div>
3 <b-modal
4 id="generate-csr"
5 ref="modal"
jason westoverd36ac8a2025-11-03 20:58:59 -06006 v-model="isVisible"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -07007 size="lg"
8 no-stacking
Sandeepa Singhb4406162021-07-26 15:05:39 +05309 :title="$t('pageCertificates.modal.generateACertificateSigningRequest')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070010 @ok="onOkGenerateCsrModal"
11 @cancel="resetForm"
Surya Vde23ea22024-07-11 15:19:46 +053012 @hidden="v$.$reset()"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070013 >
Chandra Harkude373d2432022-12-15 20:51:02 +053014 <b-form id="generate-csr-form" novalidate>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070015 <b-container fluid>
16 <b-row>
17 <b-col lg="9">
18 <b-row>
19 <b-col lg="6">
20 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +053021 :label="$t('pageCertificates.modal.certificateType')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070022 label-for="certificate-type"
23 >
24 <b-form-select
25 id="certificate-type"
26 v-model="form.certificateType"
SurenNewared0df7d22020-07-22 16:41:20 +053027 data-test-id="modalGenerateCsr-select-certificateType"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070028 :options="certificateOptions"
Surya Vde23ea22024-07-11 15:19:46 +053029 :state="getValidationState(v$.form.certificateType)"
30 @input="v$.form.certificateType.$touch()"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070031 >
Derick Montague602e98a2020-10-21 16:20:00 -050032 <template #first>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070033 <b-form-select-option :value="null" disabled>
34 {{ $t('global.form.selectAnOption') }}
35 </b-form-select-option>
36 </template>
37 </b-form-select>
38 <b-form-invalid-feedback role="alert">
39 {{ $t('global.form.fieldRequired') }}
40 </b-form-invalid-feedback>
41 </b-form-group>
42 </b-col>
43 <b-col lg="6">
44 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +053045 :label="$t('pageCertificates.modal.country')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070046 label-for="country"
47 >
48 <b-form-select
49 id="country"
50 v-model="form.country"
SurenNewared0df7d22020-07-22 16:41:20 +053051 data-test-id="modalGenerateCsr-select-country"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070052 :options="countryOptions"
Surya Vde23ea22024-07-11 15:19:46 +053053 :state="getValidationState(v$.form.country)"
54 @input="v$.form.country.$touch()"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070055 >
Derick Montague602e98a2020-10-21 16:20:00 -050056 <template #first>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070057 <b-form-select-option :value="null" disabled>
58 {{ $t('global.form.selectAnOption') }}
59 </b-form-select-option>
60 </template>
61 </b-form-select>
62 <b-form-invalid-feedback role="alert">
63 {{ $t('global.form.fieldRequired') }}
64 </b-form-invalid-feedback>
65 </b-form-group>
66 </b-col>
67 </b-row>
68 <b-row>
69 <b-col lg="6">
70 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +053071 :label="$t('pageCertificates.modal.state')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070072 label-for="state"
73 >
74 <b-form-input
75 id="state"
76 v-model="form.state"
77 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +053078 data-test-id="modalGenerateCsr-input-state"
Surya Vde23ea22024-07-11 15:19:46 +053079 :state="getValidationState(v$.form.state)"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070080 />
81 <b-form-invalid-feedback role="alert">
82 {{ $t('global.form.fieldRequired') }}
83 </b-form-invalid-feedback>
84 </b-form-group>
85 </b-col>
86 <b-col lg="6">
87 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +053088 :label="$t('pageCertificates.modal.city')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070089 label-for="city"
90 >
91 <b-form-input
92 id="city"
93 v-model="form.city"
94 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +053095 data-test-id="modalGenerateCsr-input-city"
Surya Vde23ea22024-07-11 15:19:46 +053096 :state="getValidationState(v$.form.city)"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -070097 />
98 <b-form-invalid-feedback role="alert">
99 {{ $t('global.form.fieldRequired') }}
100 </b-form-invalid-feedback>
101 </b-form-group>
102 </b-col>
103 </b-row>
104 <b-row>
105 <b-col lg="6">
106 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +0530107 :label="$t('pageCertificates.modal.companyName')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700108 label-for="company-name"
109 >
110 <b-form-input
111 id="company-name"
112 v-model="form.companyName"
113 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +0530114 data-test-id="modalGenerateCsr-input-companyName"
Surya Vde23ea22024-07-11 15:19:46 +0530115 :state="getValidationState(v$.form.companyName)"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700116 />
117 <b-form-invalid-feedback role="alert">
118 {{ $t('global.form.fieldRequired') }}
119 </b-form-invalid-feedback>
120 </b-form-group>
121 </b-col>
122 <b-col lg="6">
123 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +0530124 :label="$t('pageCertificates.modal.companyUnit')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700125 label-for="company-unit"
126 >
127 <b-form-input
128 id="company-unit"
129 v-model="form.companyUnit"
130 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +0530131 data-test-id="modalGenerateCsr-input-companyUnit"
Surya Vde23ea22024-07-11 15:19:46 +0530132 :state="getValidationState(v$.form.companyUnit)"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700133 />
134 <b-form-invalid-feedback role="alert">
135 {{ $t('global.form.fieldRequired') }}
136 </b-form-invalid-feedback>
137 </b-form-group>
138 </b-col>
139 </b-row>
140 <b-row>
141 <b-col lg="6">
142 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +0530143 :label="$t('pageCertificates.modal.commonName')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700144 label-for="common-name"
145 >
146 <b-form-input
147 id="common-name"
148 v-model="form.commonName"
149 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +0530150 data-test-id="modalGenerateCsr-input-commonName"
Surya Vde23ea22024-07-11 15:19:46 +0530151 :state="getValidationState(v$.form.commonName)"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700152 />
153 <b-form-invalid-feedback role="alert">
154 {{ $t('global.form.fieldRequired') }}
155 </b-form-invalid-feedback>
156 </b-form-group>
157 </b-col>
158 <b-col lg="6">
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500159 <b-form-group label-for="contact-person">
Derick Montague602e98a2020-10-21 16:20:00 -0500160 <template #label>
jason westoverd36ac8a2025-11-03 20:58:59 -0600161 {{ $t('pageCertificates.modal.contactPerson') }}
162 -
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500163 <span class="form-text d-inline">
164 {{ $t('global.form.optional') }}
165 </span>
166 </template>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700167 <b-form-input
168 id="contact-person"
169 v-model="form.contactPerson"
170 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +0530171 data-test-id="modalGenerateCsr-input-contactPerson"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700172 />
173 </b-form-group>
174 </b-col>
Vedangi Mittaldfba4e52024-04-23 14:13:23 +0530175 </b-row>
176 <b-row>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700177 <b-col lg="6">
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500178 <b-form-group label-for="email-address">
Derick Montague602e98a2020-10-21 16:20:00 -0500179 <template #label>
jason westoverd36ac8a2025-11-03 20:58:59 -0600180 {{ $t('pageCertificates.modal.emailAddress') }}
181 -
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500182 <span class="form-text d-inline">
183 {{ $t('global.form.optional') }}
184 </span>
185 </template>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700186 <b-form-input
187 id="email-address"
188 v-model="form.emailAddress"
189 type="text"
SurenNewared0df7d22020-07-22 16:41:20 +0530190 data-test-id="modalGenerateCsr-input-emailAddress"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700191 />
192 </b-form-group>
193 </b-col>
194 </b-row>
195 <b-row>
196 <b-col lg="12">
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500197 <b-form-group label-for="alternate-name">
Derick Montague602e98a2020-10-21 16:20:00 -0500198 <template #label>
jason westoverd36ac8a2025-11-03 20:58:59 -0600199 {{ $t('pageCertificates.modal.alternateName') }}
200 -
Dixsie Wolmers46f17ef2020-09-08 14:53:25 -0500201 <span class="form-text d-inline">
202 {{ $t('global.form.optional') }}
203 </span>
204 </template>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700205 <b-form-text id="alternate-name-help-block">
Sandeepa Singhb4406162021-07-26 15:05:39 +0530206 {{ $t('pageCertificates.modal.alternateNameHelperText') }}
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700207 </b-form-text>
208 <b-form-tags
209 v-model="form.alternateName"
210 :remove-on-delete="true"
211 :tag-pills="true"
212 input-id="alternate-name"
213 size="lg"
214 separator=" "
215 :input-attrs="{
Derick Montague602e98a2020-10-21 16:20:00 -0500216 'aria-describedby': 'alternate-name-help-block',
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700217 }"
218 :duplicate-tag-text="
Sandeepa Singhb4406162021-07-26 15:05:39 +0530219 $t('pageCertificates.modal.duplicateAlternateName')
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700220 "
221 placeholder=""
Sandeepa Singh92f87552021-02-12 18:13:46 +0530222 data-test-id="modalGenerateCsr-input-alternateName"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700223 >
Derick Montague602e98a2020-10-21 16:20:00 -0500224 <template #add-button-text>
jason westoverd36ac8a2025-11-03 20:58:59 -0600225 <icon-add />
226 {{ $t('global.action.add') }}
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700227 </template>
228 </b-form-tags>
229 </b-form-group>
230 </b-col>
231 </b-row>
232 </b-col>
233 <b-col lg="3">
234 <b-row>
235 <b-col lg="12">
236 <p class="col-form-label">
Sandeepa Singhb4406162021-07-26 15:05:39 +0530237 {{ $t('pageCertificates.modal.privateKey') }}
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700238 </p>
239 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +0530240 :label="$t('pageCertificates.modal.keyPairAlgorithm')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700241 label-for="key-pair-algorithm"
242 >
243 <b-form-select
244 id="key-pair-algorithm"
245 v-model="form.keyPairAlgorithm"
SurenNewared0df7d22020-07-22 16:41:20 +0530246 data-test-id="modalGenerateCsr-select-keyPairAlgorithm"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700247 :options="keyPairAlgorithmOptions"
Surya Vde23ea22024-07-11 15:19:46 +0530248 :state="getValidationState(v$.form.keyPairAlgorithm)"
249 @input="v$.form.keyPairAlgorithm.$touch()"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700250 >
Derick Montague602e98a2020-10-21 16:20:00 -0500251 <template #first>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700252 <b-form-select-option :value="null" disabled>
253 {{ $t('global.form.selectAnOption') }}
254 </b-form-select-option>
255 </template>
256 </b-form-select>
257 <b-form-invalid-feedback role="alert">
258 {{ $t('global.form.fieldRequired') }}
259 </b-form-invalid-feedback>
260 </b-form-group>
261 </b-col>
262 </b-row>
263 <b-row>
264 <b-col lg="12">
Surya Vde23ea22024-07-11 15:19:46 +0530265 <template v-if="v$.form.keyPairAlgorithm.$model === 'EC'">
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700266 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +0530267 :label="$t('pageCertificates.modal.keyCurveId')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700268 label-for="key-curve-id"
269 >
270 <b-form-select
271 id="key-curve-id"
272 v-model="form.keyCurveId"
SurenNewared0df7d22020-07-22 16:41:20 +0530273 data-test-id="modalGenerateCsr-select-keyCurveId"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700274 :options="keyCurveIdOptions"
Surya Vde23ea22024-07-11 15:19:46 +0530275 :state="getValidationState(v$.form.keyCurveId)"
276 @input="v$.form.keyCurveId.$touch()"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700277 >
Derick Montague602e98a2020-10-21 16:20:00 -0500278 <template #first>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700279 <b-form-select-option :value="null" disabled>
280 {{ $t('global.form.selectAnOption') }}
281 </b-form-select-option>
282 </template>
283 </b-form-select>
284 <b-form-invalid-feedback role="alert">
285 {{ $t('global.form.fieldRequired') }}
286 </b-form-invalid-feedback>
287 </b-form-group>
288 </template>
Surya Vde23ea22024-07-11 15:19:46 +0530289 <template v-if="v$.form.keyPairAlgorithm.$model === 'RSA'">
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700290 <b-form-group
Sandeepa Singhb4406162021-07-26 15:05:39 +0530291 :label="$t('pageCertificates.modal.keyBitLength')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700292 label-for="key-bit-length"
293 >
294 <b-form-select
295 id="key-bit-length"
296 v-model="form.keyBitLength"
SurenNewared0df7d22020-07-22 16:41:20 +0530297 data-test-id="modalGenerateCsr-select-keyBitLength"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700298 :options="keyBitLengthOptions"
Surya Vde23ea22024-07-11 15:19:46 +0530299 :state="getValidationState(v$.form.keyBitLength)"
300 @input="v$.form.keyBitLength.$touch()"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700301 >
Derick Montague602e98a2020-10-21 16:20:00 -0500302 <template #first>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700303 <b-form-select-option :value="null" disabled>
304 {{ $t('global.form.selectAnOption') }}
305 </b-form-select-option>
306 </template>
307 </b-form-select>
308 <b-form-invalid-feedback role="alert">
309 {{ $t('global.form.fieldRequired') }}
310 </b-form-invalid-feedback>
311 </b-form-group>
312 </template>
313 </b-col>
314 </b-row>
315 </b-col>
316 </b-row>
317 </b-container>
318 </b-form>
jason westoverd36ac8a2025-11-03 20:58:59 -0600319 <template #footer="{ ok, cancel }">
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700320 <b-button variant="secondary" @click="cancel()">
321 {{ $t('global.action.cancel') }}
322 </b-button>
323 <b-button
324 form="generate-csr-form"
325 type="submit"
326 variant="primary"
SurenNewared0df7d22020-07-22 16:41:20 +0530327 data-test-id="modalGenerateCsr-button-ok"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700328 @click="ok()"
329 >
Sandeepa Singhb4406162021-07-26 15:05:39 +0530330 {{ $t('pageCertificates.generateCsr') }}
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700331 </b-button>
332 </template>
333 </b-modal>
334 <b-modal
335 id="csr-string"
jason westoverd36ac8a2025-11-03 20:58:59 -0600336 v-model="showCsrString"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700337 no-stacking
338 size="lg"
Sandeepa Singhb4406162021-07-26 15:05:39 +0530339 :title="$t('pageCertificates.modal.certificateSigningRequest')"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700340 @hidden="onHiddenCsrStringModal"
341 >
342 {{ csrString }}
jason westoverd36ac8a2025-11-03 20:58:59 -0600343 <template #footer>
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700344 <b-btn variant="secondary" @click="copyCsrString">
345 <template v-if="csrStringCopied">
346 <icon-checkmark />
347 {{ $t('global.status.copied') }}
348 </template>
349 <template v-else>
350 {{ $t('global.action.copy') }}
351 </template>
352 </b-btn>
353 <a
Sivaprabu Ganesanc72f1e32023-01-06 20:06:04 +0530354 :href="
355 `data:application/json;charset=utf-8,` +
356 encodeURIComponent(`${csrString}`)
357 "
358 download="certificate.csr"
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700359 class="btn btn-primary"
360 >
361 {{ $t('global.action.download') }}
362 </a>
363 </template>
364 </b-modal>
365 </div>
366</template>
367
368<script>
369import IconAdd from '@carbon/icons-vue/es/add--alt/20';
370import IconCheckmark from '@carbon/icons-vue/es/checkmark/20';
371
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700372import { required, requiredIf } from '@vuelidate/validators';
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700373
374import { COUNTRY_LIST } from './CsrCountryCodes';
SurenNeware61859092020-10-01 09:37:32 +0530375import BVToastMixin from '@/components/Mixins/BVToastMixin';
376import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700377import { useVuelidate } from '@vuelidate/core';
Surya Vde23ea22024-07-11 15:19:46 +0530378import { useI18n } from 'vue-i18n';
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700379
380export default {
381 name: 'ModalGenerateCsr',
382 components: { IconAdd, IconCheckmark },
383 mixins: [BVToastMixin, VuelidateMixin],
jason westoverd36ac8a2025-11-03 20:58:59 -0600384 props: {
385 modelValue: {
386 type: Boolean,
387 default: false,
388 },
389 },
390 emits: ['update:modelValue'],
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700391 setup() {
392 return {
393 v$: useVuelidate(),
394 };
395 },
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700396 data() {
397 return {
Surya Vde23ea22024-07-11 15:19:46 +0530398 $t: useI18n().t,
jason westoverd36ac8a2025-11-03 20:58:59 -0600399 showCsrString: false,
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700400 form: {
401 certificateType: null,
402 country: null,
403 state: null,
404 city: null,
405 companyName: null,
406 companyUnit: null,
407 commonName: null,
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700408 contactPerson: null,
409 emailAddress: null,
410 alternateName: [],
411 keyPairAlgorithm: null,
412 keyCurveId: null,
Derick Montague602e98a2020-10-21 16:20:00 -0500413 keyBitLength: null,
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700414 },
Derick Montague602e98a2020-10-21 16:20:00 -0500415 countryOptions: COUNTRY_LIST.map((country) => ({
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700416 text: country.label,
Derick Montague602e98a2020-10-21 16:20:00 -0500417 value: country.code,
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700418 })),
419 keyPairAlgorithmOptions: ['EC', 'RSA'],
420 keyCurveIdOptions: ['prime256v1', 'secp521r1', 'secp384r1'],
421 keyBitLengthOptions: [2048],
422 csrString: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500423 csrStringCopied: false,
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700424 };
425 },
Sean Zhang8841b7d2024-06-15 08:42:41 +0300426 computed: {
jason westoverd36ac8a2025-11-03 20:58:59 -0600427 isVisible: {
428 get() {
429 return this.modelValue;
430 },
431 set(value) {
432 this.$emit('update:modelValue', value);
433 },
434 },
Sean Zhang8841b7d2024-06-15 08:42:41 +0300435 certificateTypes() {
436 return this.$store.getters['certificates/certificateTypes'];
437 },
438 certificateOptions() {
439 return this.certificateTypes.reduce((arr, cert) => {
440 if (cert.type === 'TrustStore Certificate') return arr;
441 arr.push({
442 text: cert.label,
443 value: cert.type,
444 });
445 return arr;
446 }, []);
447 },
448 },
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700449 validations: {
450 form: {
451 certificateType: { required },
452 country: { required },
453 state: { required },
454 city: { required },
455 companyName: { required },
456 companyUnit: { required },
457 commonName: { required },
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700458 contactPerson: {},
459 emailAddress: {},
460 alternateName: {},
461 keyPairAlgorithm: { required },
462 keyCurveId: {
Derick Montague602e98a2020-10-21 16:20:00 -0500463 reuired: requiredIf(function (form) {
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700464 return form.keyPairAlgorithm === 'EC';
Derick Montague602e98a2020-10-21 16:20:00 -0500465 }),
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700466 },
467 keyBitLength: {
Derick Montague602e98a2020-10-21 16:20:00 -0500468 reuired: requiredIf(function (form) {
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700469 return form.keyPairAlgorithm === 'RSA';
Derick Montague602e98a2020-10-21 16:20:00 -0500470 }),
471 },
472 },
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700473 },
474 methods: {
475 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +0530476 this.v$.$touch();
477 if (this.v$.$invalid) return;
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700478 this.$store
Sandeepa Singhb4406162021-07-26 15:05:39 +0530479 .dispatch('certificates/generateCsr', this.form)
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700480 .then(({ data: { CSRString } }) => {
481 this.csrString = CSRString;
jason westoverd36ac8a2025-11-03 20:58:59 -0600482 this.showCsrString = true;
Surya Vde23ea22024-07-11 15:19:46 +0530483 this.v$.$reset();
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700484 });
485 },
486 resetForm() {
487 for (let key of Object.keys(this.form)) {
488 if (key === 'alternateName') {
489 this.form[key] = [];
490 } else {
491 this.form[key] = null;
492 }
493 }
494 },
495 onOkGenerateCsrModal(bvModalEvt) {
496 // prevent modal close
497 bvModalEvt.preventDefault();
498 this.handleSubmit();
499 },
500 onHiddenCsrStringModal() {
501 this.csrString = '';
502 this.resetForm();
503 },
504 copyCsrString(bvModalEvt) {
505 // prevent modal close
506 bvModalEvt.preventDefault();
507 navigator.clipboard.writeText(this.csrString).then(() => {
508 // Show copied text for 5 seconds
509 this.csrStringCopied = true;
510 setTimeout(() => {
511 this.csrStringCopied = false;
512 }, 5000 /*5 seconds*/);
513 });
Derick Montague602e98a2020-10-21 16:20:00 -0500514 },
515 },
Yoshie Muranaka532a4b02020-03-27 11:00:50 -0700516};
517</script>