Skip to content

Commit

Permalink
use composable for shared secret data
Browse files Browse the repository at this point in the history
show secret data in edit mode
  • Loading branch information
grolu committed Nov 22, 2024
1 parent 8c08bd0 commit b4c0e22
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 160 deletions.
14 changes: 8 additions & 6 deletions frontend/src/components/Secrets/GSecretDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ import { useShootStore } from '@/store/shoot'
import GToolbar from '@/components/GToolbar.vue'
import GMessage from '@/components/GMessage'
import { useSecretDialogData } from '@/composables/useSecretDialogData'
import {
messageFromErrors,
withFieldName,
Expand All @@ -144,7 +146,6 @@ import {
import includes from 'lodash/includes'
import filter from 'lodash/filter'
import get from 'lodash/get'
import assign from 'lodash/assign'
export default {
components: {
Expand All @@ -157,10 +158,6 @@ export default {
type: Boolean,
required: true,
},
data: {
type: Object,
required: true,
},
secretValidations: {
// need to pass nested validation object which shares scope,
// as v$ is part of secretValidations but not vice versa
Expand Down Expand Up @@ -188,7 +185,11 @@ export default {
'cloud-profile-name',
],
setup () {
const { secretData, updateWithSecret } = useSecretDialogData()
return {
secretData,
updateWithSecret,
v$: useVuelidate(),
}
},
Expand Down Expand Up @@ -316,7 +317,7 @@ export default {
save () {
const credential = {
poviderType: this.providerType,
secretData: this.data,
secretData: this.secretData,
}
if (this.isCreateMode) {
return this.createCredential({ name: this.name, credential })
Expand All @@ -332,6 +333,7 @@ export default {
setDelayedInputFocus(this, 'name')
} else {
this.name = get(this.secretBinding, ['metadata', 'name'])
this.updateWithSecret(this.secretBinding.secretResource)
}
this.errorMessage = undefined
Expand Down
28 changes: 18 additions & 10 deletions frontend/src/components/Secrets/GSecretDialogAlicloud.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
<template>
<g-secret-dialog
v-model="visible"
:data="secretData"
:secret-validations="v$"
:secret-binding="secretBinding"
:provider-type="providerType"
Expand All @@ -17,7 +16,6 @@ SPDX-License-Identifier: Apache-2.0
<template #secret-slot>
<div>
<v-text-field
ref="accessKeyId"
v-model="accessKeyId"
color="primary"
label="Access Key Id"
Expand Down Expand Up @@ -100,11 +98,14 @@ import {
minLength,
maxLength,
} from '@vuelidate/validators'
import { ref } from 'vue'
import GSecretDialog from '@/components/Secrets/GSecretDialog'
import GCodeBlock from '@/components/GCodeBlock'
import GExternalLink from '@/components/GExternalLink'
import { useProvideSecretDialogData } from '@/composables/useSecretDialogData'
import { getErrorMessages } from '@/utils'
import { withFieldName } from '@/utils/validators'
Expand All @@ -130,14 +131,27 @@ export default {
'update:modelValue',
],
setup () {
const accessKeyId = ref(undefined)
const accessKeySecret = ref(undefined)
useProvideSecretDialogData({
data: {
accessKeyId,
accessKeySecret,
},
keyMapping: {
accessKeyId: 'accessKeyID',
},
})
return {
accessKeyId,
accessKeySecret,
v$: useVuelidate(),
}
},
data () {
return {
accessKeyId: undefined,
accessKeySecret: undefined,
hideSecret: true,
template: {
Statement: [
Expand Down Expand Up @@ -209,12 +223,6 @@ export default {
}
return undefined
},
secretData () {
return {
accessKeyID: this.accessKeyId,
accessKeySecret: this.accessKeySecret,
}
},
isCreateMode () {
return !this.secret
},
Expand Down
34 changes: 22 additions & 12 deletions frontend/src/components/Secrets/GSecretDialogAws.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
<template>
<g-secret-dialog
v-model="visible"
:data="secretData"
:secret-validations="v$"
:secret-binding="secretBinding"
:provider-type="providerType"
Expand All @@ -17,7 +16,6 @@ SPDX-License-Identifier: Apache-2.0
<template #secret-slot>
<div>
<v-text-field
ref="accessKeyId"
v-model="accessKeyId"
color="primary"
label="Access Key Id"
Expand Down Expand Up @@ -102,11 +100,14 @@ import {
minLength,
maxLength,
} from '@vuelidate/validators'
import { ref } from 'vue'
import GSecretDialog from '@/components/Secrets/GSecretDialog'
import GCodeBlock from '@/components/GCodeBlock'
import GExternalLink from '@/components/GExternalLink'
import { useProvideSecretDialogData } from '@/composables/useSecretDialogData'
import {
withFieldName,
alphaNumUnderscore,
Expand Down Expand Up @@ -136,15 +137,31 @@ export default {
'update:modelValue',
],
setup () {
const accessKeyId = ref(undefined)
const secretAccessKey = ref(undefined)
const awsRegion = ref(undefined)
useProvideSecretDialogData({
data: {
accessKeyId,
secretAccessKey,
awsRegion,
},
keyMapping: {
accessKeyId: 'accessKeyID',
awsRegion: 'AWS_REGION',
},
})
return {
accessKeyId,
secretAccessKey,
awsRegion,
v$: useVuelidate(),
}
},
data () {
return {
accessKeyId: undefined,
secretAccessKey: undefined,
awsRegion: undefined,
hideSecret: true,
templateAws: {
Version: '2012-10-17',
Expand Down Expand Up @@ -256,13 +273,6 @@ export default {
valid () {
return !this.v$.$invalid
},
secretData () {
return {
accessKeyID: this.accessKeyId,
secretAccessKey: this.secretAccessKey,
AWS_REGION: this.awsRegion,
}
},
isCreateMode () {
return !this.secret
},
Expand Down
59 changes: 39 additions & 20 deletions frontend/src/components/Secrets/GSecretDialogAzure.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
<template>
<g-secret-dialog
v-model="visible"
:data="secretData"
:secret-validations="v$"
:secret-binding="secretBinding"
:provider-type="providerType"
Expand All @@ -17,7 +16,6 @@ SPDX-License-Identifier: Apache-2.0
<template #secret-slot>
<div>
<v-text-field
ref="clientId"
v-model="clientId"
color="primary"
label="Client Id"
Expand Down Expand Up @@ -111,10 +109,16 @@ SPDX-License-Identifier: Apache-2.0
<script>
import { useVuelidate } from '@vuelidate/core'
import { required } from '@vuelidate/validators'
import {
ref,
computed,
} from 'vue'
import GSecretDialog from '@/components/Secrets/GSecretDialog'
import GExternalLink from '@/components/GExternalLink'
import { useProvideSecretDialogData } from '@/composables/useSecretDialogData'
import {
withFieldName,
guid,
Expand All @@ -141,19 +145,46 @@ export default {
emits: [
'update:modelValue',
],
setup () {
setup (props) {
const isDNSSecret = computed(() => {
return props.providerType === 'azure-dns' || props.providerType === 'azure-private-dns'
})
const clientId = ref(undefined)
const clientSecret = ref(undefined)
const tenantId = ref(undefined)
const subscriptionId = ref(undefined)
const azureCloud = ref(isDNSSecret.value ? 'AzurePublic' : undefined)
useProvideSecretDialogData({
data: {
clientId,
clientSecret,
tenantId,
subscriptionId,
azureCloud,
},
keyMapping: {
clientId: 'clientID',
subscriptionId: 'subscriptionID',
tenantId: 'tenantID',
azureCloud: 'AZURE_CLOUD',
},
})
return {
clientId,
clientSecret,
tenantId,
subscriptionId,
azureCloud,
isDNSSecret,
v$: useVuelidate(),
}
},
data () {
return {
clientId: undefined,
clientSecret: undefined,
tenantId: undefined,
subscriptionId: undefined,
hideSecret: true,
azureCloud: 'AzurePublic',
}
},
validations () {
Expand Down Expand Up @@ -187,15 +218,6 @@ export default {
valid () {
return !this.v$.$invalid
},
secretData () {
return {
clientID: this.clientId,
clientSecret: this.clientSecret,
subscriptionID: this.subscriptionId,
tenantID: this.tenantId,
AZURE_CLOUD: this.isDNSSecret ? this.azureCloud : undefined,
}
},
isCreateMode () {
return !this.secret
},
Expand All @@ -211,9 +233,6 @@ export default {
}
return undefined
},
isDNSSecret () {
return this.providerType === 'azure-dns' || this.providerType === 'azure-private-dns'
},
},
methods: {
getErrorMessages,
Expand Down
19 changes: 12 additions & 7 deletions frontend/src/components/Secrets/GSecretDialogCloudflare.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ SPDX-License-Identifier: Apache-2.0
<template>
<g-secret-dialog
v-model="visible"
:data="secretData"
:secret-validations="v$"
:secret-binding="secretBinding"
create-title="Add new Cloudflare Secret"
Expand Down Expand Up @@ -60,10 +59,13 @@ SPDX-License-Identifier: Apache-2.0
<script>
import { useVuelidate } from '@vuelidate/core'
import { required } from '@vuelidate/validators'
import { ref } from 'vue'
import GSecretDialog from '@/components/Secrets/GSecretDialog'
import GExternalLink from '@/components/GExternalLink'
import { useProvideSecretDialogData } from '@/composables/useSecretDialogData'
import { getErrorMessages } from '@/utils'
import { withFieldName } from '@/utils/validators'
Expand All @@ -85,13 +87,21 @@ export default {
'update:modelValue',
],
setup () {
const apiToken = ref(undefined)
useProvideSecretDialogData({
data: {
apiToken,
},
})
return {
apiToken,
v$: useVuelidate(),
}
},
data () {
return {
apiToken: undefined,
hideApiToken: true,
}
},
Expand All @@ -114,11 +124,6 @@ export default {
valid () {
return !this.v$.$invalid
},
secretData () {
return {
apiToken: this.apiToken,
}
},
isCreateMode () {
return !this.secret
},
Expand Down
Loading

0 comments on commit b4c0e22

Please sign in to comment.