Skip to content

Commit d52f590

Browse files
committed
fix(aws): applied scaffolder 2.0 zod migration
Signed-off-by: Florian JUDITH <florian.judith@alithya.com>
1 parent bf44bcd commit d52f590

9 files changed

Lines changed: 163 additions & 337 deletions

File tree

workspaces/aws/plugins/scaffolder-backend-module-aws-apps/src/actions/create-repo-access-token/create-repoAccesstoken.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,29 @@ import { parseRepoUrl } from '../../helpers/util';
77
import { InputError } from '@backstage/errors';
88
import { validate as validateArn } from '@aws-sdk/util-arn-parser';
99
import { putSecret } from '../../helpers/action-context';
10-
import { Config } from '@backstage/config';
10+
import { RootConfigService } from '@backstage/backend-plugin-api';
1111

1212
/** @public */
1313
export function createRepoAccessTokenAction(options: {
1414
integrations: ScmIntegrationRegistry;
15-
envConfig: Config;
15+
envConfig: RootConfigService;
1616
}) {
1717
const { integrations, envConfig } = options;
18-
return createTemplateAction<{
19-
repoUrl: string;
20-
secretArn: string;
21-
projectId: number;
22-
region?: string;
23-
}>({
18+
return createTemplateAction({
2419
id: 'opa:createRepoAccessToken:gitlab',
2520
description:
2621
'Initializes a git repository of the content in the workspace, and publishes it to GitLab.',
2722
schema: {
2823
input: {
29-
type: 'object',
30-
required: ['repoUrl', 'secretArn', 'projectId'],
31-
properties: {
32-
repoUrl: {
33-
title: 'Repository Location',
34-
type: 'string',
35-
},
36-
projectId: {
37-
title: 'Project Id',
38-
type: 'number',
39-
},
40-
secretArn: {
41-
title:
24+
repoUrl: z => z.string().describe('Repository Location'),
25+
projectId: z => z.number().describe('Project Id'),
26+
secretArn: z =>
27+
z
28+
.string()
29+
.describe(
4230
'Arn of the SecretsManager secret where the access token will be stored',
43-
type: 'string',
44-
},
45-
region: {
46-
title: 'AWS Region',
47-
type: 'string',
48-
},
49-
},
31+
),
32+
region: z => z.string().optional().describe('AWS Region'),
5033
},
5134
},
5235
async handler(ctx) {

workspaces/aws/plugins/scaffolder-backend-module-aws-apps/src/actions/create-s3-bucket/create-s3-bucket.ts

Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,34 @@ import { EnvironmentProvider } from '../../types';
77

88
/** @public */
99
export function createS3BucketAction() {
10-
return createTemplateAction<{
11-
bucketName: string;
12-
envProviders: EnvironmentProvider[];
13-
tags?: { Key: string; Value: string | number | boolean }[];
14-
}>({
10+
return createTemplateAction({
1511
id: 'opa:create-s3-bucket',
1612
description: 'Creates an S3 bucket',
1713
schema: {
1814
input: {
19-
type: 'object',
20-
required: ['bucketName', 'envProviders'],
21-
properties: {
22-
bucketName: {
23-
title: 'Bucket Name',
24-
description: 'The name of the S3 bucket to create',
25-
type: 'string',
26-
},
27-
envProviders: {
28-
title: 'AWS Environment Providers',
29-
description:
15+
bucketName: z =>
16+
z.string().describe('The name of the S3 bucket to create'),
17+
envProviders: z =>
18+
z
19+
.array(z.custom<EnvironmentProvider>())
20+
.describe(
3021
'The AWS environment providers containing account and region info',
31-
type: 'array',
32-
},
33-
tags: {
34-
title: 'AWS Tags',
35-
description:
22+
),
23+
tags: z =>
24+
z
25+
.array(
26+
z.object({
27+
Key: z.string(),
28+
Value: z.union([z.string(), z.number(), z.boolean()]),
29+
}),
30+
)
31+
.optional()
32+
.describe(
3633
'key/value pairs to apply as tags to any created AWS resources',
37-
type: 'array',
38-
minProperties: 1,
39-
items: [
40-
{
41-
type: 'object',
42-
properties: {
43-
Key: { type: 'string' },
44-
Value: { type: ['string', 'number', 'boolean'] },
45-
},
46-
},
47-
],
48-
},
49-
},
34+
),
5035
},
5136
output: {
52-
type: 'object',
53-
required: ['awsBucketName'],
54-
properties: {
55-
awsBucketName: {
56-
title: 'S3 Bucket Name',
57-
type: 'string',
58-
},
59-
},
37+
awsBucketName: z => z.string().describe('S3 Bucket Name'),
6038
},
6139
},
6240
async handler() {

workspaces/aws/plugins/scaffolder-backend-module-aws-apps/src/actions/create-secret/create-secret.ts

Lines changed: 30 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,66 +3,45 @@
33

44
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
55
import { createSecret } from '../../helpers/action-context';
6-
import { Config } from '@backstage/config';
6+
import { RootConfigService } from '@backstage/backend-plugin-api';
77

88
/** @public */
9-
export function createSecretAction(options: { envConfig: Config }) {
9+
export function createSecretAction(options: { envConfig: RootConfigService }) {
1010
const { envConfig } = options;
11-
return createTemplateAction<{
12-
secretName: string;
13-
description?: string;
14-
region?: string;
15-
tags?: { Key: string; Value: string | number | boolean }[];
16-
}>({
11+
return createTemplateAction({
1712
id: 'opa:create-secret',
1813
description: 'Creates secret in Secret Manager',
1914
schema: {
2015
input: {
21-
type: 'object',
22-
required: ['secretName'],
23-
properties: {
24-
secretName: {
25-
title: 'Secret Name',
26-
description: 'The name of the secret to create in SecretsManager',
27-
type: 'string',
28-
},
29-
description: {
30-
title: 'Description',
31-
description: 'An optional description of the secret',
32-
type: 'string',
33-
},
34-
region: {
35-
title: 'AWS Region',
36-
description:
37-
'The AWS region where the new secret should be created',
38-
type: 'string',
39-
},
40-
tags: {
41-
title: 'AWS Tags',
42-
description:
16+
secretName: z =>
17+
z
18+
.string()
19+
.describe('The name of the secret to create in SecretsManager'),
20+
description: z =>
21+
z
22+
.string()
23+
.optional()
24+
.describe('An optional description of the secret'),
25+
region: z =>
26+
z
27+
.string()
28+
.optional()
29+
.describe('The AWS region where the new secret should be created'),
30+
tags: z =>
31+
z
32+
.array(
33+
z.object({
34+
Key: z.string(),
35+
Value: z.union([z.string(), z.number(), z.boolean()]),
36+
}),
37+
)
38+
.optional()
39+
.describe(
4340
'key/value pairs to apply as tags to any created AWS resources',
44-
type: 'array',
45-
minProperties: 1,
46-
items: [
47-
{
48-
type: 'object',
49-
properties: {
50-
Key: { type: 'string' },
51-
Value: { type: ['string', 'number', 'boolean'] },
52-
},
53-
},
54-
],
55-
},
56-
},
41+
),
5742
},
5843
output: {
59-
type: 'object',
60-
properties: {
61-
secretARN: {
62-
title: 'SecretARN',
63-
type: 'string',
64-
},
65-
},
44+
secretARN: z => z.string().optional().describe('SecretARN'),
6645
},
6746
},
6847
async handler(ctx) {
@@ -83,7 +62,7 @@ export function createSecretAction(options: { envConfig: Config }) {
8362
tags,
8463
ctx.logger,
8564
);
86-
ctx.output('awsSecretArn', ARN!);
65+
ctx.output('secretARN', ARN!);
8766
} catch (e) {
8867
throw new Error(e instanceof Error ? e.message : JSON.stringify(e));
8968
}

workspaces/aws/plugins/scaffolder-backend-module-aws-apps/src/actions/get-component-info/get-component-info.ts

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,33 +27,17 @@ const examples = [
2727

2828
/** @public */
2929
export function getComponentInfoAction() {
30-
return createTemplateAction<{
31-
componentName: string;
32-
}>({
30+
return createTemplateAction({
3331
id: ID,
3432
description: 'Sets useful component info for other actions to use',
3533
examples,
3634
schema: {
3735
input: {
38-
type: 'object',
39-
required: ['componentName'],
40-
properties: {
41-
componentName: {
42-
title: 'Component Name',
43-
description: 'The name of the component',
44-
type: 'string',
45-
},
46-
},
36+
componentName: z => z.string().describe('The name of the component'),
4737
},
4838
output: {
49-
type: 'object',
50-
required: ['kebabCaseComponentName'],
51-
properties: {
52-
kebabCaseComponentName: {
53-
title: 'The component name, converted to kebab case',
54-
type: 'string',
55-
},
56-
},
39+
kebabCaseComponentName: z =>
40+
z.string().describe('The component name, converted to kebab case'),
5741
},
5842
},
5943
async handler(ctx) {

0 commit comments

Comments
 (0)