chore: adding secret field extension

Signed-off-by: blam <ben@blam.sh>

Signed-off-by: blam <ben@blam.sh>
This commit is contained in:
blam
2023-11-11 13:47:38 +01:00
parent f52c4306ba
commit b60b2455d2
4 changed files with 73 additions and 0 deletions
@@ -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 (
<ScaffolderField
rawErrors={rawErrors}
rawDescription={description}
disabled={disabled}
errors={errors}
required={required}
>
<InputLabel htmlFor={title}>{title}</InputLabel>
<Input
id={title}
aria-describedby={`${title}-description`}
onChange={e => setSecrets({ [name]: e.target?.value })}
type="password"
/>
</ScaffolderField>
);
};
@@ -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';
@@ -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';
@@ -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',
},
];