1
0
mirror of https://github.com/moby/moby.git synced 2025-09-19 17:01:53 +03:00
Files
moby/client/secret_list.go
Sebastiaan van Stijn 20d8342a4b move endpoint API version constraints to API server
This introduces a `WithMinimumAPIVersion` RouteWrapper to configure the
minimum API version  required for a route. It produces a 400 (Invalid Request)
error when accessing the endpoint on API versions lower than the given version.

Note that technically, it should produce a 404 ("not found") error,
as the endpoint should be considered "non-existing" on such API versions,
but 404 status-codes are used in business logic for various endpoints.

This patch allows removal of corresponding API-version checks from the client,
and other implementation of clients for the API. While the produced error message
is slightly more "technical", these situations should be rare and only happen
when the API version of the client is explicitly overridden, or a client was
implemented with a fixed API version (potentially missing version checks).

Before this patch, these errors were produced by the client:

    DOCKER_API_VERSION=v1.24 docker container prune -f
    docker container prune requires API version 1.25, but the Docker daemon API version is 1.24

With this patch applied, the error is returned by the daemon:

    DOCKER_API_VERSION=v1.24 docker container prune -f
    Error response from daemon: POST /containers/prune requires minimum API version 1.25

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-16 12:20:44 +02:00

35 lines
711 B
Go

package client
import (
"context"
"encoding/json"
"net/url"
"github.com/moby/moby/api/types/filters"
"github.com/moby/moby/api/types/swarm"
)
// SecretList returns the list of secrets.
func (cli *Client) SecretList(ctx context.Context, options SecretListOptions) ([]swarm.Secret, error) {
query := url.Values{}
if options.Filters.Len() > 0 {
filterJSON, err := filters.ToJSON(options.Filters)
if err != nil {
return nil, err
}
query.Set("filters", filterJSON)
}
resp, err := cli.get(ctx, "/secrets", query, nil)
defer ensureReaderClosed(resp)
if err != nil {
return nil, err
}
var secrets []swarm.Secret
err = json.NewDecoder(resp.Body).Decode(&secrets)
return secrets, err
}