Skip to content

Repository files navigation

Soenneker.Docker.Hub.HttpClients

Provides a cached HttpClient configured for the Docker Hub API and bearer authentication.

Installation

dotnet add package Soenneker.Docker.Hub.HttpClients

Configuration

{
  "DockerHub": {
    "AccessToken": "your-access-token"
  }
}

Keep the token in a secret provider rather than source control.

The transport can also be customized with these optional settings:

{
  "Hub": {
    "ClientBaseUrl": "https://hub.docker.com",
    "AuthHeaderName": "Authorization",
    "AuthHeaderValueTemplate": "Bearer {token}"
  }
}

The template replaces every literal {token} with DockerHub:AccessToken. Treat the base URL, header name, and template as trusted configuration because they determine where and how the credential is sent.

Registration and use

using Soenneker.Docker.Hub.HttpClients.Abstract;
using Soenneker.Docker.Hub.HttpClients.Registrars;

services.AddDockerHubOpenApiHttpClientAsSingleton();

public sealed class DockerHubTransport(IDockerHubOpenApiHttpClient clientProvider)
{
    public async Task<HttpResponseMessage> Send(
        HttpRequestMessage request,
        CancellationToken cancellationToken)
    {
        HttpClient client = await clientProvider.Get(cancellationToken);
        return await client.SendAsync(request, cancellationToken);
    }
}

Get returns the cached client. Do not dispose the returned HttpClient; the registered provider owns the cache entry.

Singleton registration is the normal choice for direct transport use. AddDockerHubOpenApiHttpClientAsScoped() creates a separately owned cache entry for each scope, so disposing one provider cannot remove another provider's client.

This package only configures transport. It does not deserialize responses, paginate results, or convert non-success status codes into domain exceptions. Use the companion OpenAPI client utility when you want the generated Docker Hub API surface.

About

A thread-safe singleton HttpClient for Hub's OpenAPI integration.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

1 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages