diff --git a/plugins/scaffolder-backend/sample-templates/template.yaml b/plugins/scaffolder-backend/sample-templates/template.yaml index 6aad96b2e7..8d0ec0316f 100644 --- a/plugins/scaffolder-backend/sample-templates/template.yaml +++ b/plugins/scaffolder-backend/sample-templates/template.yaml @@ -6,14 +6,14 @@ metadata: spec: parameters: - title: Do something + required: + - myKey properties: myKey: title: My key description: asd type: string ui:field: Secret - ui:options: - required: true steps: [] type: service \ No newline at end of file diff --git a/plugins/scaffolder/src/components/fields/Secret/Secret.tsx b/plugins/scaffolder/src/components/fields/Secret/Secret.tsx index 59256c5c09..2933a405f1 100644 --- a/plugins/scaffolder/src/components/fields/Secret/Secret.tsx +++ b/plugins/scaffolder/src/components/fields/Secret/Secret.tsx @@ -27,6 +27,7 @@ export const Secret = (props: ScaffolderRJSFFieldProps) => { rawErrors, disabled, errors, + onChange, required, } = props; @@ -42,7 +43,18 @@ export const Secret = (props: ScaffolderRJSFFieldProps) => { setSecrets({ [name]: e.target?.value })} + onChange={e => { + // TODO(blam): this is a bit of a hack. We need to to probably figure out + // how to provide our own validator that can filter out the secrets from the + // jsonschema, or merge the secrets with the formData for validation? + // Makes the review step a little cleaner with this though. + onChange( + Array(e.target?.value.length ?? 0) + .fill('*') + .join(''), + ); + setSecrets({ [name]: e.target?.value }); + }} type="password" autoComplete="off" /> diff --git a/plugins/scaffolder/src/components/fields/Secret/index.tsx b/plugins/scaffolder/src/components/fields/Secret/index.tsx index 83d7576552..e28248ef7d 100644 --- a/plugins/scaffolder/src/components/fields/Secret/index.tsx +++ b/plugins/scaffolder/src/components/fields/Secret/index.tsx @@ -14,4 +14,3 @@ * limitations under the License. */ export * from './Secret'; -export * from './validation'; diff --git a/plugins/scaffolder/src/components/fields/Secret/validation.ts b/plugins/scaffolder/src/components/fields/Secret/validation.ts deleted file mode 100644 index e7cb6566e7..0000000000 --- a/plugins/scaffolder/src/components/fields/Secret/validation.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { CustomFieldValidator } from '@backstage/plugin-scaffolder-react'; - -/* - * Copyright 2023 The Backstage Authors - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -export const secretFieldValidation: CustomFieldValidator = ( - value, - errors, - { uiSchema }, -) => { - console.log(uiSchema); - if (uiSchema['ui:options'].required && !value) { - errors.addError('Required'); - } -}; diff --git a/plugins/scaffolder/src/extensions/default.ts b/plugins/scaffolder/src/extensions/default.ts index 24b70b6a0c..ef4a701e86 100644 --- a/plugins/scaffolder/src/extensions/default.ts +++ b/plugins/scaffolder/src/extensions/default.ts @@ -43,7 +43,7 @@ import { MyGroupsPicker, MyGroupsPickerSchema, } from '../components/fields/MyGroupsPicker/MyGroupsPicker'; -import { Secret, secretFieldValidation } from '../components'; +import { Secret } from '../components'; export const DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS = [ { @@ -86,6 +86,5 @@ export const DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS = [ { component: Secret, name: 'Secret', - validation: secretFieldValidation, }, ];