Skip to content

Commit

Permalink
Remove username field; Take input of external authSecret (#717)
Browse files Browse the repository at this point in the history
Signed-off-by: SayedTahsin <[email protected]>
  • Loading branch information
SayedTahsin authored Jan 17, 2025
1 parent 954bb24 commit 900abc2
Show file tree
Hide file tree
Showing 40 changed files with 1,392 additions and 495 deletions.
17 changes: 14 additions & 3 deletions charts/kubedbcom-clickhouse-editor-options/ui/create-ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ steps:
createAuthSecret:
default: false
type: boolean
referSecret:
default: false
type: boolean
elements:
- elements:
- isArray: true
Expand Down Expand Up @@ -205,12 +208,20 @@ steps:
schema:
$ref: discriminator#/createAuthSecret
type: switch
- if: showAuthPasswordField
- if: showReferSecret
label:
text: labels.name
text: Refer existing Secret ?
onChange: onAuthChange
schema:
$ref: discriminator#/referSecret
type: switch
- fetch: getReferSecrets
if: showSecretDropdown
label:
text: Secret
schema:
$ref: schema#/properties/spec/properties/authSecret/properties/name
type: input
type: select
- if: showAuthPasswordField
label:
text: labels.password
Expand Down
117 changes: 56 additions & 61 deletions charts/kubedbcom-clickhouse-editor-options/ui/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,26 +315,12 @@ const modeDetails = {
},
}

function showAuthPasswordField({ discriminator, getValue, watchDependency }) {
const modelPathValue = getValue(discriminator, '/createAuthSecret')
watchDependency('discriminator#/createAuthSecret')
return !!modelPathValue
}

function isEqualToModelPathValue({ model, getValue, watchDependency }, value, modelPath) {
const modelPathValue = getValue(model, modelPath)
watchDependency('model#' + modelPath)
return modelPathValue === value
}

function showAuthSecretField({ discriminator, getValue, watchDependency }) {
return !showAuthPasswordField({
discriminator,
getValue,
watchDependency,
})
}

function showStorageSizeField({ model, getValue, watchDependency }) {
const modelPathValue = getValue(model, '/spec/mode')
watchDependency('model#/spec/mode')
Expand Down Expand Up @@ -433,37 +419,6 @@ function onCreateAuthSecretChange({ discriminator, getValue, commit }) {
}
}

async function getSecrets({ storeGet, axios, model, getValue, watchDependency }) {
const owner = storeGet('/route/params/user')
const cluster = storeGet('/route/params/cluster')
const namespace = getValue(model, '/metadata/release/namespace')
watchDependency('model#/metadata/release/namespace')

const resp = await axios.get(
`/clusters/${owner}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`,
{
params: {
filter: { items: { metadata: { name: null }, type: null } },
},
},
)

const secrets = (resp && resp.data && resp.data.items) || []

const filteredSecrets = secrets.filter((item) => {
const validType = ['kubernetes.io/service-account-token', 'Opaque']
return validType.includes(item.type)
})

filteredSecrets.map((item) => {
const name = (item.metadata && item.metadata.name) || ''
item.text = name
item.value = name
return true
})
return filteredSecrets
}

