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

ISystemOperations.AuthenticateAsync now returns AuthResponse. #496

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Docker.DotNet/Endpoints/ISystemOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface ISystemOperations
/// 204 - No error.
/// 500 - Server error.
/// </remarks>
Task AuthenticateAsync(AuthConfig authConfig, CancellationToken cancellationToken = default(CancellationToken));
Task<AuthResponse> AuthenticateAsync(AuthConfig authConfig, CancellationToken cancellationToken = default(CancellationToken));

/// <summary>
/// Get version.
Expand Down
9 changes: 5 additions & 4 deletions src/Docker.DotNet/Endpoints/SystemOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,16 @@ internal SystemOperations(DockerClient client)
this._client = client;
}

public Task AuthenticateAsync(AuthConfig authConfig, CancellationToken cancellationToken = default(CancellationToken))
public async Task<AuthResponse> AuthenticateAsync(AuthConfig authConfig, CancellationToken cancellationToken = default(CancellationToken))
{
if (authConfig == null)
{
throw new ArgumentNullException(nameof(authConfig));
}
var data = new JsonRequestContent<AuthConfig>(authConfig, this._client.JsonSerializer);

return this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Post, "auth", null, data, cancellationToken);
var data = new JsonRequestContent<AuthConfig>(authConfig, this._client.JsonSerializer);

var response = await this._client.MakeRequestAsync(this._client.NoErrorHandlers, HttpMethod.Post, "auth", null, data, cancellationToken).ConfigureAwait(false);
return this._client.JsonSerializer.DeserializeObject<AuthResponse>(response.Body);
}

public async Task<VersionResponse> GetVersionAsync(CancellationToken cancellationToken = default(CancellationToken))
Expand Down
11 changes: 11 additions & 0 deletions test/Docker.DotNet.Tests/ISystemOperations.Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ public async Task PingAsync_Succeeds()
await _client.System.PingAsync();
}

[Fact]
public async Task AuthenticateAsync_Succeeds()
{
// The blank config goes to Dockerhub, which allows anonymous
// reads, so the auth will definitely be accepted. This lets
// us check whether we correctly retrieve that acceptance.
var config = new AuthConfig();
var response = await _client.System.AuthenticateAsync(config);
Assert.Equal("Login Succeeded", response.Status);
}

private class ProgressMessage : IProgress<Message>
{
internal Action<Message> _onMessageCalled;
Expand Down