Skip to content

Commit 23117af

Browse files
committed
api/types: move SecretCreateResponse, SecretListOptions to types/swarm
Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 94e8416 commit 23117af

13 files changed

Lines changed: 54 additions & 45 deletions

File tree

api/server/router/swarm/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type Backend interface {
3030
RemoveNode(string, bool) error
3131
GetTasks(types.TaskListOptions) ([]swarm.Task, error)
3232
GetTask(string) (swarm.Task, error)
33-
GetSecrets(opts types.SecretListOptions) ([]swarm.Secret, error)
33+
GetSecrets(opts swarm.SecretListOptions) ([]swarm.Secret, error)
3434
CreateSecret(s swarm.SecretSpec) (string, error)
3535
RemoveSecret(idOrName string) error
3636
GetSecret(id string) (swarm.Secret, error)

api/server/router/swarm/cluster_routes.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ func (sr *swarmRouter) getSecrets(ctx context.Context, w http.ResponseWriter, r
416416
return err
417417
}
418418

419-
secrets, err := sr.backend.GetSecrets(basictypes.SecretListOptions{Filters: filters})
419+
secrets, err := sr.backend.GetSecrets(types.SecretListOptions{Filters: filters})
420420
if err != nil {
421421
return err
422422
}
@@ -439,7 +439,7 @@ func (sr *swarmRouter) createSecret(ctx context.Context, w http.ResponseWriter,
439439
return err
440440
}
441441

442-
return httputils.WriteJSON(w, http.StatusCreated, &basictypes.SecretCreateResponse{
442+
return httputils.WriteJSON(w, http.StatusCreated, &types.SecretCreateResponse{
443443
ID: id,
444444
})
445445
}

api/types/swarm/secret.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package swarm // import "github.com/docker/docker/api/types/swarm"
22

3-
import "os"
3+
import (
4+
"os"
5+
6+
"github.com/docker/docker/api/types/filters"
7+
)
48

59
// Secret represents a secret.
610
type Secret struct {
@@ -48,3 +52,15 @@ type SecretReference struct {
4852
SecretID string
4953
SecretName string
5054
}
55+
56+
// SecretCreateResponse contains the information returned to a client
57+
// on the creation of a new secret.
58+
type SecretCreateResponse struct {
59+
// ID is the id of the created secret.
60+
ID string
61+
}
62+
63+
// SecretListOptions holds parameters to list secrets
64+
type SecretListOptions struct {
65+
Filters filters.Args
66+
}

api/types/types.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,18 +94,6 @@ type DiskUsage struct {
9494
BuilderSize int64 `json:",omitempty"` // Deprecated: deprecated in API 1.38, and no longer used since API 1.40.
9595
}
9696

97-
// SecretCreateResponse contains the information returned to a client
98-
// on the creation of a new secret.
99-
type SecretCreateResponse struct {
100-
// ID is the id of the created secret.
101-
ID string
102-
}
103-
104-
// SecretListOptions holds parameters to list secrets
105-
type SecretListOptions struct {
106-
Filters filters.Args
107-
}
108-
10997
// ConfigCreateResponse contains the information returned to a client
11098
// on the creation of a new config.
11199
type ConfigCreateResponse struct {

api/types/types_deprecated.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/docker/docker/api/types/container"
99
"github.com/docker/docker/api/types/image"
1010
"github.com/docker/docker/api/types/storage"
11+
"github.com/docker/docker/api/types/swarm"
1112
)
1213

1314
// IDResponse Response to an API call that returns just an Id.
@@ -115,6 +116,17 @@ type ImageInspect = image.InspectResponse
115116
// Deprecated: moved to [github.com/docker/docker/api/types/registry.RequestAuthConfig].
116117
type RequestPrivilegeFunc func(context.Context) (string, error)
117118

119+
// SecretCreateResponse contains the information returned to a client
120+
// on the creation of a new secret.
121+
//
122+
// Deprecated: use [swarm.SecretCreateResponse].
123+
type SecretCreateResponse = swarm.SecretCreateResponse
124+
125+
// SecretListOptions holds parameters to list secrets
126+
//
127+
// Deprecated: use [swarm.SecretListOptions].
128+
type SecretListOptions = swarm.SecretListOptions
129+
118130
// BuildCache contains information about a build cache record.
119131
//
120132
// Deprecated: deprecated in API 1.49. Use [build.CacheRecord] instead.

client/client_interfaces.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ type VolumeAPIClient interface {
220220

221221
// SecretAPIClient defines API client methods for secrets
222222
type SecretAPIClient interface {
223-
SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error)
224-
SecretCreate(ctx context.Context, secret swarm.SecretSpec) (types.SecretCreateResponse, error)
223+
SecretList(ctx context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error)
224+
SecretCreate(ctx context.Context, secret swarm.SecretSpec) (swarm.SecretCreateResponse, error)
225225
SecretRemove(ctx context.Context, id string) error
226226
SecretInspectWithRaw(ctx context.Context, name string) (swarm.Secret, []byte, error)
227227
SecretUpdate(ctx context.Context, id string, version swarm.Version, secret swarm.SecretSpec) error

client/secret_create.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@ import (
44
"context"
55
"encoding/json"
66

7-
"github.com/docker/docker/api/types"
87
"github.com/docker/docker/api/types/swarm"
98
)
109

1110
// SecretCreate creates a new secret.
12-
func (cli *Client) SecretCreate(ctx context.Context, secret swarm.SecretSpec) (types.SecretCreateResponse, error) {
11+
func (cli *Client) SecretCreate(ctx context.Context, secret swarm.SecretSpec) (swarm.SecretCreateResponse, error) {
1312
if err := cli.NewVersionError(ctx, "1.25", "secret create"); err != nil {
14-
return types.SecretCreateResponse{}, err
13+
return swarm.SecretCreateResponse{}, err
1514
}
1615
resp, err := cli.post(ctx, "/secrets/create", nil, secret, nil)
1716
defer ensureReaderClosed(resp)
1817
if err != nil {
19-
return types.SecretCreateResponse{}, err
18+
return swarm.SecretCreateResponse{}, err
2019
}
2120

22-
var response types.SecretCreateResponse
21+
var response swarm.SecretCreateResponse
2322
err = json.NewDecoder(resp.Body).Decode(&response)
2423
return response, err
2524
}

client/secret_create_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"github.com/docker/docker/api/types"
1413
"github.com/docker/docker/api/types/swarm"
1514
"github.com/docker/docker/errdefs"
1615
"gotest.tools/v3/assert"
@@ -46,7 +45,7 @@ func TestSecretCreate(t *testing.T) {
4645
if req.Method != http.MethodPost {
4746
return nil, fmt.Errorf("expected POST method, got %s", req.Method)
4847
}
49-
b, err := json.Marshal(types.SecretCreateResponse{
48+
b, err := json.Marshal(swarm.SecretCreateResponse{
5049
ID: "test_secret",
5150
})
5251
if err != nil {

client/secret_list.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import (
55
"encoding/json"
66
"net/url"
77

8-
"github.com/docker/docker/api/types"
98
"github.com/docker/docker/api/types/filters"
109
"github.com/docker/docker/api/types/swarm"
1110
)
1211

1312
// SecretList returns the list of secrets.
14-
func (cli *Client) SecretList(ctx context.Context, options types.SecretListOptions) ([]swarm.Secret, error) {
13+
func (cli *Client) SecretList(ctx context.Context, options swarm.SecretListOptions) ([]swarm.Secret, error) {
1514
if err := cli.NewVersionError(ctx, "1.25", "secret list"); err != nil {
1615
return nil, err
1716
}

client/secret_list_test.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strings"
1111
"testing"
1212

13-
"github.com/docker/docker/api/types"
1413
"github.com/docker/docker/api/types/filters"
1514
"github.com/docker/docker/api/types/swarm"
1615
"github.com/docker/docker/errdefs"
@@ -23,7 +22,7 @@ func TestSecretListUnsupported(t *testing.T) {
2322
version: "1.24",
2423
client: &http.Client{},
2524
}
26-
_, err := client.SecretList(context.Background(), types.SecretListOptions{})
25+
_, err := client.SecretList(context.Background(), swarm.SecretListOptions{})
2726
assert.Check(t, is.Error(err, `"secret list" requires API version 1.25, but the Docker daemon API version is 1.24`))
2827
}
2928

@@ -33,25 +32,25 @@ func TestSecretListError(t *testing.T) {
3332
client: newMockClient(errorMock(http.StatusInternalServerError, "Server error")),
3433
}
3534

36-
_, err := client.SecretList(context.Background(), types.SecretListOptions{})
35+
_, err := client.SecretList(context.Background(), swarm.SecretListOptions{})
3736
assert.Check(t, is.ErrorType(err, errdefs.IsSystem))
3837
}
3938

4039
func TestSecretList(t *testing.T) {
4140
const expectedURL = "/v1.25/secrets"
4241

4342
listCases := []struct {
44-
options types.SecretListOptions
43+
options swarm.SecretListOptions
4544
expectedQueryParams map[string]string
4645
}{
4746
{
48-
options: types.SecretListOptions{},
47+
options: swarm.SecretListOptions{},
4948
expectedQueryParams: map[string]string{
5049
"filters": "",
5150
},
5251
},
5352
{
54-
options: types.SecretListOptions{
53+
options: swarm.SecretListOptions{
5554
Filters: filters.NewArgs(
5655
filters.Arg("label", "label1"),
5756
filters.Arg("label", "label2"),

0 commit comments

Comments
 (0)