function getMachineListForOptions() {
const array = machineList.map((item) => {
return { text: item, value: item }
Expand Down Expand Up @@ -1085,20 +1040,17 @@ function showIssuer({ model, getValue, watchDependency, discriminator }) {
return isTlsEnabled && isIssuerToggleEnabled
}

function onAuthChange({ getValue, discriminator, commit }) {
const isAuthOn = getValue(discriminator, '/createAuthSecret')
if (!isAuthOn) {
commit('wizard/model$update', {
path: '/spec/authSecret/name',
value: '',
force: true,
})
commit('wizard/model$update', {
path: '/spec/authSecret/password',
value: '',
force: true,
})
}
function onAuthChange({ commit }) {
commit('wizard/model$update', {
path: '/spec/authSecret/name',
value: '',
force: true,
})
commit('wizard/model$update', {
path: '/spec/authSecret/password',
value: '',
force: true,
})
}
function setMonitoring({ getValue, model }) {
const agent = getValue(model, '/spec/admin/monitoring/agent') || ''
Expand Down Expand Up @@ -1174,7 +1126,52 @@ function isConfigAvailable({ getValue, model }) {
return val !== ''
}

async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) {
const referSecret = getValue(discriminator, '/referSecret')
if (!referSecret) {
return []
}

const params = storeGet('/route/params')
const { user, cluster } = params
const namespace = getValue(model, `/metadata/release/namespace`)
let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`

const options = []
try {
const resp = await axios.get(url)
const items = resp.data?.items
items.forEach((ele) => {
options.push(ele.metadata?.name)
})
} catch (e) {
console.log(e)
}
return options
}

function showAuthPasswordField({ discriminator, getValue, watchDependency }) {
const modelPathValue = getValue(discriminator, '/referSecret')
watchDependency('discriminator#/referSecret')
return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency })
}

function showSecretDropdown({ discriminator, getValue, watchDependency }) {
const modelPathValue = getValue(discriminator, '/referSecret')
watchDependency('discriminator#/referSecret')
return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency })
}

function showReferSecret({ discriminator, getValue, watchDependency }) {
const modelPathValue = getValue(discriminator, '/createAuthSecret')
watchDependency('discriminator#/createAuthSecret')
return !!modelPathValue
}

return {
showSecretDropdown,
showReferSecret,
getReferSecrets,
isConfigAvailable,
showAdditionalSettings,
returnFalse,
Expand Down Expand Up @@ -1202,12 +1199,10 @@ return {
fetchJsons,
showAuthPasswordField,
isEqualToModelPathValue,
showAuthSecretField,
showStorageSizeField,
getResources,
getMongoDbVersions,
onCreateAuthSecretChange,
getSecrets,
getMachineListForOptions,
setLimits,
setRequests,
Expand Down
17 changes: 14 additions & 3 deletions charts/kubedbcom-druid-editor-options/ui/create-ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,9 @@ steps:
metadataStorage:
default: {}
type: object
referSecret:
default: false
type: boolean
zookeeperRef:
default: {}
type: object
Expand Down Expand Up @@ -318,12 +321,20 @@ steps:
schema:
$ref: discriminator#/createAuthSecret
type: switch
- if: showAuthPasswordField
- if: showReferSecret
label:
text: labels.name
text: Refer existing Secret ?
onChange: onAuthChange
schema:
$ref: discriminator#/referSecret
type: switch
- fetch: getReferSecrets
if: showSecretDropdown
label:
text: Secret
schema:
$ref: schema#/properties/spec/properties/authSecret/properties/name
type: input
type: select
- if: showAuthPasswordField
label:
text: labels.password
Expand Down
76 changes: 56 additions & 20 deletions charts/kubedbcom-druid-editor-options/ui/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,12 +304,6 @@ const machineList = [
'db.r.24xlarge',
]

function showAuthPasswordField({ discriminator, getValue, watchDependency }) {
const modelPathValue = getValue(discriminator, '/createAuthSecret')
watchDependency('discriminator#/createAuthSecret')
return !!modelPathValue
}

async function getNamespaces({ axios, storeGet }) {
const params = storeGet('/route/params')
const { user, cluster, group, version, resource } = params
Expand Down Expand Up @@ -560,20 +554,17 @@ function setBackup({ model, getValue }) {
return backup === 'KubeStash' && features.includes('backup') && val
}

function onAuthChange({ getValue, discriminator, commit }) {
const isAuthOn = getValue(discriminator, '/createAuthSecret')
if (!isAuthOn) {
commit('wizard/model$update', {
path: '/spec/authSecret/name',
value: '',
force: true,
})
commit('wizard/model$update', {
path: '/spec/authSecret/password',
value: '',
force: true,
})
}
function onAuthChange({ commit }) {
commit('wizard/model$update', {
path: '/spec/authSecret/name',
value: '',
force: true,
})
commit('wizard/model$update', {
path: '/spec/authSecret/password',
value: '',
force: true,
})
}

function isConfigDatabaseOn({ watchDependency, discriminator, getValue }) {
Expand Down Expand Up @@ -964,7 +955,52 @@ function isConfigAvailable({ getValue, model }) {
return val !== ''
}

async function getReferSecrets({ getValue, model, storeGet, axios, discriminator }) {
const referSecret = getValue(discriminator, '/referSecret')
if (!referSecret) {
return []
}

const params = storeGet('/route/params')
const { user, cluster } = params
const namespace = getValue(model, `/metadata/release/namespace`)
let url = `/clusters/${user}/${cluster}/proxy/core/v1/namespaces/${namespace}/secrets`

const options = []
try {
const resp = await axios.get(url)
const items = resp.data?.items
items.forEach((ele) => {
options.push(ele.metadata?.name)
})
} catch (e) {
console.log(e)
}
return options
}

function showAuthPasswordField({ discriminator, getValue, watchDependency }) {
const modelPathValue = getValue(discriminator, '/referSecret')
watchDependency('discriminator#/referSecret')
return !modelPathValue && showReferSecret({ discriminator, getValue, watchDependency })
}

function showSecretDropdown({ discriminator, getValue, watchDependency }) {
const modelPathValue = getValue(discriminator, '/referSecret')
watchDependency('discriminator#/referSecret')
return !!modelPathValue && showReferSecret({ discriminator, getValue, watchDependency })
}

function showReferSecret({ discriminator, getValue, watchDependency }) {
const modelPathValue = getValue(discriminator, '/createAuthSecret')
watchDependency('discriminator#/createAuthSecret')
return !!modelPathValue
}

return {
showSecretDropdown,
showReferSecret,
getReferSecrets,
isConfigAvailable,
showAdditionalSettings,
returnFalse,
Expand Down
17 changes: 14 additions & 3 deletions charts/kubedbcom-elasticsearch-editor-options/ui/create-ui.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ steps:
createAuthSecret:
default: false
type: boolean
referSecret:
default: false
type: boolean
elements:
- elements:
- isArray: true
Expand Down Expand Up @@ -301,12 +304,20 @@ steps:
schema:
$ref: discriminator#/createAuthSecret
type: switch
- if: showAuthPasswordField
- if: showReferSecret
label:
text: labels.name
text: Refer existing Secret ?
onChange: onAuthChange
schema:
$ref: discriminator#/referSecret
type: switch
- fetch: getReferSecrets
if: showSecretDropdown
label:
text: Secret
schema:
$ref: schema#/properties/spec/properties/authSecret/properties/name
type: input
type: select
- if: showAuthPasswordField
label:
text: labels.password
Expand Down
Loading

0 comments on commit 900abc2

Please sign in to comment.