api/types: move SecretCreateResponse, SecretListOptions to types/swarm

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-05-19 09:36:48 +02:00
parent 94e84169ec
commit 23117afca8
13 changed files with 54 additions and 45 deletions

View File

@@ -30,7 +30,7 @@ type Backend interface {
RemoveNode(string, bool) error
GetTasks(types.TaskListOptions) ([]swarm.Task, error)
GetTask(string) (swarm.Task, error)
GetSecrets(opts types.SecretListOptions) ([]swarm.Secret, error)
GetSecrets(opts swarm.SecretListOptions) ([]swarm.Secret, error)
CreateSecret(s swarm.SecretSpec) (string, error)
RemoveSecret(idOrName string) error
GetSecret(id string) (swarm.Secret, error)

View File

@@ -416,7 +416,7 @@ func (sr *swarmRouter) getSecrets(ctx context.Context, w http.ResponseWriter, r
return err
}
secrets, err := sr.backend.GetSecrets(basictypes.SecretListOptions{Filters: filters})
secrets, err := sr.backend.GetSecrets(types.SecretListOptions{Filters: filters})
if err != nil {
return err
}
@@ -439,7 +439,7 @@ func (sr *swarmRouter) createSecret(ctx context.Context, w http.ResponseWriter,
return err
}
return httputils.WriteJSON(w, http.StatusCreated, &basictypes.SecretCreateResponse{
return httputils.WriteJSON(w, http.StatusCreated, &types.SecretCreateResponse{
ID: id,
})
}

View File

@@ -1,6 +1,10 @@
package swarm // import "github.com/docker/docker/api/types/swarm"
import "os"
import (
"os"
"github.com/docker/docker/api/types/filters"
)
// Secret represents a secret.
type Secret struct {
@@ -48,3 +52,15 @@ type SecretReference struct {
SecretID string
SecretName string
}
// SecretCreateResponse contains the information returned to a client
// on the creation of a new secret.
type SecretCreateResponse struct {
// ID is the id of the created secret.
ID string
}
// SecretListOptions holds parameters to list secrets
type SecretListOptions struct {
Filters filters.Args
}

View File

@@ -94,18 +94,6 @@ type DiskUsage struct {
BuilderSize int64 `json:",omitempty"` // Deprecated: deprecated in API 1.38, and no longer used since API 1.40.
}
// SecretCreateResponse contains the information returned to a client
// on the creation of a new secret.
type SecretCreateResponse struct {
// ID is the id of the created secret.
ID string
}
// SecretListOptions holds parameters to list secrets
type SecretListOptions struct {
Filters filters.Args
}
// ConfigCreateResponse contains the information returned to a client
// on the creation of a new config.
type ConfigCreateResponse struct {

View File

@@ -8,6 +8,7 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/storage"
"github.com/docker/docker/api/types/swarm"
)
// IDResponse Response to an API call that returns just an Id.
@@ -115,6 +116,17 @@ type ImageInspect = image.InspectResponse
// Deprecated: moved to [github.com/docker/docker/api/types/registry.RequestAuthConfig].
type RequestPrivilegeFunc func(context.Context) (string, error)
// SecretCreateResponse contains the information returned to a client
// on the creation of a new secret.
//
// Deprecated: use [swarm.SecretCreateResponse].
type SecretCreateResponse = swarm.SecretCreateResponse
// SecretListOptions holds parameters to list secrets
//
// Deprecated: use [swarm.SecretListOptions].
type SecretListOptions = swarm.SecretListOptions
// BuildCache contains information about a build cache record.
//
// Deprecated: deprecated in API 1.49. Use [build.CacheRecord] instead.

View File

@@ -220,8 +220,8 @@ type VolumeAPIClient interface {
// SecretAPIClient defines API client methods for secrets
type SecretAPIClient interface {
SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error)
SecretCreate(ctx context.Context, secret swarm.SecretSpec) (types.SecretCreateResponse, error)
SecretList(ctx context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error)
SecretCreate(ctx context.Context, secret swarm.SecretSpec) (swarm.SecretCreateResponse, error)
SecretRemove(ctx context.Context, id string) error
SecretInspectWithRaw(ctx context.Context, name string) (swarm.Secret, []byte, error)
SecretUpdate(ctx context.Context, id string, version swarm.Version, secret swarm.SecretSpec) error

View File

@@ -4,22 +4,21 @@ import (
"context"
"encoding/json"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
)
// SecretCreate creates a new secret.
func (cli *Client) SecretCreate(ctx context.Context, secret swarm.SecretSpec) (types.SecretCreateResponse, error) {
func (cli *Client) SecretCreate(ctx context.Context, secret swarm.SecretSpec) (swarm.SecretCreateResponse, error) {
if err := cli.NewVersionError(ctx, "1.25", "secret create"); err != nil {
return types.SecretCreateResponse{}, err
return swarm.SecretCreateResponse{}, err
}
resp, err := cli.post(ctx, "/secrets/create", nil, secret, nil)
defer ensureReaderClosed(resp)
if err != nil {
return types.SecretCreateResponse{}, err
return swarm.SecretCreateResponse{}, err
}
var response types.SecretCreateResponse
var response swarm.SecretCreateResponse
err = json.NewDecoder(resp.Body).Decode(&response)
return response, err
}

View File

@@ -10,7 +10,6 @@ import (
"strings"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/errdefs"
"gotest.tools/v3/assert"
@@ -46,7 +45,7 @@ func TestSecretCreate(t *testing.T) {
if req.Method != http.MethodPost {
return nil, fmt.Errorf("expected POST method, got %s", req.Method)
}
b, err := json.Marshal(types.SecretCreateResponse{
b, err := json.Marshal(swarm.SecretCreateResponse{
ID: "test_secret",
})
if err != nil {

View File

@@ -5,13 +5,12 @@ import (
"encoding/json"
"net/url"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm"
)
// SecretList returns the list of secrets.
func (cli *Client) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
func (cli *Client) SecretList(ctx context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error) {
if err := cli.NewVersionError(ctx, "1.25", "secret list"); err != nil {
return nil, err
}

View File

@@ -10,7 +10,6 @@ import (
"strings"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/errdefs"
@@ -23,7 +22,7 @@ func TestSecretListUnsupported(t *testing.T) {
version: "1.24",
client: &http.Client{},
}
_, err := client.SecretList(context.Background(), types.SecretListOptions{})
_, err := client.SecretList(context.Background(), swarm.SecretListOptions{})
assert.Check(t, is.Error(err, `"secret list" requires API version 1.25, but the Docker daemon API version is 1.24`))
}
@@ -33,7 +32,7 @@ func TestSecretListError(t *testing.T) {
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
}
_, err := client.SecretList(context.Background(), types.SecretListOptions{})
_, err := client.SecretList(context.Background(), swarm.SecretListOptions{})
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
}
@@ -41,17 +40,17 @@ func TestSecretList(t *testing.T) {
const expectedURL = "/v1.25/secrets"
listCases := []struct {
options types.SecretListOptions
options swarm.SecretListOptions
expectedQueryParams map[string]string
}{
{
options: types.SecretListOptions{},
options: swarm.SecretListOptions{},
expectedQueryParams: map[string]string{
"filters": "",
},
},
{
options: types.SecretListOptions{
options: swarm.SecretListOptions{
Filters: filters.NewArgs(
filters.Arg("label", "label1"),
filters.Arg("label", "label2"),

View File

@@ -3,7 +3,6 @@ package cluster // import "github.com/docker/docker/daemon/cluster"
import (
"context"
apitypes "github.com/docker/docker/api/types"
types "github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/daemon/cluster/convert"
swarmapi "github.com/moby/swarmkit/v2/api"
@@ -28,7 +27,7 @@ func (c *Cluster) GetSecret(input string) (types.Secret, error) {
}
// GetSecrets returns all secrets of a managed swarm cluster.
func (c *Cluster) GetSecrets(options apitypes.SecretListOptions) ([]types.Secret, error) {
func (c *Cluster) GetSecrets(options types.SecretListOptions) ([]types.Secret, error) {
c.mu.RLock()
defer c.mu.RUnlock()

View File

@@ -8,7 +8,6 @@ import (
"testing"
"time"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
"github.com/docker/docker/api/types/filters"
swarmtypes "github.com/docker/docker/api/types/swarm"
@@ -54,7 +53,7 @@ func TestSecretList(t *testing.T) {
c := d.NewClientT(t)
defer c.Close()
configs, err := c.SecretList(ctx, types.SecretListOptions{})
configs, err := c.SecretList(ctx, swarmtypes.SecretListOptions{})
assert.NilError(t, err)
assert.Check(t, is.Equal(len(configs), 0))
@@ -70,7 +69,7 @@ func TestSecretList(t *testing.T) {
secret1ID := createSecret(ctx, t, c, testName1, []byte("TESTINGDATA1"), map[string]string{"type": "production"})
// test by `secret ls`
entries, err := c.SecretList(ctx, types.SecretListOptions{})
entries, err := c.SecretList(ctx, swarmtypes.SecretListOptions{})
assert.NilError(t, err)
assert.Check(t, is.DeepEqual(secretNamesFromList(entries), testNames))
@@ -103,7 +102,7 @@ func TestSecretList(t *testing.T) {
},
}
for _, tc := range testCases {
entries, err = c.SecretList(ctx, types.SecretListOptions{
entries, err = c.SecretList(ctx, swarmtypes.SecretListOptions{
Filters: tc.filters,
})
assert.NilError(t, err)
@@ -357,7 +356,7 @@ func TestSecretCreateResolve(t *testing.T) {
fakeName := secretID
fakeID := createSecret(ctx, t, c, fakeName, []byte("fake foo"), nil)
entries, err := c.SecretList(ctx, types.SecretListOptions{})
entries, err := c.SecretList(ctx, swarmtypes.SecretListOptions{})
assert.NilError(t, err)
assert.Check(t, is.Contains(secretNamesFromList(entries), testName))
assert.Check(t, is.Contains(secretNamesFromList(entries), fakeName))
@@ -366,7 +365,7 @@ func TestSecretCreateResolve(t *testing.T) {
assert.NilError(t, err)
// Fake one will remain
entries, err = c.SecretList(ctx, types.SecretListOptions{})
entries, err = c.SecretList(ctx, swarmtypes.SecretListOptions{})
assert.NilError(t, err)
assert.Assert(t, is.DeepEqual(secretNamesFromList(entries), []string{fakeName}))
@@ -377,14 +376,14 @@ func TestSecretCreateResolve(t *testing.T) {
// - Partial ID (prefix)
err = c.SecretRemove(ctx, fakeName[:5])
assert.Assert(t, nil != err)
entries, err = c.SecretList(ctx, types.SecretListOptions{})
entries, err = c.SecretList(ctx, swarmtypes.SecretListOptions{})
assert.NilError(t, err)
assert.Assert(t, is.DeepEqual(secretNamesFromList(entries), []string{fakeName}))
// Remove based on ID prefix of the fake one should succeed
err = c.SecretRemove(ctx, fakeID[:5])
assert.NilError(t, err)
entries, err = c.SecretList(ctx, types.SecretListOptions{})
entries, err = c.SecretList(ctx, swarmtypes.SecretListOptions{})
assert.NilError(t, err)
assert.Assert(t, is.Equal(0, len(entries)))
}

View File

@@ -4,7 +4,6 @@ import (
"context"
"testing"
"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/swarm"
"gotest.tools/v3/assert"
)
@@ -30,7 +29,7 @@ func (d *Daemon) ListSecrets(t testing.TB) []swarm.Secret {
cli := d.NewClientT(t)
defer cli.Close()
secrets, err := cli.SecretList(context.Background(), types.SecretListOptions{})
secrets, err := cli.SecretList(context.Background(), swarm.SecretListOptions{})
assert.NilError(t, err)
return secrets
}