Skip to content
6 changes: 3 additions & 3 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ the input arguments from Git - `<protocol>://<host>[/<path>]` - no username is
included even if present.

Host providers are queried in turn, by priority (then registration order) via
the `IHostProvider.IsSupported(InputArguments)` method and passed the input
the `IHostProvider.IsSupported(GitRequest)` method and passed the input
received from Git. If the provider recognises the request, for example by a
matching known host name, they can return `true`. If the provider wants to
cancel and abort an authentication request, for example if this is a HTTP (not
Expand All @@ -213,12 +213,12 @@ Host providers can also be queried via the `IHostProvider.IsSupported(HttpRespon
method and passed the response message from a HEAD call made to the remote URI.
This is useful for detecting on-premises instances based on header values. GCM
will only query a provider via this method overload if no other provider at the
same registration priority has returned `true` to the `InputArguments` overload.
same registration priority has returned `true` to the `GitRequest` overload.

Depending on the request from Git, one of `GetCredentialAsync` (for `get`
requests), `StoreCredentialAsync` (for `store` requests) or
`EraseCredentialAsync` (for `erase` requests) will be called. The argument
`InputArguments` contains the request information passed over standard input
`GitRequest` contains the request information passed over standard input
from Git/the caller; the same as was passed to `IsSupported`.

The return value for the `get` operation must be an `ICredential` that Git can
Expand Down
6 changes: 3 additions & 3 deletions docs/hostprovider.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ request in a standard way.

### 2.2. Handling Requests

The `IsSupported(InputArguments)` method will be called on all registered host
The `IsSupported(GitRequest)` method will be called on all registered host
providers in-turn on the invocation of a `get`, `store`, or `erase` request. The
first host provider to return `true` will be called upon to handle the specific
request. If the user has overridden the host provider selection process, a
specific host provider may be selected instead, and the
`IsSupported(InputArguments)` method will NOT be called.
`IsSupported(GitRequest)` method will NOT be called.

This method MUST return `true` if and only if the provider understands the
request and can serve or handle the request. If the provider does not know how
to handle the request it MUST return `false` instead.

If no host provider returns `true` to a call to the `IsSupported(InputArguments)`
If no host provider returns `true` to a call to the `IsSupported(GitRequest)`
method for a each host provider priority level, then a HTTP HEAD request will be
made to the remote URL and each host provider will be be called via the
`IsSupported(HttpResponseMessage)` method. A host provider SHOULD use this call
Expand Down
254 changes: 127 additions & 127 deletions src/shared/Atlassian.Bitbucket.Tests/BitbucketHostProviderTest.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ public void BitbucketRestApiRegistry_Get_ReturnsCloudApi_ForBitbucketOrg()
settings.Setup(s => s.RemoteUri).Returns(new System.Uri("https://bitbucket.org"));
context.Setup(c => c.Settings).Returns(settings.Object);

var input = new InputArguments(new Dictionary<string, string>
var request = new GitRequest(new Dictionary<string, string>
{
["protocol"] = "https",
["host"] = "bitbucket.org",
});

// When
var registry = new BitbucketRestApiRegistry(context.Object);
var api = registry.Get(input);
var api = registry.Get(request);

// Then
Assert.NotNull(api);
Expand All @@ -40,15 +40,15 @@ public void BitbucketRestApiRegistry_Get_ReturnsDataCenterApi_ForBitbucketDC()
settings.Setup(s => s.RemoteUri).Returns(new System.Uri("https://example.com"));
context.Setup(c => c.Settings).Returns(settings.Object);

var input = new InputArguments(new Dictionary<string, string>
var request = new GitRequest(new Dictionary<string, string>
{
["protocol"] = "http",
["host"] = "example.com",
});

// When
var registry = new BitbucketRestApiRegistry(context.Object);
var api = registry.Get(input);
var api = registry.Get(request);

// Then
Assert.NotNull(api);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public void BitbucketOAuth2Client_GetRefreshTokenServiceName(string protocol, st
{
var trace2 = new NullTrace2();
var client = new Bitbucket.Cloud.BitbucketOAuth2Client(httpClient.Object, settings.Object, trace2);
var input = new InputArguments(new Dictionary<string, string>
var request = new GitRequest(new Dictionary<string, string>
{
["protocol"] = protocol,
["host"] = host,
["username"] = username
});
Assert.Equal(expectedResult, client.GetRefreshTokenServiceName(input));
Assert.Equal(expectedResult, client.GetRefreshTokenServiceName(request));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void BitbucketRestApiRegistry_Get_ReturnsCloudOAuth2Client()
MockSettingOverride(CloudConstants.EnvironmentVariables.OAuthClientSecret, CloudConstants.GitConfiguration.Credential.OAuthClientSecret, "never used", false);
MockSettingOverride(CloudConstants.EnvironmentVariables.OAuthRedirectUri, CloudConstants.GitConfiguration.Credential.OAuthRedirectUri, "never used", false);
MockHttpClientFactory();
var input = MockInputArguments(host);
var input = MockGitRequest(host);

// When
var registry = new OAuth2ClientRegistry(context.Object);
Expand All @@ -52,7 +52,7 @@ public void BitbucketRestApiRegistry_Get_ReturnsDataCenterOAuth2Client_ForBitbuc
MockSettingOverride(DataCenterConstants.EnvironmentVariables.OAuthClientSecret, DataCenterConstants.GitConfiguration.Credential.OAuthClientSecret, "", true); ;
MockSettingOverride(DataCenterConstants.EnvironmentVariables.OAuthRedirectUri, DataCenterConstants.GitConfiguration.Credential.OAuthRedirectUri, "never used", false);
MockHttpClientFactory();
var input = MockInputArguments(host);
var input = MockGitRequest(host);

// When
var registry = new OAuth2ClientRegistry(context.Object);
Expand All @@ -64,9 +64,9 @@ public void BitbucketRestApiRegistry_Get_ReturnsDataCenterOAuth2Client_ForBitbuc

}

private static InputArguments MockInputArguments(string host)
private static GitRequest MockGitRequest(string host)
{
return new InputArguments(new Dictionary<string, string>
return new GitRequest(new Dictionary<string, string>
{
["protocol"] = "https",
["host"] = host,
Expand Down
20 changes: 10 additions & 10 deletions src/shared/Atlassian.Bitbucket/BitbucketAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public enum AuthenticationModes
public interface IBitbucketAuthentication : IDisposable
{
Task<CredentialsPromptResult> GetCredentialsAsync(Uri targetUri, string userName, AuthenticationModes modes);
Task<OAuth2TokenResult> CreateOAuthCredentialsAsync(InputArguments input);
Task<OAuth2TokenResult> RefreshOAuthCredentialsAsync(InputArguments input, string refreshToken);
string GetRefreshTokenServiceName(InputArguments input);
Task<OAuth2TokenResult> CreateOAuthCredentialsAsync(GitRequest request);
Task<OAuth2TokenResult> RefreshOAuthCredentialsAsync(GitRequest request, string refreshToken);
string GetRefreshTokenServiceName(GitRequest request);
}

public class CredentialsPromptResult
Expand Down Expand Up @@ -249,7 +249,7 @@ private async Task<CredentialsPromptResult> GetCredentialsViaHelperAsync(
}
}

public async Task<OAuth2TokenResult> CreateOAuthCredentialsAsync(InputArguments input)
public async Task<OAuth2TokenResult> CreateOAuthCredentialsAsync(GitRequest request)
{
ThrowIfUserInteractionDisabled();

Expand All @@ -260,22 +260,22 @@ public async Task<OAuth2TokenResult> CreateOAuthCredentialsAsync(InputArguments
};

var browser = new OAuth2SystemWebBrowser(Context.SessionManager, browserOptions);
var oauth2Client = _oauth2ClientRegistry.Get(input);
var oauth2Client = _oauth2ClientRegistry.Get(request);

var authCodeResult = await oauth2Client.GetAuthorizationCodeAsync(browser, CancellationToken.None);
return await oauth2Client.GetTokenByAuthorizationCodeAsync(authCodeResult, CancellationToken.None);
}

public async Task<OAuth2TokenResult> RefreshOAuthCredentialsAsync(InputArguments input, string refreshToken)
public async Task<OAuth2TokenResult> RefreshOAuthCredentialsAsync(GitRequest request, string refreshToken)
{
var client = _oauth2ClientRegistry.Get(input);
var client = _oauth2ClientRegistry.Get(request);
return await client.GetTokenByRefreshTokenAsync(refreshToken, CancellationToken.None);
}

public string GetRefreshTokenServiceName(InputArguments input)
public string GetRefreshTokenServiceName(GitRequest request)
{
var client = _oauth2ClientRegistry.Get(input);
return client.GetRefreshTokenServiceName(input);
var client = _oauth2ClientRegistry.Get(request);
return client.GetRefreshTokenServiceName(request);
}

protected internal virtual bool TryFindHelperCommand(out string command, out string args)
Expand Down
4 changes: 2 additions & 2 deletions src/shared/Atlassian.Bitbucket/BitbucketHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public static string GetBaseUri(Uri remoteUri)
return $"{remoteUri.Scheme}://{remoteUri.Host}:{remoteUri.Port}{path}";
}

public static bool IsBitbucketOrg(InputArguments input)
public static bool IsBitbucketOrg(GitRequest request)
{
return IsBitbucketOrg(input.GetRemoteUri());
return IsBitbucketOrg(request.GetRemoteUri());
}

public static bool IsBitbucketOrg(Uri targetUri)
Expand Down
Loading