@backstage/plugin-scaffolder-backend-module-gitlab 0.1.0-next.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 ADDED
@@ -0,0 +1,15 @@
1
+ # @backstage/plugin-scaffolder-backend-module-gitlab
2
+
3
+ ## 0.1.0-next.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1ad400bb2de: Add Gitlab Scaffolder Plugin
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies
12
+ - @backstage/plugin-scaffolder-node@0.1.2-next.0
13
+ - @backstage/config@1.0.7
14
+ - @backstage/integration@1.4.3
15
+ - @backstage/errors@1.1.5
package/README.md ADDED
@@ -0,0 +1,162 @@
1
+ # scaffolder-backend-module-gitlab
2
+
3
+ Welcome to the Gitlab Module for Scaffolder.
4
+
5
+ Here you can find all Gitlab related features to improve your scaffolder:
6
+
7
+ ## Getting started
8
+
9
+ ## From your Backstage root directory
10
+
11
+ ```bash
12
+ # From your Backstage root directory
13
+ yarn add --cwd packages/backend @backstage/plugin-scaffolder-backend-module-gitlab
14
+ ```
15
+
16
+ Configure the action:
17
+ (you can check the [docs](https://backstage.io/docs/features/software-templates/writing-custom-actions#registering-custom-actions) to see all options):
18
+
19
+ ```typescript
20
+ // packages/backend/src/plugins/scaffolder.ts
21
+
22
+ import {
23
+ createGitlabProjectAccessTokenAction,
24
+ createGitlabProjectAccessTokenAction,
25
+ createGitlabProjectDeployTokenAction,
26
+ } from '@backstage/plugin-scaffolder-backend-module-gitlab';
27
+
28
+ // Create BuiltIn Actions
29
+ const builtInActions = createBuiltinActions({
30
+ integrations,
31
+ catalogClient,
32
+ config: env.config,
33
+ reader: env.reader,
34
+ });
35
+
36
+ // Add Gitlab Actions
37
+ const actions = [
38
+ ...builtInActions,
39
+ createGitlabProjectAccessTokenAction({
40
+ integrations: integrations,
41
+ }),
42
+ createGitlabProjectAccessTokenAction({
43
+ integrations: integrations,
44
+ }),
45
+ createGitlabProjectDeployTokenAction({
46
+ integrations: integrations,
47
+ }),
48
+ ];
49
+
50
+ // Create Scaffolder Router
51
+ return await createRouter({
52
+ containerRunner,
53
+ catalogClient,
54
+ actions,
55
+ logger: env.logger,
56
+ config: env.config,
57
+ database: env.database,
58
+ reader: env.reader,
59
+ });
60
+ ```
61
+
62
+ After that you can use the action in your template:
63
+
64
+ ```yaml
65
+ apiVersion: scaffolder.backstage.io/v1beta3
66
+ kind: Template
67
+ metadata:
68
+ name: gitlab-demo
69
+ title: Gitlab DEMO
70
+ description: Scaffolder Gitlab Demo
71
+ spec:
72
+ owner: backstage/techdocs-core
73
+ type: service
74
+
75
+ parameters:
76
+ - title: Fill in some steps
77
+ required:
78
+ - name
79
+ properties:
80
+ name:
81
+ title: Name
82
+ type: string
83
+ description: Unique name of the component
84
+ ui:autofocus: true
85
+ ui:options:
86
+ rows: 5
87
+ - title: Choose a location
88
+ required:
89
+ - repoUrl
90
+ properties:
91
+ repoUrl:
92
+ title: Repository Location
93
+ type: string
94
+ ui:field: RepoUrlPicker
95
+ ui:options:
96
+ allowedHosts:
97
+ - gitlab.com
98
+
99
+ steps:
100
+ - id: fetch
101
+ name: Fetch
102
+ action: fetch:template
103
+ input:
104
+ url: https://github.com/TEMPLATE
105
+ values:
106
+ name: ${{ parameters.name }}
107
+
108
+ - id: publish
109
+ name: Publish
110
+ action: publish:gitlab
111
+ input:
112
+ description: This is ${{ parameters.name }}
113
+ repoUrl: ${{ parameters.repoUrl }}
114
+ sourcePath: pimcore
115
+ defaultBranch: main
116
+
117
+ - id: gitlab-deploy-token
118
+ name: Create Deploy Token
119
+ action: gitlab:projectDeployToken:create
120
+ input:
121
+ repoUrl: ${{ parameters.repoUrl }}
122
+ projectId: "${{ steps['publish'].output.projectId }}"
123
+ name: ${{ parameters.name }}-secret
124
+ username: ${{ parameters.name }}-secret
125
+ scopes: ['read_registry']
126
+
127
+ - id: gitlab-access-token
128
+ name: Gitlab Project Access Token
129
+ action: gitlab:projectAccessToken:create
130
+ input:
131
+ repoUrl: ${{ parameters.repoUrl }}
132
+ projectId: "${{ steps['publish-manifest'].output.projectId }}"
133
+ name: ${{ parameters.name }}-access-token
134
+ accessLevel: 40
135
+ scopes: ['read_repository', 'write_repository']
136
+
137
+ - id: gitlab-project-variable
138
+ name: Gitlab Project Variable
139
+ action: gitlab:projectVariable:create
140
+ input:
141
+ repoUrl: ${{ parameters.repoUrl }}
142
+ projectId: "${{ steps['publish'].output.projectId }}"
143
+ key: 'VARIABLE_NAME'
144
+ value: "${{ steps['gitlab-access-token'].output.access_token }}"
145
+ variableType: 'env_var'
146
+ masked: true
147
+ variableProtected: false
148
+ raw: false
149
+ environmentScope: '*'
150
+
151
+ - id: register
152
+ name: Register
153
+ action: catalog:register
154
+ input:
155
+ repoContentsUrl: ${{ steps['publish'].output.repoContentsUrl }}
156
+ catalogInfoPath: '/catalog-info.yaml'
157
+
158
+ output:
159
+ links:
160
+ - title: Repository
161
+ url: ${{ steps['publish'].output.remoteUrl }}
162
+ ```
@@ -0,0 +1,291 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var pluginScaffolderNode = require('@backstage/plugin-scaffolder-node');
6
+ var node = require('@gitbeaker/node');
7
+ var errors = require('@backstage/errors');
8
+
9
+ const parseRepoHost = (repoUrl) => {
10
+ let parsed;
11
+ try {
12
+ parsed = new URL(`https://${repoUrl}`);
13
+ } catch (error) {
14
+ throw new errors.InputError(
15
+ `Invalid repo URL passed to publisher, got ${repoUrl}, ${error}`
16
+ );
17
+ }
18
+ return parsed.host;
19
+ };
20
+ const getToken = (repoUrl, inputToken, integrations) => {
21
+ const host = parseRepoHost(repoUrl);
22
+ const integrationConfig = integrations.gitlab.byHost(host);
23
+ if (!integrationConfig) {
24
+ throw new errors.InputError(
25
+ `No matching integration configuration for host ${host}, please check your integrations config`
26
+ );
27
+ }
28
+ const token = inputToken || integrationConfig.config.token;
29
+ const tokenType = inputToken ? "oauthToken" : "token";
30
+ if (tokenType === "oauthToken") {
31
+ throw new errors.InputError(`OAuth Token is currently not supported`);
32
+ }
33
+ return { token, integrationConfig };
34
+ };
35
+
36
+ const createGitlabProjectDeployTokenAction = (options) => {
37
+ const { integrations } = options;
38
+ return pluginScaffolderNode.createTemplateAction({
39
+ id: "gitlab:projectDeployToken:create",
40
+ schema: {
41
+ input: {
42
+ required: ["projectId", "repoUrl"],
43
+ type: "object",
44
+ properties: {
45
+ repoUrl: {
46
+ title: "Repository Location",
47
+ type: "string"
48
+ },
49
+ projectId: {
50
+ title: "Project ID",
51
+ type: ["string", "number"]
52
+ },
53
+ name: {
54
+ title: "Deploy Token Name",
55
+ type: "string"
56
+ },
57
+ username: {
58
+ title: "Deploy Token Username",
59
+ type: "string"
60
+ },
61
+ scopes: {
62
+ title: "Scopes",
63
+ type: "array"
64
+ },
65
+ token: {
66
+ title: "Authentication Token",
67
+ type: "string",
68
+ description: "The token to use for authorization to GitLab"
69
+ }
70
+ }
71
+ },
72
+ output: {
73
+ type: "object",
74
+ properties: {
75
+ deploy_token: {
76
+ title: "Deploy Token",
77
+ type: "string"
78
+ },
79
+ user: {
80
+ title: "User",
81
+ type: "string"
82
+ }
83
+ }
84
+ }
85
+ },
86
+ async handler(ctx) {
87
+ ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`);
88
+ const { repoUrl, projectId, name, username, scopes } = ctx.input;
89
+ const { token, integrationConfig } = getToken(
90
+ repoUrl,
91
+ ctx.input.token,
92
+ integrations
93
+ );
94
+ const api = new node.Gitlab({
95
+ host: integrationConfig.config.baseUrl,
96
+ token
97
+ });
98
+ const deployToken = await api.ProjectDeployTokens.add(
99
+ projectId,
100
+ name,
101
+ scopes,
102
+ {
103
+ username
104
+ }
105
+ );
106
+ if (!deployToken.hasOwnProperty("token")) {
107
+ throw new errors.InputError(`No deploy_token given from gitlab instance`);
108
+ }
109
+ ctx.output("deploy_token", deployToken.token);
110
+ ctx.output("user", deployToken.username);
111
+ }
112
+ });
113
+ };
114
+
115
+ const createGitlabProjectAccessTokenAction = (options) => {
116
+ const { integrations } = options;
117
+ return pluginScaffolderNode.createTemplateAction({
118
+ id: "gitlab:projectAccessToken:create",
119
+ schema: {
120
+ input: {
121
+ required: ["projectId", "repoUrl"],
122
+ type: "object",
123
+ properties: {
124
+ repoUrl: {
125
+ title: "Repository Location",
126
+ type: "string"
127
+ },
128
+ projectId: {
129
+ title: "Project ID",
130
+ type: ["string", "number"]
131
+ },
132
+ name: {
133
+ title: "Deploy Token Name",
134
+ type: "string"
135
+ },
136
+ accessLevel: {
137
+ title: "Access Level of the Token",
138
+ type: "number"
139
+ },
140
+ scopes: {
141
+ title: "Scopes",
142
+ type: "array"
143
+ },
144
+ token: {
145
+ title: "Authentication Token",
146
+ type: "string",
147
+ description: "The token to use for authorization to GitLab"
148
+ }
149
+ }
150
+ },
151
+ output: {
152
+ type: "object",
153
+ properties: {
154
+ access_token: {
155
+ title: "Access Token",
156
+ type: "string"
157
+ }
158
+ }
159
+ }
160
+ },
161
+ async handler(ctx) {
162
+ ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`);
163
+ const { repoUrl, projectId, name, accessLevel, scopes } = ctx.input;
164
+ const { token, integrationConfig } = getToken(
165
+ repoUrl,
166
+ ctx.input.token,
167
+ integrations
168
+ );
169
+ const response = await fetch(
170
+ `${integrationConfig.config.baseUrl}/api/v4/projects/${projectId}/access_tokens`,
171
+ {
172
+ method: "POST",
173
+ // *GET, POST, PUT, DELETE, etc.
174
+ headers: {
175
+ "PRIVATE-TOKEN": token,
176
+ "Content-Type": "application/json"
177
+ },
178
+ body: JSON.stringify({
179
+ name,
180
+ scopes,
181
+ access_level: accessLevel
182
+ })
183
+ }
184
+ );
185
+ const result = await response.json();
186
+ ctx.output("access_token", result.token);
187
+ }
188
+ });
189
+ };
190
+
191
+ const createGitlabProjectVariableAction = (options) => {
192
+ const { integrations } = options;
193
+ return pluginScaffolderNode.createTemplateAction({
194
+ id: "gitlab:projectVariable:create",
195
+ schema: {
196
+ input: {
197
+ required: [
198
+ "repoUrl",
199
+ "projectId",
200
+ "key",
201
+ "value",
202
+ "variableType",
203
+ "variableProtected",
204
+ "masked",
205
+ "raw",
206
+ "environmentScope"
207
+ ],
208
+ type: "object",
209
+ properties: {
210
+ repoUrl: {
211
+ title: "Repository Location",
212
+ type: "string"
213
+ },
214
+ projectId: {
215
+ title: "Project ID",
216
+ type: ["string", "number"]
217
+ },
218
+ key: {
219
+ title: "The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed",
220
+ type: "string"
221
+ },
222
+ value: {
223
+ title: "The value of a variable",
224
+ type: "string"
225
+ },
226
+ variableType: {
227
+ title: "Variable Type (env_var or file)",
228
+ type: "string"
229
+ },
230
+ variableProtected: {
231
+ title: "Whether the variable is protected. Default: false",
232
+ type: "boolean"
233
+ },
234
+ masked: {
235
+ title: "Whether the variable is masked. Default: false",
236
+ type: "boolean"
237
+ },
238
+ raw: {
239
+ title: "Whether the variable is expandable. Default: false",
240
+ type: "boolean"
241
+ },
242
+ environmentScope: {
243
+ title: "The environment_scope of the variable. Default: *",
244
+ type: "string"
245
+ },
246
+ token: {
247
+ title: "Authentication Token",
248
+ type: "string",
249
+ description: "The token to use for authorization to GitLab"
250
+ }
251
+ }
252
+ }
253
+ },
254
+ async handler(ctx) {
255
+ const {
256
+ repoUrl,
257
+ projectId,
258
+ key,
259
+ value,
260
+ variableType,
261
+ variableProtected,
262
+ masked,
263
+ raw,
264
+ environmentScope
265
+ } = ctx.input;
266
+ const { token, integrationConfig } = getToken(
267
+ repoUrl,
268
+ ctx.input.token,
269
+ integrations
270
+ );
271
+ const api = new node.Gitlab({
272
+ host: integrationConfig.config.baseUrl,
273
+ token
274
+ });
275
+ await api.ProjectVariables.create(projectId, {
276
+ key,
277
+ value,
278
+ variable_type: variableType,
279
+ protected: variableProtected,
280
+ masked,
281
+ raw,
282
+ environment_scope: environmentScope
283
+ });
284
+ }
285
+ });
286
+ };
287
+
288
+ exports.createGitlabProjectAccessTokenAction = createGitlabProjectAccessTokenAction;
289
+ exports.createGitlabProjectDeployTokenAction = createGitlabProjectDeployTokenAction;
290
+ exports.createGitlabProjectVariableAction = createGitlabProjectVariableAction;
291
+ //# sourceMappingURL=index.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs.js","sources":["../src/util.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 { InputError } from '@backstage/errors';\nimport {\n GitLabIntegration,\n ScmIntegrationRegistry,\n} from '@backstage/integration';\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 repoUrl: string,\n inputToken: string | null | undefined,\n integrations: ScmIntegrationRegistry,\n): { token: string; integrationConfig: GitLabIntegration } => {\n const host = parseRepoHost(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 = inputToken || integrationConfig.config.token!;\n const tokenType = inputToken ? '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 { Gitlab } from '@gitbeaker/node';\nimport { ScmIntegrationRegistry } from '@backstage/integration';\nimport { DeployTokenScope } from '@gitbeaker/core/dist/types/templates/ResourceDeployTokens';\nimport { getToken } from '../util';\nimport { InputError } from '@backstage/errors';\n\n/**\n * Creates a `gitlab:create-project-deploy-token` 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 repoUrl: string;\n projectId: string | number;\n name: string;\n username: string;\n scopes: string[];\n token?: string;\n }>({\n id: 'gitlab:projectDeployToken:create',\n schema: {\n input: {\n required: ['projectId', 'repoUrl'],\n type: 'object',\n properties: {\n repoUrl: {\n title: 'Repository Location',\n type: 'string',\n },\n projectId: {\n title: 'Project ID',\n type: ['string', 'number'],\n },\n name: {\n title: 'Deploy Token Name',\n type: 'string',\n },\n username: {\n title: 'Deploy Token Username',\n type: 'string',\n },\n scopes: {\n title: 'Scopes',\n type: 'array',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n deploy_token: {\n title: 'Deploy Token',\n type: 'string',\n },\n user: {\n title: 'User',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n ctx.logger.info(`Creating Token for Project \"${ctx.input.projectId}\"`);\n const { repoUrl, projectId, name, username, scopes } = ctx.input;\n const { token, integrationConfig } = getToken(\n repoUrl,\n ctx.input.token,\n integrations,\n );\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 { getToken } from '../util';\n\n/**\n * Creates a `gitlab:create-project-access-token` 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 repoUrl: string;\n projectId: string | number;\n name: string;\n accessLevel: number;\n scopes: string[];\n token?: string;\n }>({\n id: 'gitlab:projectAccessToken:create',\n schema: {\n input: {\n required: ['projectId', 'repoUrl'],\n type: 'object',\n properties: {\n repoUrl: {\n title: 'Repository Location',\n type: 'string',\n },\n projectId: {\n title: 'Project ID',\n type: ['string', 'number'],\n },\n name: {\n title: 'Deploy Token Name',\n type: 'string',\n },\n accessLevel: {\n title: 'Access Level of the Token',\n type: 'number',\n },\n scopes: {\n title: 'Scopes',\n type: 'array',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n },\n },\n output: {\n type: 'object',\n properties: {\n access_token: {\n title: 'Access Token',\n type: 'string',\n },\n },\n },\n },\n async handler(ctx) {\n ctx.logger.info(`Creating Token for Project \"${ctx.input.projectId}\"`);\n const { repoUrl, projectId, name, accessLevel, scopes } = ctx.input;\n const { token, integrationConfig } = getToken(\n repoUrl,\n ctx.input.token,\n integrations,\n );\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 { getToken } from '../util';\nimport { Gitlab } from '@gitbeaker/node';\n\n/**\n * Creates a `gitlab:create-project-variable` 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 repoUrl: string;\n projectId: string | number;\n key: string;\n value: string;\n variableType: string;\n variableProtected: boolean;\n masked: boolean;\n raw: boolean;\n environmentScope: string;\n token?: string;\n }>({\n id: 'gitlab:projectVariable:create',\n schema: {\n input: {\n required: [\n 'repoUrl',\n 'projectId',\n 'key',\n 'value',\n 'variableType',\n 'variableProtected',\n 'masked',\n 'raw',\n 'environmentScope',\n ],\n type: 'object',\n properties: {\n repoUrl: {\n title: 'Repository Location',\n type: 'string',\n },\n projectId: {\n title: 'Project ID',\n type: ['string', 'number'],\n },\n key: {\n title:\n 'The key of a variable; must have no more than 255 characters; only A-Z, a-z, 0-9, and _ are allowed',\n type: 'string',\n },\n value: {\n title: 'The value of a variable',\n type: 'string',\n },\n variableType: {\n title: 'Variable Type (env_var or file)',\n type: 'string',\n },\n variableProtected: {\n title: 'Whether the variable is protected. Default: false',\n type: 'boolean',\n },\n masked: {\n title: 'Whether the variable is masked. Default: false',\n type: 'boolean',\n },\n raw: {\n title: 'Whether the variable is expandable. Default: false',\n type: 'boolean',\n },\n environmentScope: {\n title: 'The environment_scope of the variable. Default: *',\n type: 'string',\n },\n token: {\n title: 'Authentication Token',\n type: 'string',\n description: 'The token to use for authorization to GitLab',\n },\n },\n },\n },\n async handler(ctx) {\n const {\n repoUrl,\n projectId,\n key,\n value,\n variableType,\n variableProtected,\n masked,\n raw,\n environmentScope,\n } = ctx.input;\n const { token, integrationConfig } = getToken(\n repoUrl,\n ctx.input.token,\n integrations,\n );\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":["InputError","createTemplateAction","Gitlab"],"mappings":";;;;;;;;AAsBa,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,IAAIA,iBAAA;AAAA,MACR,6CAA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A;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;;;;;;"}
@@ -0,0 +1,59 @@
1
+ import * as _backstage_plugin_scaffolder_node from '@backstage/plugin-scaffolder-node';
2
+ import { ScmIntegrationRegistry } from '@backstage/integration';
3
+
4
+ /**
5
+ * Creates a `gitlab:create-project-deploy-token` Scaffolder action.
6
+ *
7
+ * @param options - Templating configuration.
8
+ * @public
9
+ */
10
+ declare const createGitlabProjectDeployTokenAction: (options: {
11
+ integrations: ScmIntegrationRegistry;
12
+ }) => _backstage_plugin_scaffolder_node.TemplateAction<{
13
+ repoUrl: string;
14
+ projectId: string | number;
15
+ name: string;
16
+ username: string;
17
+ scopes: string[];
18
+ token?: string | undefined;
19
+ }>;
20
+
21
+ /**
22
+ * Creates a `gitlab:create-project-access-token` Scaffolder action.
23
+ *
24
+ * @param options - Templating configuration.
25
+ * @public
26
+ */
27
+ declare const createGitlabProjectAccessTokenAction: (options: {
28
+ integrations: ScmIntegrationRegistry;
29
+ }) => _backstage_plugin_scaffolder_node.TemplateAction<{
30
+ repoUrl: string;
31
+ projectId: string | number;
32
+ name: string;
33
+ accessLevel: number;
34
+ scopes: string[];
35
+ token?: string | undefined;
36
+ }>;
37
+
38
+ /**
39
+ * Creates a `gitlab:create-project-variable` Scaffolder action.
40
+ *
41
+ * @param options - Templating configuration.
42
+ * @public
43
+ */
44
+ declare const createGitlabProjectVariableAction: (options: {
45
+ integrations: ScmIntegrationRegistry;
46
+ }) => _backstage_plugin_scaffolder_node.TemplateAction<{
47
+ repoUrl: string;
48
+ projectId: string | number;
49
+ key: string;
50
+ value: string;
51
+ variableType: string;
52
+ variableProtected: boolean;
53
+ masked: boolean;
54
+ raw: boolean;
55
+ environmentScope: string;
56
+ token?: string | undefined;
57
+ }>;
58
+
59
+ export { createGitlabProjectAccessTokenAction, createGitlabProjectDeployTokenAction, createGitlabProjectVariableAction };
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "@backstage/plugin-scaffolder-backend-module-gitlab",
3
+ "version": "0.1.0-next.0",
4
+ "main": "dist/index.esm.js",
5
+ "types": "dist/index.d.ts",
6
+ "license": "Apache-2.0",
7
+ "publishConfig": {
8
+ "access": "public",
9
+ "main": "dist/index.esm.js",
10
+ "types": "dist/index.d.ts"
11
+ },
12
+ "backstage": {
13
+ "role": "backend-plugin-module"
14
+ },
15
+ "homepage": "https://backstage.io",
16
+ "repository": {
17
+ "type": "git",
18
+ "url": "https://github.com/backstage/backstage",
19
+ "directory": "plugins/scaffolder-backend-module-gitlab"
20
+ },
21
+ "keywords": [
22
+ "backstage"
23
+ ],
24
+ "scripts": {
25
+ "start": "backstage-cli package start",
26
+ "build": "backstage-cli package build",
27
+ "lint": "backstage-cli package lint",
28
+ "test": "backstage-cli package test",
29
+ "clean": "backstage-cli package clean",
30
+ "prepack": "backstage-cli package prepack",
31
+ "postpack": "backstage-cli package postpack"
32
+ },
33
+ "dependencies": {
34
+ "@backstage/config": "^1.0.7",
35
+ "@backstage/errors": "^1.1.5",
36
+ "@backstage/integration": "^1.4.3",
37
+ "@backstage/plugin-scaffolder-node": "^0.1.2-next.0",
38
+ "@gitbeaker/node": "^35.8.0"
39
+ },
40
+ "devDependencies": {
41
+ "@backstage/backend-common": "^0.18.4-next.0",
42
+ "@backstage/cli": "^0.22.6-next.0",
43
+ "@backstage/core-app-api": "^1.7.0-next.0"
44
+ },
45
+ "files": [
46
+ "dist"
47
+ ]
48
+ }