diff --git a/api/types/swarm/secret.go b/api/types/swarm/secret.go index 6fea600b42..0e27ed9b07 100644 --- a/api/types/swarm/secret.go +++ b/api/types/swarm/secret.go @@ -2,8 +2,6 @@ package swarm import ( "os" - - "github.com/moby/moby/api/types/filters" ) // Secret represents a secret. @@ -59,8 +57,3 @@ 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 -} diff --git a/client/client_interfaces.go b/client/client_interfaces.go index c686f535f5..c0831b9a3c 100644 --- a/client/client_interfaces.go +++ b/client/client_interfaces.go @@ -206,7 +206,7 @@ type VolumeAPIClient interface { // SecretAPIClient defines API client methods for secrets type SecretAPIClient interface { - SecretList(ctx context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error) + SecretList(ctx context.Context, options 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) diff --git a/client/secret_list.go b/client/secret_list.go index 2ed1997a0a..13879ba9f2 100644 --- a/client/secret_list.go +++ b/client/secret_list.go @@ -10,7 +10,7 @@ import ( ) // SecretList returns the list of secrets. -func (cli *Client) SecretList(ctx context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error) { +func (cli *Client) SecretList(ctx context.Context, options SecretListOptions) ([]swarm.Secret, error) { if err := cli.NewVersionError(ctx, "1.25", "secret list"); err != nil { return nil, err } diff --git a/client/secret_list_opts.go b/client/secret_list_opts.go new file mode 100644 index 0000000000..313eeefe39 --- /dev/null +++ b/client/secret_list_opts.go @@ -0,0 +1,8 @@ +package client + +import "github.com/moby/moby/api/types/filters" + +// SecretListOptions holds parameters to list secrets +type SecretListOptions struct { + Filters filters.Args +} diff --git a/client/secret_list_test.go b/client/secret_list_test.go index c50e3ba4b6..a4b24ccfb1 100644 --- a/client/secret_list_test.go +++ b/client/secret_list_test.go @@ -22,7 +22,7 @@ func TestSecretListUnsupported(t *testing.T) { version: "1.24", client: &http.Client{}, } - _, err := client.SecretList(context.Background(), swarm.SecretListOptions{}) + _, err := client.SecretList(context.Background(), SecretListOptions{}) assert.Check(t, is.Error(err, `"secret list" requires API version 1.25, but the Docker daemon API version is 1.24`)) } @@ -32,7 +32,7 @@ func TestSecretListError(t *testing.T) { client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")), } - _, err := client.SecretList(context.Background(), swarm.SecretListOptions{}) + _, err := client.SecretList(context.Background(), SecretListOptions{}) assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal)) } @@ -40,17 +40,17 @@ func TestSecretList(t *testing.T) { const expectedURL = "/v1.25/secrets" listCases := []struct { - options swarm.SecretListOptions + options SecretListOptions expectedQueryParams map[string]string }{ { - options: swarm.SecretListOptions{}, + options: SecretListOptions{}, expectedQueryParams: map[string]string{ "filters": "", }, }, { - options: swarm.SecretListOptions{ + options: SecretListOptions{ Filters: filters.NewArgs( filters.Arg("label", "label1"), filters.Arg("label", "label2"), diff --git a/daemon/cluster/secrets.go b/daemon/cluster/secrets.go index bc5a6d6eee..f3f207fe39 100644 --- a/daemon/cluster/secrets.go +++ b/daemon/cluster/secrets.go @@ -5,6 +5,7 @@ import ( types "github.com/moby/moby/api/types/swarm" "github.com/moby/moby/v2/daemon/cluster/convert" + "github.com/moby/moby/v2/daemon/server/swarmbackend" swarmapi "github.com/moby/swarmkit/v2/api" "google.golang.org/grpc" ) @@ -27,7 +28,7 @@ func (c *Cluster) GetSecret(input string) (types.Secret, error) { } // GetSecrets returns all secrets of a managed swarm cluster. -func (c *Cluster) GetSecrets(options types.SecretListOptions) ([]types.Secret, error) { +func (c *Cluster) GetSecrets(options swarmbackend.SecretListOptions) ([]types.Secret, error) { c.mu.RLock() defer c.mu.RUnlock() diff --git a/daemon/server/router/swarm/backend.go b/daemon/server/router/swarm/backend.go index e6205e717d..c555bb63d9 100644 --- a/daemon/server/router/swarm/backend.go +++ b/daemon/server/router/swarm/backend.go @@ -30,7 +30,7 @@ type Backend interface { RemoveNode(string, bool) error GetTasks(swarmbackend.TaskListOptions) ([]swarm.Task, error) GetTask(string) (swarm.Task, error) - GetSecrets(opts swarm.SecretListOptions) ([]swarm.Secret, error) + GetSecrets(opts swarmbackend.SecretListOptions) ([]swarm.Secret, error) CreateSecret(s swarm.SecretSpec) (string, error) RemoveSecret(idOrName string) error GetSecret(id string) (swarm.Secret, error) diff --git a/daemon/server/router/swarm/cluster_routes.go b/daemon/server/router/swarm/cluster_routes.go index f597c705ae..e700db5cae 100644 --- a/daemon/server/router/swarm/cluster_routes.go +++ b/daemon/server/router/swarm/cluster_routes.go @@ -416,7 +416,7 @@ func (sr *swarmRouter) getSecrets(ctx context.Context, w http.ResponseWriter, r return err } - secrets, err := sr.backend.GetSecrets(types.SecretListOptions{Filters: filters}) + secrets, err := sr.backend.GetSecrets(swarmbackend.SecretListOptions{Filters: filters}) if err != nil { return err } diff --git a/daemon/server/swarmbackend/swarm.go b/daemon/server/swarmbackend/swarm.go index c850dea25b..3a1b5da159 100644 --- a/daemon/server/swarmbackend/swarm.go +++ b/daemon/server/swarmbackend/swarm.go @@ -50,3 +50,8 @@ type ServiceListOptions struct { // count of running and desired tasks. Status bool } + +// SecretListOptions holds parameters to list secrets +type SecretListOptions struct { + Filters filters.Args +} diff --git a/integration/secret/secret_test.go b/integration/secret/secret_test.go index 10d7d3d76a..721b3a5503 100644 --- a/integration/secret/secret_test.go +++ b/integration/secret/secret_test.go @@ -53,7 +53,7 @@ func TestSecretList(t *testing.T) { c := d.NewClientT(t) defer c.Close() - configs, err := c.SecretList(ctx, swarmtypes.SecretListOptions{}) + configs, err := c.SecretList(ctx, client.SecretListOptions{}) assert.NilError(t, err) assert.Check(t, is.Equal(len(configs), 0)) @@ -69,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, swarmtypes.SecretListOptions{}) + entries, err := c.SecretList(ctx, client.SecretListOptions{}) assert.NilError(t, err) assert.Check(t, is.DeepEqual(secretNamesFromList(entries), testNames)) @@ -102,7 +102,7 @@ func TestSecretList(t *testing.T) { }, } for _, tc := range testCases { - entries, err = c.SecretList(ctx, swarmtypes.SecretListOptions{ + entries, err = c.SecretList(ctx, client.SecretListOptions{ Filters: tc.filters, }) assert.NilError(t, err) @@ -356,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, swarmtypes.SecretListOptions{}) + entries, err := c.SecretList(ctx, client.SecretListOptions{}) assert.NilError(t, err) assert.Check(t, is.Contains(secretNamesFromList(entries), testName)) assert.Check(t, is.Contains(secretNamesFromList(entries), fakeName)) @@ -365,7 +365,7 @@ func TestSecretCreateResolve(t *testing.T) { assert.NilError(t, err) // Fake one will remain - entries, err = c.SecretList(ctx, swarmtypes.SecretListOptions{}) + entries, err = c.SecretList(ctx, client.SecretListOptions{}) assert.NilError(t, err) assert.Assert(t, is.DeepEqual(secretNamesFromList(entries), []string{fakeName})) @@ -376,14 +376,14 @@ func TestSecretCreateResolve(t *testing.T) { // - Partial ID (prefix) err = c.SecretRemove(ctx, fakeName[:5]) assert.Assert(t, err != nil) - entries, err = c.SecretList(ctx, swarmtypes.SecretListOptions{}) + entries, err = c.SecretList(ctx, client.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, swarmtypes.SecretListOptions{}) + entries, err = c.SecretList(ctx, client.SecretListOptions{}) assert.NilError(t, err) assert.Assert(t, is.Equal(0, len(entries))) } diff --git a/testutil/daemon/secret.go b/testutil/daemon/secret.go index 63884d83b1..7b9636cadd 100644 --- a/testutil/daemon/secret.go +++ b/testutil/daemon/secret.go @@ -5,6 +5,7 @@ import ( "testing" "github.com/moby/moby/api/types/swarm" + "github.com/moby/moby/client" "gotest.tools/v3/assert" ) @@ -29,7 +30,7 @@ func (d *Daemon) ListSecrets(t testing.TB) []swarm.Secret { cli := d.NewClientT(t) defer cli.Close() - secrets, err := cli.SecretList(context.Background(), swarm.SecretListOptions{}) + secrets, err := cli.SecretList(context.Background(), client.SecretListOptions{}) assert.NilError(t, err) return secrets } diff --git a/vendor/github.com/moby/moby/api/types/swarm/secret.go b/vendor/github.com/moby/moby/api/types/swarm/secret.go index 6fea600b42..0e27ed9b07 100644 --- a/vendor/github.com/moby/moby/api/types/swarm/secret.go +++ b/vendor/github.com/moby/moby/api/types/swarm/secret.go @@ -2,8 +2,6 @@ package swarm import ( "os" - - "github.com/moby/moby/api/types/filters" ) // Secret represents a secret. @@ -59,8 +57,3 @@ 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 -} diff --git a/vendor/github.com/moby/moby/client/client_interfaces.go b/vendor/github.com/moby/moby/client/client_interfaces.go index c686f535f5..c0831b9a3c 100644 --- a/vendor/github.com/moby/moby/client/client_interfaces.go +++ b/vendor/github.com/moby/moby/client/client_interfaces.go @@ -206,7 +206,7 @@ type VolumeAPIClient interface { // SecretAPIClient defines API client methods for secrets type SecretAPIClient interface { - SecretList(ctx context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error) + SecretList(ctx context.Context, options 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) diff --git a/vendor/github.com/moby/moby/client/secret_list.go b/vendor/github.com/moby/moby/client/secret_list.go index 2ed1997a0a..13879ba9f2 100644 --- a/vendor/github.com/moby/moby/client/secret_list.go +++ b/vendor/github.com/moby/moby/client/secret_list.go @@ -10,7 +10,7 @@ import ( ) // SecretList returns the list of secrets. -func (cli *Client) SecretList(ctx context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error) { +func (cli *Client) SecretList(ctx context.Context, options SecretListOptions) ([]swarm.Secret, error) { if err := cli.NewVersionError(ctx, "1.25", "secret list"); err != nil { return nil, err } diff --git a/vendor/github.com/moby/moby/client/secret_list_opts.go b/vendor/github.com/moby/moby/client/secret_list_opts.go new file mode 100644 index 0000000000..313eeefe39 --- /dev/null +++ b/vendor/github.com/moby/moby/client/secret_list_opts.go @@ -0,0 +1,8 @@ +package client + +import "github.com/moby/moby/api/types/filters" + +// SecretListOptions holds parameters to list secrets +type SecretListOptions struct { + Filters filters.Args +}