From da34ebee34dd04b2e2b1ba64fee142550d1e1a20 Mon Sep 17 00:00:00 2001 From: blam Date: Mon, 13 Nov 2023 11:14:52 +0100 Subject: [PATCH] wip Signed-off-by: blam Signed-off-by: blam --- .../sample-templates/all-templates.yaml | 1 + .../sample-templates/template.yaml | 19 +++++++++++++ .../src/components/fields/Secret/index.tsx | 1 + .../components/fields/Secret/validation.ts | 27 +++++++++++++++++++ plugins/scaffolder/src/extensions/default.ts | 3 ++- 5 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 plugins/scaffolder-backend/sample-templates/template.yaml create mode 100644 plugins/scaffolder/src/components/fields/Secret/validation.ts diff --git a/plugins/scaffolder-backend/sample-templates/all-templates.yaml b/plugins/scaffolder-backend/sample-templates/all-templates.yaml index 6637c9479b..fb2db2e608 100644 --- a/plugins/scaffolder-backend/sample-templates/all-templates.yaml +++ b/plugins/scaffolder-backend/sample-templates/all-templates.yaml @@ -6,6 +6,7 @@ metadata: spec: targets: - ./remote-templates.yaml + - ./template.yaml # For local development of a template, you can reference your local templates here. # Examples: # diff --git a/plugins/scaffolder-backend/sample-templates/template.yaml b/plugins/scaffolder-backend/sample-templates/template.yaml new file mode 100644 index 0000000000..6aad96b2e7 --- /dev/null +++ b/plugins/scaffolder-backend/sample-templates/template.yaml @@ -0,0 +1,19 @@ +apiVersion: scaffolder.backstage.io/v1beta3 +kind: Template +metadata: + name: test + title: Test template +spec: + parameters: + - title: Do something + 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/index.tsx b/plugins/scaffolder/src/components/fields/Secret/index.tsx index e28248ef7d..83d7576552 100644 --- a/plugins/scaffolder/src/components/fields/Secret/index.tsx +++ b/plugins/scaffolder/src/components/fields/Secret/index.tsx @@ -14,3 +14,4 @@ * 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 new file mode 100644 index 0000000000..e7cb6566e7 --- /dev/null +++ b/plugins/scaffolder/src/components/fields/Secret/validation.ts @@ -0,0 +1,27 @@ +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 ef4a701e86..24b70b6a0c 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 } from '../components'; +import { Secret, secretFieldValidation } from '../components'; export const DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS = [ { @@ -86,5 +86,6 @@ export const DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS = [ { component: Secret, name: 'Secret', + validation: secretFieldValidation, }, ];