Merge pull request #31472 from veenarm/fix-31333
Fix Create gitlabProjectDeployTokenCreate resolves 31333
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/plugin-scaffolder-backend-module-gitlab': minor
|
||||
---
|
||||
|
||||
fix scaffolder action createDeployToken to allow usage of oauth tokens
|
||||
+31
@@ -79,6 +79,37 @@ describe('gitlab:create-deploy-token', () => {
|
||||
name: 'tokenname',
|
||||
username: 'tokenuser',
|
||||
scopes: ['read_repository'],
|
||||
token: 'oidctoken',
|
||||
},
|
||||
});
|
||||
|
||||
expect(mockGitlabClient.DeployTokens.create).toHaveBeenCalledWith(
|
||||
'tokenname',
|
||||
['read_repository'],
|
||||
{
|
||||
projectId: '123',
|
||||
username: 'tokenuser',
|
||||
},
|
||||
);
|
||||
|
||||
expect(mockContext.output).toHaveBeenCalledWith('deploy_token', 'TOKEN');
|
||||
expect(mockContext.output).toHaveBeenCalledWith('user', 'User');
|
||||
});
|
||||
|
||||
it('should work when there is not a token provided through ctx.input e.g. integration token', async () => {
|
||||
mockGitlabClient.DeployTokens.create.mockResolvedValue({
|
||||
token: 'TOKEN',
|
||||
username: 'User',
|
||||
});
|
||||
|
||||
await action.handler({
|
||||
...mockContext,
|
||||
input: {
|
||||
repoUrl: 'gitlab.com?repo=bob&owner=owner',
|
||||
projectId: '123',
|
||||
name: 'tokenname',
|
||||
username: 'tokenuser',
|
||||
scopes: ['read_repository'],
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
+5
-8
@@ -17,8 +17,8 @@
|
||||
import { InputError } from '@backstage/errors';
|
||||
import { ScmIntegrationRegistry } from '@backstage/integration';
|
||||
import { createTemplateAction } from '@backstage/plugin-scaffolder-node';
|
||||
import { DeployTokenScope, Gitlab } from '@gitbeaker/rest';
|
||||
import { getToken } from '../util';
|
||||
import { DeployTokenScope } from '@gitbeaker/rest';
|
||||
import { getClient, parseRepoUrl } from '../util';
|
||||
import { examples } from './gitlabProjectDeployTokenCreate.examples';
|
||||
|
||||
/**
|
||||
@@ -78,8 +78,7 @@ export const createGitlabProjectDeployTokenAction = (options: {
|
||||
},
|
||||
async handler(ctx) {
|
||||
ctx.logger.info(`Creating Token for Project "${ctx.input.projectId}"`);
|
||||
const { projectId, name, username, scopes } = ctx.input;
|
||||
const { token, integrationConfig } = getToken(ctx.input, integrations);
|
||||
const { projectId, name, username, scopes, repoUrl, token } = ctx.input;
|
||||
|
||||
if (scopes.length === 0) {
|
||||
throw new InputError(
|
||||
@@ -87,10 +86,8 @@ export const createGitlabProjectDeployTokenAction = (options: {
|
||||
);
|
||||
}
|
||||
|
||||
const api = new Gitlab({
|
||||
host: integrationConfig.config.baseUrl,
|
||||
token: token,
|
||||
});
|
||||
const { host } = parseRepoUrl(repoUrl, integrations);
|
||||
const api = getClient({ host, integrations, token });
|
||||
|
||||
const { deployToken, deployUsername } = await ctx.checkpoint({
|
||||
key: `create.deploy.token.${projectId}.${name}`,
|
||||
|
||||
Reference in New Issue
Block a user