@backstage/plugin-scaffolder-backend-module-gitlab 0.2.0-next.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # @backstage/plugin-scaffolder-backend-module-gitlab
2
2
 
3
+ ## 0.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 439e2986be1: Add a new scaffolder action for gitlab to ensure a group exists
8
+
9
+ ### Patch Changes
10
+
11
+ - f1496d4ab6f: Fix input schema validation issue for gitlab actions:
12
+
13
+ - gitlab:group:ensureExists
14
+ - gitlab:projectAccessToken:create
15
+ - gitlab:projectDeployToken:create
16
+ - gitlab:projectVariable:create
17
+
18
+ - Updated dependencies
19
+ - @backstage/integration@1.4.5
20
+ - @backstage/plugin-scaffolder-node@0.1.3
21
+ - @backstage/config@1.0.7
22
+ - @backstage/errors@1.1.5
23
+
3
24
  ## 0.2.0-next.2
4
25
 
5
26
  ### Minor Changes
package/dist/index.cjs.js CHANGED
@@ -45,7 +45,7 @@ const createGitlabGroupEnsureExistsAction = (options) => {
45
45
  id: "gitlab:group:ensureExists",
46
46
  description: "Ensures a Gitlab group exists",
47
47
  schema: {
48
- input: commonGitlabConfig.and(
48
+ input: commonGitlabConfig.merge(
49
49
  zod.z.object({
50
50
  path: zod.z.array(zod.z.string(), {
51
51
  description: "A path of group names that is ensured to exist"
@@ -99,7 +99,7 @@ const createGitlabProjectDeployTokenAction = (options) => {
99
99
  return pluginScaffolderNode.createTemplateAction({
100
100
  id: "gitlab:projectDeployToken:create",
101
101
  schema: {
102
- input: commonGitlabConfig.and(
102
+ input: commonGitlabConfig.merge(
103
103
  zod.z.object({
104
104
  projectId: zod.z.union([zod.z.number(), zod.z.string()], {
105
105
  description: "Project ID"
@@ -144,7 +144,7 @@ const createGitlabProjectAccessTokenAction = (options) => {
144
144
  return pluginScaffolderNode.createTemplateAction({
145
145
  id: "gitlab:projectAccessToken:create",
146
146
  schema: {
147
- input: commonGitlabConfig.and(
147
+ input: commonGitlabConfig.merge(
148
148
  zod.z.object({
149
149
  projectId: zod.z.union([zod.z.number(), zod.z.string()], {
150
150
  description: "Project ID"
@@ -189,7 +189,7 @@ const createGitlabProjectVariableAction = (options) => {
189
189
  return pluginScaffolderNode.createTemplateAction({
190
190
  id: "gitlab:projectVariable:create",
191
191
  schema: {
192
- input: commonGitlabConfig.and(
192
+ input: commonGitlabConfig.merge(
193
193
  zod.z.object({
194
194
  projectId: zod.z.union([zod.z.number(), zod.z.string()], {
195
195
  description: "Project ID"
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs.js","sources":["../src/commonGitlabConfig.ts","../src/util.ts","../src/actions/createGitlabGroupEnsureExistsAction.ts","../src/actions/createGitlabProjectDeployTokenAction.ts","../src/actions/createGitlabProjectAccessTokenAction.ts","../src/actions/createGitlabProjectVariableAction.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { z } from 'zod';\n\nconst commonGitlabConfig = z.object({\n repoUrl: z.string({ description: 'Repository Location' }),\n token: z\n .string({ description: 'The token to use for authorization to GitLab' })\n .optional(),\n});\n\nexport default commonGitlabConfig;\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n GitLabIntegration,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { z } from 'zod';\nimport commonGitlabConfig from './commonGitlabConfig';\n\nexport const parseRepoHost = (repoUrl: string): string => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n return parsed.host;\n};\n\nexport const getToken = (\n config: z.infer<typeof commonGitlabConfig>,\n integrations: ScmIntegrationRegistry,\n): { token: string; integrationConfig: GitLabIntegration } => {\n const host = parseRepoHost(config.repoUrl);\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const token = config.token || integrationConfig.config.token!;\n const tokenType = config.token ? 'oauthToken' : 'token';\n\n if (tokenType === 'oauthToken') {\n throw new InputError(`OAuth Token is currently not supported`);\n }\n\n return { token: token, integrationConfig: integrationConfig };\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { Gitlab } from '@gitbeaker/node';\nimport { GroupSchema } from '@gitbeaker/core/dist/types/resources/Groups';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { getToken } from '../util';\nimport { z } from 'zod';\n\n/**\n * Creates an `gitlab:group:ensureExists` Scaffolder action.\n *\n * @public\n */\nexport const createGitlabGroupEnsureExistsAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction({\n id: 'gitlab:group:ensureExists',\n description: 'Ensures a Gitlab group exists',\n schema: {\n input: commonGitlabConfig.and(\n z.object({\n path: z\n .array(z.string(), {\n description: 'A path of group names that is ensured to exist',\n })\n .min(1),\n }),\n ),\n output: z.object({\n groupId: z\n .number({ description: 'The id of the innermost sub-group' })\n .optional(),\n }),\n },\n async handler(ctx) {\n const { path } = ctx.input;\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n const api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: token,\n });\n\n let currentPath: string = 'repos';\n let parent: GroupSchema | null = null;\n for (const pathElement of path) {\n const fullPath = `${currentPath}/${pathElement}`;\n const result = (await api.Groups.search(\n fullPath,\n )) as any as Array<GroupSchema>; // recast since the return type for search is wrong in the gitbeaker typings\n const subGroup = result.find(\n searchPathElem => searchPathElem.full_path === fullPath,\n );\n if (!subGroup) {\n ctx.logger.info(`creating missing group ${fullPath}`);\n parent = await api.Groups.create(\n pathElement,\n pathElement,\n parent\n ? {\n parent_id: parent.id,\n }\n : {},\n );\n } else {\n parent = subGroup;\n }\n currentPath = fullPath;\n }\n if (parent !== null) {\n ctx.output('groupId', parent?.id);\n }\n },\n });\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { Gitlab } from '@gitbeaker/node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { DeployTokenScope } from '@gitbeaker/core/dist/types/templates/ResourceDeployTokens';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { getToken } from '../util';\nimport { InputError } from '@backstage/errors';\nimport { z } from 'zod';\n\n/**\n * Creates a `gitlab:projectDeployToken:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabProjectDeployTokenAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectDeployToken:create',\n schema: {\n input: commonGitlabConfig.and(\n z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n name: z.string({ description: 'Deploy Token Name' }),\n username: z\n .string({ description: 'Deploy Token Username' })\n .optional(),\n scopes: z.array(z.string(), { description: 'Scopes' }).optional(),\n }),\n ),\n output: z.object({\n deploy_token: z.string({ description: 'Deploy Token' }),\n user: z.string({ description: 'User' }),\n }),\n },\n async handler(ctx) {\n ctx.logger.info(`Creating Token for Project \"${ctx.input.projectId}\"`);\n const { projectId, name, username, scopes } = ctx.input;\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n const api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: token,\n });\n\n const deployToken = await api.ProjectDeployTokens.add(\n projectId,\n name,\n scopes as DeployTokenScope[],\n {\n username: username,\n },\n );\n\n if (!deployToken.hasOwnProperty('token')) {\n throw new InputError(`No deploy_token given from gitlab instance`);\n }\n\n ctx.output('deploy_token', deployToken.token as string);\n ctx.output('user', deployToken.username);\n },\n });\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { getToken } from '../util';\nimport { z } from 'zod';\n\n/**\n * Creates a `gitlab:projectAccessToken:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabProjectAccessTokenAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectAccessToken:create',\n schema: {\n input: commonGitlabConfig.and(\n z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n name: z.string({ description: 'Deploy Token Name' }).optional(),\n accessLevel: z\n .number({ description: 'Access Level of the Token' })\n .optional(),\n scopes: z.array(z.string(), { description: 'Scopes' }).optional(),\n }),\n ),\n output: z.object({\n access_token: z.string({ description: 'Access Token' }),\n }),\n },\n async handler(ctx) {\n ctx.logger.info(`Creating Token for Project \"${ctx.input.projectId}\"`);\n const { projectId, name, accessLevel, scopes } = ctx.input;\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n const response = await fetch(\n `${integrationConfig.config.baseUrl}/api/v4/projects/${projectId}/access_tokens`,\n {\n method: 'POST', // *GET, POST, PUT, DELETE, etc.\n headers: {\n 'PRIVATE-TOKEN': token,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n name: name,\n scopes: scopes,\n access_level: accessLevel,\n }),\n },\n );\n\n const result = await response.json();\n\n ctx.output('access_token', result.token);\n },\n });\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { Gitlab } from '@gitbeaker/node';\nimport { getToken } from '../util';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { z } from 'zod';\n\n/**\n * Creates a `gitlab:projectVariable:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabProjectVariableAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectVariable:create',\n schema: {\n input: commonGitlabConfig.and(\n z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n key: z\n .string({\n description:\n 'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed',\n })\n .regex(/^[A-Za-z0-9_]{1,255}$/),\n value: z.string({ description: 'The value of a variable' }),\n variableType: z.string({\n description: 'Variable Type (env_var or file)',\n }),\n variableProtected: z\n .boolean({ description: 'Whether the variable is protected' })\n .default(false)\n .optional(),\n masked: z\n .boolean({ description: 'Whether the variable is masked' })\n .default(false)\n .optional(),\n raw: z\n .boolean({ description: 'Whether the variable is expandable' })\n .default(false)\n .optional(),\n environmentScope: z\n .string({ description: 'The environment_scope of the variable' })\n .default('*')\n .optional(),\n }),\n ),\n },\n async handler(ctx) {\n const {\n projectId,\n key,\n value,\n variableType,\n variableProtected = false,\n masked = false,\n raw = false,\n environmentScope = '*',\n } = ctx.input;\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n const api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: token,\n });\n\n await api.ProjectVariables.create(projectId, {\n key: key,\n value: value,\n variable_type: variableType,\n protected: variableProtected,\n masked: masked,\n raw: raw,\n environment_scope: environmentScope,\n });\n },\n });\n};\n"],"names":["z","InputError","createTemplateAction","Gitlab"],"mappings":";;;;;;;;;AAkBA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AA,QACA,YAAA;AAAA,QACA,iBAAoB,GAAA,KAAA;AAAA,QACpB,MAAS,GAAA,KAAA;AAAA,QACT,GAAM,GAAA,KAAA;AAAA,QACN,gBAAmB,GAAA,GAAA;AAAA,UACjB,GAAI,CAAA,KAAA,CAAA;AACR,MAAA,MAAM,EAAE,KAAO,EAAA,iBAAA,KAAsB,QAAS,CAAA,GAAA,CAAI,OAAO,YAAY,CAAA,CAAA;AAErE,MAAM,MAAA,GAAA,GAAM,IAAIG,WAAO,CAAA;AAAA,QACrB,IAAA,EAAM,kBAAkB,MAAO,CAAA,OAAA;AAAA,QAC/B,KAAA;AAAA,OACD,CAAA,CAAA;AAED,MAAM,MAAA,GAAA,CAAI,gBAAiB,CAAA,MAAA,CAAO,SAAW,EAAA;AAAA,QAC3C,GAAA;AAAA,QACA,KAAA;AAAA,QACA,aAAe,EAAA,YAAA;AAAA,QACf,SAAW,EAAA,iBAAA;AAAA,QACX,MAAA;AAAA,QACA,GAAA;AAAA,QACA,iBAAmB,EAAA,gBAAA;AAAA,OACpB,CAAA,CAAA;AAAA,KACH;AAAA,GACD,CAAA,CAAA;AACH;;;;;;;"}
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/commonGitlabConfig.ts","../src/util.ts","../src/actions/createGitlabGroupEnsureExistsAction.ts","../src/actions/createGitlabProjectDeployTokenAction.ts","../src/actions/createGitlabProjectAccessTokenAction.ts","../src/actions/createGitlabProjectVariableAction.ts"],"sourcesContent":["/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { z } from 'zod';\n\nconst commonGitlabConfig = z.object({\n repoUrl: z.string({ description: 'Repository Location' }),\n token: z\n .string({ description: 'The token to use for authorization to GitLab' })\n .optional(),\n});\n\nexport default commonGitlabConfig;\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { InputError } from '@backstage/errors';\nimport {\n GitLabIntegration,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\nimport { z } from 'zod';\nimport commonGitlabConfig from './commonGitlabConfig';\n\nexport const parseRepoHost = (repoUrl: string): string => {\n let parsed;\n try {\n parsed = new URL(`https://${repoUrl}`);\n } catch (error) {\n throw new InputError(\n `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`,\n );\n }\n return parsed.host;\n};\n\nexport const getToken = (\n config: z.infer<typeof commonGitlabConfig>,\n integrations: ScmIntegrationRegistry,\n): { token: string; integrationConfig: GitLabIntegration } => {\n const host = parseRepoHost(config.repoUrl);\n const integrationConfig = integrations.gitlab.byHost(host);\n\n if (!integrationConfig) {\n throw new InputError(\n `No matching integration configuration for host ${host}, please check your integrations config`,\n );\n }\n\n const token = config.token || integrationConfig.config.token!;\n const tokenType = config.token ? 'oauthToken' : 'token';\n\n if (tokenType === 'oauthToken') {\n throw new InputError(`OAuth Token is currently not supported`);\n }\n\n return { token: token, integrationConfig: integrationConfig };\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { Gitlab } from '@gitbeaker/node';\nimport { GroupSchema } from '@gitbeaker/core/dist/types/resources/Groups';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { getToken } from '../util';\nimport { z } from 'zod';\n\n/**\n * Creates an `gitlab:group:ensureExists` Scaffolder action.\n *\n * @public\n */\nexport const createGitlabGroupEnsureExistsAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n\n return createTemplateAction({\n id: 'gitlab:group:ensureExists',\n description: 'Ensures a Gitlab group exists',\n schema: {\n input: commonGitlabConfig.merge(\n z.object({\n path: z\n .array(z.string(), {\n description: 'A path of group names that is ensured to exist',\n })\n .min(1),\n }),\n ),\n output: z.object({\n groupId: z\n .number({ description: 'The id of the innermost sub-group' })\n .optional(),\n }),\n },\n async handler(ctx) {\n const { path } = ctx.input;\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n const api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: token,\n });\n\n let currentPath: string = 'repos';\n let parent: GroupSchema | null = null;\n for (const pathElement of path) {\n const fullPath = `${currentPath}/${pathElement}`;\n const result = (await api.Groups.search(\n fullPath,\n )) as any as Array<GroupSchema>; // recast since the return type for search is wrong in the gitbeaker typings\n const subGroup = result.find(\n searchPathElem => searchPathElem.full_path === fullPath,\n );\n if (!subGroup) {\n ctx.logger.info(`creating missing group ${fullPath}`);\n parent = await api.Groups.create(\n pathElement,\n pathElement,\n parent\n ? {\n parent_id: parent.id,\n }\n : {},\n );\n } else {\n parent = subGroup;\n }\n currentPath = fullPath;\n }\n if (parent !== null) {\n ctx.output('groupId', parent?.id);\n }\n },\n });\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { Gitlab } from '@gitbeaker/node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { DeployTokenScope } from '@gitbeaker/core/dist/types/templates/ResourceDeployTokens';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { getToken } from '../util';\nimport { InputError } from '@backstage/errors';\nimport { z } from 'zod';\n\n/**\n * Creates a `gitlab:projectDeployToken:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabProjectDeployTokenAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectDeployToken:create',\n schema: {\n input: commonGitlabConfig.merge(\n z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n name: z.string({ description: 'Deploy Token Name' }),\n username: z\n .string({ description: 'Deploy Token Username' })\n .optional(),\n scopes: z.array(z.string(), { description: 'Scopes' }).optional(),\n }),\n ),\n output: z.object({\n deploy_token: z.string({ description: 'Deploy Token' }),\n user: z.string({ description: 'User' }),\n }),\n },\n async handler(ctx) {\n ctx.logger.info(`Creating Token for Project \"${ctx.input.projectId}\"`);\n const { projectId, name, username, scopes } = ctx.input;\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n const api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: token,\n });\n\n const deployToken = await api.ProjectDeployTokens.add(\n projectId,\n name,\n scopes as DeployTokenScope[],\n {\n username: username,\n },\n );\n\n if (!deployToken.hasOwnProperty('token')) {\n throw new InputError(`No deploy_token given from gitlab instance`);\n }\n\n ctx.output('deploy_token', deployToken.token as string);\n ctx.output('user', deployToken.username);\n },\n });\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { getToken } from '../util';\nimport { z } from 'zod';\n\n/**\n * Creates a `gitlab:projectAccessToken:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabProjectAccessTokenAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectAccessToken:create',\n schema: {\n input: commonGitlabConfig.merge(\n z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n name: z.string({ description: 'Deploy Token Name' }).optional(),\n accessLevel: z\n .number({ description: 'Access Level of the Token' })\n .optional(),\n scopes: z.array(z.string(), { description: 'Scopes' }).optional(),\n }),\n ),\n output: z.object({\n access_token: z.string({ description: 'Access Token' }),\n }),\n },\n async handler(ctx) {\n ctx.logger.info(`Creating Token for Project \"${ctx.input.projectId}\"`);\n const { projectId, name, accessLevel, scopes } = ctx.input;\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n const response = await fetch(\n `${integrationConfig.config.baseUrl}/api/v4/projects/${projectId}/access_tokens`,\n {\n method: 'POST', // *GET, POST, PUT, DELETE, etc.\n headers: {\n 'PRIVATE-TOKEN': token,\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n name: name,\n scopes: scopes,\n access_level: accessLevel,\n }),\n },\n );\n\n const result = await response.json();\n\n ctx.output('access_token', result.token);\n },\n });\n};\n","/*\n * Copyright 2021 The Backstage Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createTemplateAction } from '@backstage/plugin-scaffolder-node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { Gitlab } from '@gitbeaker/node';\nimport { getToken } from '../util';\nimport commonGitlabConfig from '../commonGitlabConfig';\nimport { z } from 'zod';\n\n/**\n * Creates a `gitlab:projectVariable:create` Scaffolder action.\n *\n * @param options - Templating configuration.\n * @public\n */\nexport const createGitlabProjectVariableAction = (options: {\n integrations: ScmIntegrationRegistry;\n}) => {\n const { integrations } = options;\n return createTemplateAction({\n id: 'gitlab:projectVariable:create',\n schema: {\n input: commonGitlabConfig.merge(\n z.object({\n projectId: z.union([z.number(), z.string()], {\n description: 'Project ID',\n }),\n key: z\n .string({\n description:\n 'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed',\n })\n .regex(/^[A-Za-z0-9_]{1,255}$/),\n value: z.string({ description: 'The value of a variable' }),\n variableType: z.string({\n description: 'Variable Type (env_var or file)',\n }),\n variableProtected: z\n .boolean({ description: 'Whether the variable is protected' })\n .default(false)\n .optional(),\n masked: z\n .boolean({ description: 'Whether the variable is masked' })\n .default(false)\n .optional(),\n raw: z\n .boolean({ description: 'Whether the variable is expandable' })\n .default(false)\n .optional(),\n environmentScope: z\n .string({ description: 'The environment_scope of the variable' })\n .default('*')\n .optional(),\n }),\n ),\n },\n async handler(ctx) {\n const {\n projectId,\n key,\n value,\n variableType,\n variableProtected = false,\n masked = false,\n raw = false,\n environmentScope = '*',\n } = ctx.input;\n const { token, integrationConfig } = getToken(ctx.input, integrations);\n\n const api = new Gitlab({\n host: integrationConfig.config.baseUrl,\n token: token,\n });\n\n await api.ProjectVariables.create(projectId, {\n key: key,\n value: value,\n variable_type: variableType,\n protected: variableProtected,\n masked: masked,\n raw: raw,\n environment_scope: environmentScope,\n });\n },\n });\n};\n"],"names":["z","InputError","createTemplateAction","Gitlab"],"mappings":";;;;;;;;;AAkBA,MAAM,kBAAA,GAAqBA,MAAE,MAAO,CAAA;AAAA,EAClC,SAASA,KAAE,CAAA,MAAA,CAAO,EAAE,WAAA,EAAa,uBAAuB,CAAA;AAAA,EACxD,KAAA,EAAOA,MACJ,MAAO,CAAA,EAAE,aAAa,8CAA+C,EAAC,EACtE,QAAS,EAAA;AACd,CAAC,CAAA;;ACCY,MAAA,aAAA,GAAgB,CAAC,OAA4B,KAAA;AACxD,EAAI,IAAA,MAAA,CAAA;AACJ,EAAI,IAAA;AACF,IAAS,MAAA,GAAA,IAAI,GAAI,CAAA,CAAA,QAAA,EAAW,OAAS,CAAA,CAAA,CAAA,CAAA;AAAA,WAC9B,KAAP,EAAA;AACA,IAAA,MAAM,IAAIC,iBAAA;AAAA,MACR,6CAA6C,OAAY,CAAA,EAAA,EAAA,KAAA,CAAA,CAAA;AAAA,KAC3D,CAAA;AAAA,GACF;AACA,EAAA,OAAO,MAAO,CAAA,IAAA,CAAA;AAChB,CAAA,CAAA;AAEa,MAAA,QAAA,GAAW,CACtB,MAAA,EACA,YAC4D,KAAA;AAC5D,EAAM,MAAA,IAAA,GAAO,aAAc,CAAA,MAAA,CAAO,OAAO,CAAA,CAAA;AACzC,EAAA,MAAM,iBAAoB,GAAA,YAAA,CAAa,MAAO,CAAA,MAAA,CAAO,IAAI,CAAA,CAAA;AAEzD,EAAA,IAAI,CAAC,iBAAmB,EAAA;AACtB,IAAA,MAAM,IAAIA,iBAAA;AAAA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AA,OAAA,CAAQ,KAAK,CAAA,CACb,QAAS,EAAA;AAAA,UACZ,gBAAA,EAAkBA,KACf,CAAA,MAAA,CAAO,EAAE,WAAA,EAAa,uCAAwC,EAAC,CAC/D,CAAA,OAAA,CAAQ,GAAG,CAAA,CACX,QAAS,EAAA;AAAA,SACb,CAAA;AAAA,OACH;AAAA,KACF;AAAA,IACA,MAAM,QAAQ,GAAK,EAAA;AACjB,MAAM,MAAA;AAAA,QACJ,SAAA;AAAA,QACA,GAAA;AAAA,QACA,KAAA;AAAA,QACA,YAAA;AAAA,QACA,iBAAoB,GAAA,KAAA;AAAA,QACpB,MAAS,GAAA,KAAA;AAAA,QACT,GAAM,GAAA,KAAA;AAAA,QACN,gBAAmB,GAAA,GAAA;AAAA,UACjB,GAAI,CAAA,KAAA,CAAA;AACR,MAAA,MAAM,EAAE,KAAO,EAAA,iBAAA,KAAsB,QAAS,CAAA,GAAA,CAAI,OAAO,YAAY,CAAA,CAAA;AAErE,MAAM,MAAA,GAAA,GAAM,IAAIG,WAAO,CAAA;AAAA,QACrB,IAAA,EAAM,kBAAkB,MAAO,CAAA,OAAA;AAAA,QAC/B,KAAA;AAAA,OACD,CAAA,CAAA;AAED,MAAM,MAAA,GAAA,CAAI,gBAAiB,CAAA,MAAA,CAAO,SAAW,EAAA;AAAA,QAC3C,GAAA;AAAA,QACA,KAAA;AAAA,QACA,aAAe,EAAA,YAAA;AAAA,QACf,SAAW,EAAA,iBAAA;AAAA,QACX,MAAA;AAAA,QACA,GAAA;AAAA,QACA,iBAAmB,EAAA,gBAAA;AAAA,OACpB,CAAA,CAAA;AAAA,KACH;AAAA,GACD,CAAA,CAAA;AACH;;;;;;;"}
package/dist/index.d.ts CHANGED
@@ -10,10 +10,9 @@ import * as _backstage_types from '@backstage/types';
10
10
  declare const createGitlabGroupEnsureExistsAction: (options: {
11
11
  integrations: ScmIntegrationRegistry;
12
12
  }) => _backstage_plugin_scaffolder_node.TemplateAction<{
13
+ path: string[];
13
14
  repoUrl: string;
14
15
  token?: string | undefined;
15
- } & {
16
- path: string[];
17
16
  }, {
18
17
  groupId?: number | undefined;
19
18
  }>;
@@ -27,11 +26,10 @@ declare const createGitlabGroupEnsureExistsAction: (options: {
27
26
  declare const createGitlabProjectDeployTokenAction: (options: {
28
27
  integrations: ScmIntegrationRegistry;
29
28
  }) => _backstage_plugin_scaffolder_node.TemplateAction<{
30
- repoUrl: string;
31
- token?: string | undefined;
32
- } & {
33
29
  name: string;
34
30
  projectId: string | number;
31
+ repoUrl: string;
32
+ token?: string | undefined;
35
33
  username?: string | undefined;
36
34
  scopes?: string[] | undefined;
37
35
  }, {
@@ -48,10 +46,9 @@ declare const createGitlabProjectDeployTokenAction: (options: {
48
46
  declare const createGitlabProjectAccessTokenAction: (options: {
49
47
  integrations: ScmIntegrationRegistry;
50
48
  }) => _backstage_plugin_scaffolder_node.TemplateAction<{
49
+ projectId: string | number;
51
50
  repoUrl: string;
52
51
  token?: string | undefined;
53
- } & {
54
- projectId: string | number;
55
52
  name?: string | undefined;
56
53
  accessLevel?: number | undefined;
57
54
  scopes?: string[] | undefined;
@@ -68,13 +65,12 @@ declare const createGitlabProjectAccessTokenAction: (options: {
68
65
  declare const createGitlabProjectVariableAction: (options: {
69
66
  integrations: ScmIntegrationRegistry;
70
67
  }) => _backstage_plugin_scaffolder_node.TemplateAction<{
71
- repoUrl: string;
72
- token?: string | undefined;
73
- } & {
74
68
  key: string;
75
69
  value: string;
76
70
  projectId: string | number;
71
+ repoUrl: string;
77
72
  variableType: string;
73
+ token?: string | undefined;
78
74
  variableProtected?: boolean | undefined;
79
75
  masked?: boolean | undefined;
80
76
  raw?: boolean | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@backstage/plugin-scaffolder-backend-module-gitlab",
3
- "version": "0.2.0-next.2",
3
+ "version": "0.2.0",
4
4
  "main": "dist/index.esm.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "license": "Apache-2.0",
@@ -33,15 +33,15 @@
33
33
  "dependencies": {
34
34
  "@backstage/config": "^1.0.7",
35
35
  "@backstage/errors": "^1.1.5",
36
- "@backstage/integration": "^1.4.5-next.0",
37
- "@backstage/plugin-scaffolder-node": "^0.1.3-next.2",
36
+ "@backstage/integration": "^1.4.5",
37
+ "@backstage/plugin-scaffolder-node": "^0.1.3",
38
38
  "@gitbeaker/node": "^35.8.0",
39
39
  "zod": "^3.21.4"
40
40
  },
41
41
  "devDependencies": {
42
- "@backstage/backend-common": "^0.18.5-next.1",
43
- "@backstage/cli": "^0.22.7-next.0",
44
- "@backstage/core-app-api": "^1.8.0-next.1"
42
+ "@backstage/backend-common": "^0.18.5",
43
+ "@backstage/cli": "^0.22.7",
44
+ "@backstage/core-app-api": "^1.8.0"
45
45
  },
46
46
  "files": [
47
47
  "dist"