From a14c084cad1c132087180e26d7843a84c7a7a687 Mon Sep 17 00:00:00 2001 From: Thomas Troschke Date: Thu, 8 Feb 2024 13:18:28 +0100 Subject: [PATCH] changed to older Gitbeaker version Signed-off-by: Thomas Troschke --- .../api-report.md | 1 + .../createGitlabProjectAccessTokenAction.ts | 24 ++++++++++--------- .../src/util.ts | 7 +----- yarn.lock | 4 ++-- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/plugins/scaffolder-backend-module-gitlab/api-report.md b/plugins/scaffolder-backend-module-gitlab/api-report.md index 94aabe9b72..f7ec2edac8 100644 --- a/plugins/scaffolder-backend-module-gitlab/api-report.md +++ b/plugins/scaffolder-backend-module-gitlab/api-report.md @@ -62,6 +62,7 @@ export const createGitlabProjectAccessTokenAction: (options: { name?: string | undefined; accessLevel?: number | undefined; scopes?: string[] | undefined; + expiresAt?: string | undefined; }, { access_token: string; diff --git a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectAccessTokenAction.ts b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectAccessTokenAction.ts index 4ee9375064..7de2dca011 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectAccessTokenAction.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/actions/createGitlabProjectAccessTokenAction.ts @@ -17,7 +17,6 @@ import { InputError } from '@backstage/errors'; import { ScmIntegrationRegistry } from '@backstage/integration'; import { createTemplateAction } from '@backstage/plugin-scaffolder-node'; -import { AccessTokenScopes } from '@gitbeaker/core'; import { Gitlab } from '@gitbeaker/rest'; import { DateTime } from 'luxon'; import { z } from 'zod'; @@ -31,8 +30,6 @@ import { examples } from './createGitlabProjectAccessTokenAction.examples'; * @public */ -const gitbeakerAccessTokenScopesType: z.ZodType = z.any(); - export const createGitlabProjectAccessTokenAction = (options: { integrations: ScmIntegrationRegistry; }) => { @@ -42,9 +39,14 @@ export const createGitlabProjectAccessTokenAction = (options: { examples, schema: { input: z.object({ - projectId: z.number({ + projectId: z.union([z.number(), z.string()], { description: 'Project ID/Name(slug) of the Gitlab Project', }), + token: z + .string({ + description: 'The token to use for authorization to GitLab', + }) + .optional(), name: z.string({ description: 'Name of Access Key' }).optional(), repoUrl: z.string({ description: 'URL to gitlab instance' }), accessLevel: z @@ -53,18 +55,18 @@ export const createGitlabProjectAccessTokenAction = (options: { 'Access Level of the Token, 10 (Guest), 20 (Reporter), 30 (Developer), 40 (Maintainer), and 50 (Owner)', }) .optional(), - scopes: gitbeakerAccessTokenScopesType, + scopes: z + .string({ + description: 'Scopes for a project access token', + }) + .array() + .optional(), expiresAt: z .string({ description: 'Expiration date of the access token in ISO format (YYYY-MM-DD). If Empty, it will set to the maximum of 365 days.', }) .optional(), - token: z - .string({ - description: 'The token to use for authorization to GitLab', - }) - .optional(), }), output: z.object({ access_token: z.string({ description: 'Access Token' }), @@ -107,7 +109,7 @@ export const createGitlabProjectAccessTokenAction = (options: { const response = await api.ProjectAccessTokens.create( projectId, name, - scopes, + scopes as any, { expiresAt: expiresAt || DateTime.now().plus({ days: 365 }).toISODate()!, diff --git a/plugins/scaffolder-backend-module-gitlab/src/util.ts b/plugins/scaffolder-backend-module-gitlab/src/util.ts index a4d819d490..d897604956 100644 --- a/plugins/scaffolder-backend-module-gitlab/src/util.ts +++ b/plugins/scaffolder-backend-module-gitlab/src/util.ts @@ -19,9 +19,9 @@ import { GitLabIntegration, ScmIntegrationRegistry, } from '@backstage/integration'; +import { Gitlab, GroupSchema } from '@gitbeaker/rest'; import { z } from 'zod'; import commonGitlabConfig from './commonGitlabConfig'; -import { Gitlab, GroupSchema } from '@gitbeaker/rest'; import * as util from './util'; export const parseRepoHost = (repoUrl: string): string => { @@ -50,11 +50,6 @@ export const getToken = ( } const token = config.token || integrationConfig.config.token!; - const tokenType = config.token ? 'oauthToken' : 'token'; - - if (tokenType === 'oauthToken') { - throw new InputError(`OAuth Token is currently not supported`); - } return { token: token, integrationConfig: integrationConfig }; }; diff --git a/yarn.lock b/yarn.lock index 92cba60d60..703e7debab 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8381,7 +8381,7 @@ __metadata: "@backstage/errors": "workspace:^" "@backstage/integration": "workspace:^" "@backstage/plugin-scaffolder-node": "workspace:^" - "@gitbeaker/core": ^39.25.0 + "@gitbeaker/core": ^35.8.0 "@gitbeaker/node": ^35.8.0 "@gitbeaker/rest": ^39.25.0 jest-date-mock: ^1.0.8 @@ -11260,7 +11260,7 @@ __metadata: languageName: node linkType: hard -"@gitbeaker/core@npm:^35.6.0, @gitbeaker/core@npm:^35.8.1": +"@gitbeaker/core@npm:^35.6.0, @gitbeaker/core@npm:^35.8.0, @gitbeaker/core@npm:^35.8.1": version: 35.8.1 resolution: "@gitbeaker/core@npm:35.8.1" dependencies: