feat: use Bearer auth header at git commands with Bitbucket Server token

Use Bearer auth header at git commands with Bitbucket Server token
instead of username + token as password.

The username `x-token-auth` was not working with Bitbucket Server
but is used at Bitbucket Cloud.

Signed-off-by: Patrick Jungermann <Patrick.Jungermann@gmail.com>
This commit is contained in:
Patrick Jungermann
2022-07-23 01:04:28 +02:00
parent 3b7930b3e5
commit 3f1316f1c5
3 changed files with 11 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/plugin-scaffolder-backend': minor
---
User Bearer Authorization header at Git commands with token-based auth at Bitbucket Server.
@@ -357,7 +357,7 @@ describe('publish:bitbucketServer', () => {
dir: mockContext.workspacePath,
remoteUrl: 'https://bitbucket.mycompany.com/scm/project/repo',
defaultBranch: 'master',
auth: { username: 'x-token-auth', password: 'thing' },
auth: { token: 'thing' },
logger: mockContext.logger,
gitAuthorInfo: {},
});
@@ -455,7 +455,7 @@ describe('publish:bitbucketServer', () => {
dir: mockContext.workspacePath,
remoteUrl: 'https://bitbucket.mycompany.com/scm/project/repo',
defaultBranch: 'main',
auth: { username: 'x-token-auth', password: 'thing' },
auth: { token: 'thing' },
logger: mockContext.logger,
gitAuthorInfo: {},
});
@@ -524,7 +524,7 @@ describe('publish:bitbucketServer', () => {
expect(initRepoAndPush).toHaveBeenCalledWith({
dir: mockContext.workspacePath,
remoteUrl: 'https://bitbucket.mycompany.com/scm/project/repo',
auth: { username: 'x-token-auth', password: 'thing' },
auth: { token: 'thing' },
logger: mockContext.logger,
defaultBranch: 'master',
gitAuthorInfo: { name: 'Test', email: 'example@example.com' },
@@ -591,7 +591,7 @@ describe('publish:bitbucketServer', () => {
expect(initRepoAndPush).toHaveBeenCalledWith({
dir: mockContext.workspacePath,
remoteUrl: 'https://bitbucket.mycompany.com/scm/project/repo',
auth: { username: 'x-token-auth', password: 'thing' },
auth: { token: 'thing' },
logger: mockContext.logger,
defaultBranch: 'master',
commitMessage: 'Test commit message',
@@ -221,7 +221,7 @@ export function createPublishBitbucketServerAction(options: {
const authorization = reqOpts.headers.Authorization;
if (!authorization) {
throw new Error(
`Authorization has not been provided for ${integrationConfig.config.host}. Please add either (a) a user login auth token, (b) a token or (c) username + password to the integration config.`,
`Authorization has not been provided for ${integrationConfig.config.host}. Please add either (a) a user login auth token, or (b) a token or (c) username + password to the integration config.`,
);
}
@@ -243,8 +243,7 @@ export function createPublishBitbucketServerAction(options: {
const auth = authConfig.token
? {
username: 'x-token-auth',
password: token!,
token: token!,
}
: {
username: authConfig.username!,