mirror of
https://github.com/andwati/dokploy.git
synced 2026-11-07 20:45:17 +00:00
fix(bitbucket): enhance Bitbucket authentication handling
- Added support for Bitbucket email and workspace name in the authentication process. - Updated the clone URL generation to use the correct format for API tokens. - Improved error handling to ensure required fields are provided for both API tokens and app passwords. - Added console logs for debugging clone URL and repository information during cloning.
This commit is contained in:
@@ -31,29 +31,45 @@ export const getBitbucketCloneUrl = (
|
|||||||
apiToken?: string | null;
|
apiToken?: string | null;
|
||||||
bitbucketUsername?: string | null;
|
bitbucketUsername?: string | null;
|
||||||
appPassword?: string | null;
|
appPassword?: string | null;
|
||||||
|
bitbucketEmail?: string | null;
|
||||||
|
bitbucketWorkspaceName?: string | null;
|
||||||
} | null,
|
} | null,
|
||||||
repoClone: string,
|
repoClone: string,
|
||||||
) => {
|
) => {
|
||||||
if (!bitbucketProvider) {
|
if (!bitbucketProvider) {
|
||||||
throw new Error("Bitbucket provider is required");
|
throw new Error("Bitbucket provider is required");
|
||||||
}
|
}
|
||||||
return bitbucketProvider.apiToken
|
|
||||||
? `https://x-token-auth:${bitbucketProvider.apiToken}@${repoClone}`
|
if (bitbucketProvider.apiToken) {
|
||||||
: `https://${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}@${repoClone}`;
|
return `https://x-bitbucket-api-token-auth:${bitbucketProvider.apiToken}@${repoClone}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For app passwords, use username:app_password format
|
||||||
|
if (!bitbucketProvider.bitbucketUsername || !bitbucketProvider.appPassword) {
|
||||||
|
throw new Error("Username and app password are required when not using API token");
|
||||||
|
}
|
||||||
|
return `https://${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}@${repoClone}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const getBitbucketHeaders = (bitbucketProvider: Bitbucket) => {
|
export const getBitbucketHeaders = (bitbucketProvider: Bitbucket) => {
|
||||||
if (bitbucketProvider.apiToken) {
|
if (bitbucketProvider.apiToken) {
|
||||||
// For API tokens, use HTTP Basic auth with email and token
|
// According to Bitbucket official docs, for API calls with API tokens:
|
||||||
// According to Bitbucket docs: email:token for API calls
|
// "You will need both your Atlassian account email and an API token"
|
||||||
const email =
|
// Use: {atlassian_account_email}:{api_token}
|
||||||
bitbucketProvider.bitbucketEmail || bitbucketProvider.bitbucketUsername;
|
|
||||||
|
if (!bitbucketProvider.bitbucketEmail) {
|
||||||
|
throw new Error("Atlassian account email is required when using API token for API calls");
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
Authorization: `Basic ${Buffer.from(`${email}:${bitbucketProvider.apiToken}`).toString("base64")}`,
|
Authorization: `Basic ${Buffer.from(`${bitbucketProvider.bitbucketEmail}:${bitbucketProvider.apiToken}`).toString("base64")}`,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// For app passwords, use HTTP Basic auth with username and app password
|
// For app passwords, use HTTP Basic auth with username and app password
|
||||||
|
if (!bitbucketProvider.bitbucketUsername || !bitbucketProvider.appPassword) {
|
||||||
|
throw new Error("Username and app password are required when not using API token");
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
Authorization: `Basic ${Buffer.from(`${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}`).toString("base64")}`,
|
Authorization: `Basic ${Buffer.from(`${bitbucketProvider.bitbucketUsername}:${bitbucketProvider.appPassword}`).toString("base64")}`,
|
||||||
};
|
};
|
||||||
@@ -88,6 +104,8 @@ export const cloneBitbucketRepository = async (
|
|||||||
await recreateDirectory(outputPath);
|
await recreateDirectory(outputPath);
|
||||||
const repoclone = `bitbucket.org/${bitbucketOwner}/${bitbucketRepository}.git`;
|
const repoclone = `bitbucket.org/${bitbucketOwner}/${bitbucketRepository}.git`;
|
||||||
const cloneUrl = getBitbucketCloneUrl(bitbucket, repoclone);
|
const cloneUrl = getBitbucketCloneUrl(bitbucket, repoclone);
|
||||||
|
console.log("cloneUrl", cloneUrl);
|
||||||
|
console.log("repoclone", repoclone);
|
||||||
try {
|
try {
|
||||||
writeStream.write(`\nCloning Repo ${repoclone} to ${outputPath}: ✅\n`);
|
writeStream.write(`\nCloning Repo ${repoclone} to ${outputPath}: ✅\n`);
|
||||||
const cloneArgs = [
|
const cloneArgs = [
|
||||||
|
|||||||
Reference in New Issue
Block a user