Browse code

api/types/swarm: move `SecretListOptions` type to client

Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>

Austin Vazquez authored on 2025/08/27 04:15:35
Showing 15 changed files
... ...
@@ -2,8 +2,6 @@ package swarm
2 2
 
3 3
 import (
4 4
 	"os"
5
-
6
-	"github.com/moby/moby/api/types/filters"
7 5
 )
8 6
 
9 7
 // Secret represents a secret.
... ...
@@ -59,8 +57,3 @@ type SecretCreateResponse struct {
59 59
 	// ID is the id of the created secret.
60 60
 	ID string
61 61
 }
62
-
63
-// SecretListOptions holds parameters to list secrets
64
-type SecretListOptions struct {
65
-	Filters filters.Args
66
-}
... ...
@@ -206,7 +206,7 @@ type VolumeAPIClient interface {
206 206
 
207 207
 // SecretAPIClient defines API client methods for secrets
208 208
 type SecretAPIClient interface {
209
-	SecretList(ctx context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error)
209
+	SecretList(ctx context.Context, options SecretListOptions) ([]swarm.Secret, error)
210 210
 	SecretCreate(ctx context.Context, secret swarm.SecretSpec) (swarm.SecretCreateResponse, error)
211 211
 	SecretRemove(ctx context.Context, id string) error
212 212
 	SecretInspectWithRaw(ctx context.Context, name string) (swarm.Secret, []byte, error)
... ...
@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 // SecretList returns the list of secrets.
13
-func (cli *Client) SecretList(ctx context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error) {
13
+func (cli *Client) SecretList(ctx context.Context, options SecretListOptions) ([]swarm.Secret, error) {
14 14
 	if err := cli.NewVersionError(ctx, "1.25", "secret list"); err != nil {
15 15
 		return nil, err
16 16
 	}
17 17
new file mode 100644
... ...
@@ -0,0 +1,8 @@
0
+package client
1
+
2
+import "github.com/moby/moby/api/types/filters"
3
+
4
+// SecretListOptions holds parameters to list secrets
5
+type SecretListOptions struct {
6
+	Filters filters.Args
7
+}
... ...
@@ -22,7 +22,7 @@ func TestSecretListUnsupported(t *testing.T) {
22 22
 		version: "1.24",
23 23
 		client:  &http.Client{},
24 24
 	}
25
-	_, err := client.SecretList(context.Background(), swarm.SecretListOptions{})
25
+	_, err := client.SecretList(context.Background(), SecretListOptions{})
26 26
 	assert.Check(t, is.Error(err, `"secret list" requires API version 1.25, but the Docker daemon API version is 1.24`))
27 27
 }
28 28
 
... ...
@@ -32,7 +32,7 @@ func TestSecretListError(t *testing.T) {
32 32
 		client:  newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
33 33
 	}
34 34
 
35
-	_, err := client.SecretList(context.Background(), swarm.SecretListOptions{})
35
+	_, err := client.SecretList(context.Background(), SecretListOptions{})
36 36
 	assert.Check(t, is.ErrorType(err, cerrdefs.IsInternal))
37 37
 }
38 38
 
... ...
@@ -40,17 +40,17 @@ func TestSecretList(t *testing.T) {
40 40
 	const expectedURL = "/v1.25/secrets"
41 41
 
42 42
 	listCases := []struct {
43
-		options             swarm.SecretListOptions
43
+		options             SecretListOptions
44 44
 		expectedQueryParams map[string]string
45 45
 	}{
46 46
 		{
47
-			options: swarm.SecretListOptions{},
47
+			options: SecretListOptions{},
48 48
 			expectedQueryParams: map[string]string{
49 49
 				"filters": "",
50 50
 			},
51 51
 		},
52 52
 		{
53
-			options: swarm.SecretListOptions{
53
+			options: SecretListOptions{
54 54
 				Filters: filters.NewArgs(
55 55
 					filters.Arg("label", "label1"),
56 56
 					filters.Arg("label", "label2"),
... ...
@@ -5,6 +5,7 @@ import (
5 5
 
6 6
 	types "github.com/moby/moby/api/types/swarm"
7 7
 	"github.com/moby/moby/v2/daemon/cluster/convert"
8
+	"github.com/moby/moby/v2/daemon/server/swarmbackend"
8 9
 	swarmapi "github.com/moby/swarmkit/v2/api"
9 10
 	"google.golang.org/grpc"
10 11
 )
... ...
@@ -27,7 +28,7 @@ func (c *Cluster) GetSecret(input string) (types.Secret, error) {
27 27
 }
28 28
 
29 29
 // GetSecrets returns all secrets of a managed swarm cluster.
30
-func (c *Cluster) GetSecrets(options types.SecretListOptions) ([]types.Secret, error) {
30
+func (c *Cluster) GetSecrets(options swarmbackend.SecretListOptions) ([]types.Secret, error) {
31 31
 	c.mu.RLock()
32 32
 	defer c.mu.RUnlock()
33 33
 
... ...
@@ -30,7 +30,7 @@ type Backend interface {
30 30
 	RemoveNode(string, bool) error
31 31
 	GetTasks(swarmbackend.TaskListOptions) ([]swarm.Task, error)
32 32
 	GetTask(string) (swarm.Task, error)
33
-	GetSecrets(opts swarm.SecretListOptions) ([]swarm.Secret, error)
33
+	GetSecrets(opts swarmbackend.SecretListOptions) ([]swarm.Secret, error)
34 34
 	CreateSecret(s swarm.SecretSpec) (string, error)
35 35
 	RemoveSecret(idOrName string) error
36 36
 	GetSecret(id string) (swarm.Secret, error)
... ...
@@ -416,7 +416,7 @@ func (sr *swarmRouter) getSecrets(ctx context.Context, w http.ResponseWriter, r
416 416
 		return err
417 417
 	}
418 418
 
419
-	secrets, err := sr.backend.GetSecrets(types.SecretListOptions{Filters: filters})
419
+	secrets, err := sr.backend.GetSecrets(swarmbackend.SecretListOptions{Filters: filters})
420 420
 	if err != nil {
421 421
 		return err
422 422
 	}
... ...
@@ -50,3 +50,8 @@ type ServiceListOptions struct {
50 50
 	// count of running and desired tasks.
51 51
 	Status bool
52 52
 }
53
+
54
+// SecretListOptions holds parameters to list secrets
55
+type SecretListOptions struct {
56
+	Filters filters.Args
57
+}
... ...
@@ -53,7 +53,7 @@ func TestSecretList(t *testing.T) {
53 53
 	c := d.NewClientT(t)
54 54
 	defer c.Close()
55 55
 
56
-	configs, err := c.SecretList(ctx, swarmtypes.SecretListOptions{})
56
+	configs, err := c.SecretList(ctx, client.SecretListOptions{})
57 57
 	assert.NilError(t, err)
58 58
 	assert.Check(t, is.Equal(len(configs), 0))
59 59
 
... ...
@@ -69,7 +69,7 @@ func TestSecretList(t *testing.T) {
69 69
 	secret1ID := createSecret(ctx, t, c, testName1, []byte("TESTINGDATA1"), map[string]string{"type": "production"})
70 70
 
71 71
 	// test by `secret ls`
72
-	entries, err := c.SecretList(ctx, swarmtypes.SecretListOptions{})
72
+	entries, err := c.SecretList(ctx, client.SecretListOptions{})
73 73
 	assert.NilError(t, err)
74 74
 	assert.Check(t, is.DeepEqual(secretNamesFromList(entries), testNames))
75 75
 
... ...
@@ -102,7 +102,7 @@ func TestSecretList(t *testing.T) {
102 102
 		},
103 103
 	}
104 104
 	for _, tc := range testCases {
105
-		entries, err = c.SecretList(ctx, swarmtypes.SecretListOptions{
105
+		entries, err = c.SecretList(ctx, client.SecretListOptions{
106 106
 			Filters: tc.filters,
107 107
 		})
108 108
 		assert.NilError(t, err)
... ...
@@ -356,7 +356,7 @@ func TestSecretCreateResolve(t *testing.T) {
356 356
 	fakeName := secretID
357 357
 	fakeID := createSecret(ctx, t, c, fakeName, []byte("fake foo"), nil)
358 358
 
359
-	entries, err := c.SecretList(ctx, swarmtypes.SecretListOptions{})
359
+	entries, err := c.SecretList(ctx, client.SecretListOptions{})
360 360
 	assert.NilError(t, err)
361 361
 	assert.Check(t, is.Contains(secretNamesFromList(entries), testName))
362 362
 	assert.Check(t, is.Contains(secretNamesFromList(entries), fakeName))
... ...
@@ -365,7 +365,7 @@ func TestSecretCreateResolve(t *testing.T) {
365 365
 	assert.NilError(t, err)
366 366
 
367 367
 	// Fake one will remain
368
-	entries, err = c.SecretList(ctx, swarmtypes.SecretListOptions{})
368
+	entries, err = c.SecretList(ctx, client.SecretListOptions{})
369 369
 	assert.NilError(t, err)
370 370
 	assert.Assert(t, is.DeepEqual(secretNamesFromList(entries), []string{fakeName}))
371 371
 
... ...
@@ -376,14 +376,14 @@ func TestSecretCreateResolve(t *testing.T) {
376 376
 	// - Partial ID (prefix)
377 377
 	err = c.SecretRemove(ctx, fakeName[:5])
378 378
 	assert.Assert(t, err != nil)
379
-	entries, err = c.SecretList(ctx, swarmtypes.SecretListOptions{})
379
+	entries, err = c.SecretList(ctx, client.SecretListOptions{})
380 380
 	assert.NilError(t, err)
381 381
 	assert.Assert(t, is.DeepEqual(secretNamesFromList(entries), []string{fakeName}))
382 382
 
383 383
 	// Remove based on ID prefix of the fake one should succeed
384 384
 	err = c.SecretRemove(ctx, fakeID[:5])
385 385
 	assert.NilError(t, err)
386
-	entries, err = c.SecretList(ctx, swarmtypes.SecretListOptions{})
386
+	entries, err = c.SecretList(ctx, client.SecretListOptions{})
387 387
 	assert.NilError(t, err)
388 388
 	assert.Assert(t, is.Equal(0, len(entries)))
389 389
 }
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"testing"
6 6
 
7 7
 	"github.com/moby/moby/api/types/swarm"
8
+	"github.com/moby/moby/client"
8 9
 	"gotest.tools/v3/assert"
9 10
 )
10 11
 
... ...
@@ -29,7 +30,7 @@ func (d *Daemon) ListSecrets(t testing.TB) []swarm.Secret {
29 29
 	cli := d.NewClientT(t)
30 30
 	defer cli.Close()
31 31
 
32
-	secrets, err := cli.SecretList(context.Background(), swarm.SecretListOptions{})
32
+	secrets, err := cli.SecretList(context.Background(), client.SecretListOptions{})
33 33
 	assert.NilError(t, err)
34 34
 	return secrets
35 35
 }
... ...
@@ -2,8 +2,6 @@ package swarm
2 2
 
3 3
 import (
4 4
 	"os"
5
-
6
-	"github.com/moby/moby/api/types/filters"
7 5
 )
8 6
 
9 7
 // Secret represents a secret.
... ...
@@ -59,8 +57,3 @@ type SecretCreateResponse struct {
59 59
 	// ID is the id of the created secret.
60 60
 	ID string
61 61
 }
62
-
63
-// SecretListOptions holds parameters to list secrets
64
-type SecretListOptions struct {
65
-	Filters filters.Args
66
-}
... ...
@@ -206,7 +206,7 @@ type VolumeAPIClient interface {
206 206
 
207 207
 // SecretAPIClient defines API client methods for secrets
208 208
 type SecretAPIClient interface {
209
-	SecretList(ctx context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error)
209
+	SecretList(ctx context.Context, options SecretListOptions) ([]swarm.Secret, error)
210 210
 	SecretCreate(ctx context.Context, secret swarm.SecretSpec) (swarm.SecretCreateResponse, error)
211 211
 	SecretRemove(ctx context.Context, id string) error
212 212
 	SecretInspectWithRaw(ctx context.Context, name string) (swarm.Secret, []byte, error)
... ...
@@ -10,7 +10,7 @@ import (
10 10
 )
11 11
 
12 12
 // SecretList returns the list of secrets.
13
-func (cli *Client) SecretList(ctx context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error) {
13
+func (cli *Client) SecretList(ctx context.Context, options SecretListOptions) ([]swarm.Secret, error) {
14 14
 	if err := cli.NewVersionError(ctx, "1.25", "secret list"); err != nil {
15 15
 		return nil, err
16 16
 	}
17 17
new file mode 100644
... ...
@@ -0,0 +1,8 @@
0
+package client
1
+
2
+import "github.com/moby/moby/api/types/filters"
3
+
4
+// SecretListOptions holds parameters to list secrets
5
+type SecretListOptions struct {
6
+	Filters filters.Args
7
+}