From b60b2455d2ade5ddea692a949b29d832e313d419 Mon Sep 17 00:00:00 2001 From: blam Date: Sat, 11 Nov 2023 13:47:38 +0100 Subject: [PATCH] chore: adding secret field extension Signed-off-by: blam Signed-off-by: blam --- .../src/components/fields/Secret/Secret.tsx | 50 +++++++++++++++++++ .../src/components/fields/Secret/index.tsx | 16 ++++++ .../scaffolder/src/components/fields/index.ts | 2 + plugins/scaffolder/src/extensions/default.ts | 5 ++ 4 files changed, 73 insertions(+) create mode 100644 plugins/scaffolder/src/components/fields/Secret/Secret.tsx create mode 100644 plugins/scaffolder/src/components/fields/Secret/index.tsx diff --git a/plugins/scaffolder/src/components/fields/Secret/Secret.tsx b/plugins/scaffolder/src/components/fields/Secret/Secret.tsx new file mode 100644 index 0000000000..bdd862f8ce --- /dev/null +++ b/plugins/scaffolder/src/components/fields/Secret/Secret.tsx @@ -0,0 +1,50 @@ +/* + * 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. + */ +import React from 'react'; +import { useTemplateSecrets } from '@backstage/plugin-scaffolder-react'; +import { ScaffolderRJSFFieldProps } from '@backstage/plugin-scaffolder-react'; +import { ScaffolderField } from '@backstage/plugin-scaffolder-react/alpha'; +import { Input, InputLabel } from '@material-ui/core'; + +export const Secret = (props: ScaffolderRJSFFieldProps) => { + const { setSecrets } = useTemplateSecrets(); + const { + name, + schema: { title, description }, + rawErrors, + disabled, + errors, + required, + } = props; + + return ( + + {title} + setSecrets({ [name]: e.target?.value })} + type="password" + /> + + ); +}; diff --git a/plugins/scaffolder/src/components/fields/Secret/index.tsx b/plugins/scaffolder/src/components/fields/Secret/index.tsx new file mode 100644 index 0000000000..e28248ef7d --- /dev/null +++ b/plugins/scaffolder/src/components/fields/Secret/index.tsx @@ -0,0 +1,16 @@ +/* + * 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 * from './Secret'; diff --git a/plugins/scaffolder/src/components/fields/index.ts b/plugins/scaffolder/src/components/fields/index.ts index 7ee4448f6b..e29a4d791c 100644 --- a/plugins/scaffolder/src/components/fields/index.ts +++ b/plugins/scaffolder/src/components/fields/index.ts @@ -19,4 +19,6 @@ export * from './RepoUrlPicker'; export * from './OwnedEntityPicker'; export * from './EntityTagsPicker'; export * from './MyGroupsPicker'; +export * from './Secret'; + export { type FieldSchema, makeFieldSchemaFromZod } from './utils'; diff --git a/plugins/scaffolder/src/extensions/default.ts b/plugins/scaffolder/src/extensions/default.ts index 013f242a12..ef4a701e86 100644 --- a/plugins/scaffolder/src/extensions/default.ts +++ b/plugins/scaffolder/src/extensions/default.ts @@ -43,6 +43,7 @@ import { MyGroupsPicker, MyGroupsPickerSchema, } from '../components/fields/MyGroupsPicker/MyGroupsPicker'; +import { Secret } from '../components'; export const DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS = [ { @@ -82,4 +83,8 @@ export const DEFAULT_SCAFFOLDER_FIELD_EXTENSIONS = [ name: 'MyGroupsPicker', schema: MyGroupsPickerSchema, }, + { + component: Secret, + name: 'Secret', + }, ];