Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update support for Bitbucket Server #141

Closed
14 changes: 7 additions & 7 deletions src/shared/Atlassian.Bitbucket/BitbucketHostProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public async Task<ICredential> GetCredentialAsync(InputArguments input)
if (StringComparer.OrdinalIgnoreCase.Equals(input.Protocol, "http")
&& !IsBitbucketServer(targetUri))
{
throw new Exception("Unencrypted HTTP is not supported for Bitbucket. Ensure the repository remote URL is using HTTPS.");
throw new Exception("Unencrypted HTTP is not supported for Bitbucket.org. Ensure the repository remote URL is using HTTPS.");
}

// Try and get the username specified in the remote URL if any
Expand Down Expand Up @@ -185,13 +185,13 @@ public Task StoreCredentialAsync(InputArguments input)
_context.Trace.WriteLine("Credential was successfully stored.");

Uri targetUri = GetTargetUri(input);
if(IsBitbucketServer(targetUri))
if (IsBitbucketServer(targetUri))
{
// BBS doesn't usually include the username in the urls which means they aren't included in the GET call,
// which means if we store only with the username the credentials are never found again ...
// This does have the potential to overwrite itself for different BbS accounts,
// but typically BbS doesn't encourage multiple user accounts
string bbsCredentialKey = GetBbSCredentialKey(input);
string bbsCredentialKey = GetBitbuckerServerCredentialKey(input);
mjcheetham marked this conversation as resolved.
Show resolved Hide resolved
_context.Trace.WriteLine($"Storing Bitbucket Server credential with key '{bbsCredentialKey}'...");
_context.CredentialStore.AddOrUpdate(bbsCredentialKey, credential);
_context.Trace.WriteLine("Bitbucket Server Credential was successfully stored.");
Expand Down Expand Up @@ -236,7 +236,7 @@ private async Task<string> ResolveOAuthUserNameAsync(string accessToken)

private async Task<bool> RequiresTwoFactorAuthenticationAsync(ICredential credentials, Uri targetUri)
{
if(IsBitbucketServer(targetUri))
if (IsBitbucketServer(targetUri))
{
// BBS does not support 2FA out of the box so neither does GCM
return false;
Expand Down Expand Up @@ -277,11 +277,11 @@ private string GetCredentialKey(InputArguments input)
return $"git:{url}";
}

private string GetBbSCredentialKey(InputArguments input)
private string GetBitbucketServerCredentialKey(InputArguments input)
{
// The credential (user/pass or an OAuth access token) key is the full target URI.
// If the full path is included (credential.useHttpPath = true) then respect that.
string url = GetBbsTargetUri(input).AbsoluteUri;
string url = GetBitbucketServerTargetUri(input).AbsoluteUri;

// Trim trailing slash
if (url.EndsWith("/"))
Expand Down Expand Up @@ -332,7 +332,7 @@ private static Uri GetTargetUri(InputArguments input)
return uri;
}

private static Uri GetBbsTargetUri(InputArguments input)
private static Uri GetBitbucketServerTargetUri(InputArguments input)
{
Uri uri = new UriBuilder
{
Expand Down