Skip to content

Commit 7d9c50d

Browse files
committed
api: /info: omit non-distributable-artifacts fields for API >= 1.49
- registry.ServiceConfig: add a "ExtraFields" for outputting deprecated fields. - remove uses of AllowNondistributableArtifactsCIDRs and AllowNondistributableArtifactsHostnames Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
1 parent ebc6c06 commit 7d9c50d

File tree

5 files changed

+34
-41
lines changed

5 files changed

+34
-41
lines changed

api/server/router/system/system_routes.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.22
3+
14
package system // import "github.com/docker/docker/api/server/router/system"
25

36
import (
@@ -103,8 +106,10 @@ func (s *systemRouter) getInfo(ctx context.Context, w http.ResponseWriter, r *ht
103106
if versions.LessThan(version, "1.47") {
104107
// Field is omitted in API 1.48 and up, but should still be included
105108
// in older versions, even if no values are set.
106-
info.RegistryConfig.AllowNondistributableArtifactsCIDRs = []*registry.NetIPNet{}
107-
info.RegistryConfig.AllowNondistributableArtifactsHostnames = []string{}
109+
info.RegistryConfig.ExtraFields = map[string]any{
110+
"AllowNondistributableArtifactsCIDRs": json.RawMessage(nil),
111+
"AllowNondistributableArtifactsHostnames": json.RawMessage(nil),
112+
}
108113
}
109114
if versions.LessThan(version, "1.49") {
110115
// FirewallBackend field introduced in API v1.49.

api/swagger.yaml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7017,32 +7017,6 @@ definitions:
70177017
type: "object"
70187018
x-nullable: true
70197019
properties:
7020-
AllowNondistributableArtifactsCIDRs:
7021-
description: |
7022-
List of IP ranges to which nondistributable artifacts can be pushed,
7023-
using the CIDR syntax [RFC 4632](https://tools.ietf.org/html/4632).
7024-
7025-
<p><br /></p>
7026-
7027-
> **Deprecated**: Pushing nondistributable artifacts is now always enabled
7028-
> and this field is always `null`. This field will be removed in a API v1.49.
7029-
type: "array"
7030-
items:
7031-
type: "string"
7032-
example: []
7033-
AllowNondistributableArtifactsHostnames:
7034-
description: |
7035-
List of registry hostnames to which nondistributable artifacts can be
7036-
pushed, using the format `<hostname>[:<port>]` or `<IP address>[:<port>]`.
7037-
7038-
<p><br /></p>
7039-
7040-
> **Deprecated**: Pushing nondistributable artifacts is now always enabled
7041-
> and this field is always `null`. This field will be removed in a API v1.49.
7042-
type: "array"
7043-
items:
7044-
type: "string"
7045-
example: []
70467020
InsecureRegistryCIDRs:
70477021
description: |
70487022
List of IP ranges of insecure registries, using the CIDR syntax

api/types/registry/registry.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.22
3+
14
package registry // import "github.com/docker/docker/api/types/registry"
25

36
import (
@@ -15,23 +18,26 @@ type ServiceConfig struct {
1518
InsecureRegistryCIDRs []*NetIPNet `json:"InsecureRegistryCIDRs"`
1619
IndexConfigs map[string]*IndexInfo `json:"IndexConfigs"`
1720
Mirrors []string
21+
22+
// ExtraFields is for internal use to include deprecated fields on older API versions.
23+
ExtraFields map[string]any `json:"-"`
1824
}
1925

2026
// MarshalJSON implements a custom marshaler to include legacy fields
2127
// in API responses.
22-
func (sc ServiceConfig) MarshalJSON() ([]byte, error) {
23-
tmp := map[string]interface{}{
24-
"InsecureRegistryCIDRs": sc.InsecureRegistryCIDRs,
25-
"IndexConfigs": sc.IndexConfigs,
26-
"Mirrors": sc.Mirrors,
27-
}
28-
if sc.AllowNondistributableArtifactsCIDRs != nil {
29-
tmp["AllowNondistributableArtifactsCIDRs"] = nil
28+
func (sc *ServiceConfig) MarshalJSON() ([]byte, error) {
29+
type tmp ServiceConfig
30+
base, err := json.Marshal((*tmp)(sc))
31+
if err != nil {
32+
return nil, err
3033
}
31-
if sc.AllowNondistributableArtifactsHostnames != nil {
32-
tmp["AllowNondistributableArtifactsHostnames"] = nil
34+
var merged map[string]any
35+
_ = json.Unmarshal(base, &merged)
36+
37+
for k, v := range sc.ExtraFields {
38+
merged[k] = v
3339
}
34-
return json.Marshal(tmp)
40+
return json.Marshal(merged)
3541
}
3642

3743
// NetIPNet is the net.IPNet type, which can be marshalled and

api/types/registry/registry_test.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
2+
//go:build go1.22
3+
14
package registry
25

36
import (
@@ -20,8 +23,10 @@ func TestServiceConfigMarshalLegacyFields(t *testing.T) {
2023
// used for API versions < 1.49.
2124
t.Run("with legacy fields", func(t *testing.T) {
2225
b, err := json.Marshal(&ServiceConfig{
23-
AllowNondistributableArtifactsCIDRs: []*NetIPNet{},
24-
AllowNondistributableArtifactsHostnames: []string{},
26+
ExtraFields: map[string]any{
27+
"AllowNondistributableArtifactsCIDRs": json.RawMessage(nil),
28+
"AllowNondistributableArtifactsHostnames": json.RawMessage(nil),
29+
},
2530
})
2631
assert.NilError(t, err)
2732
const expected = `{"AllowNondistributableArtifactsCIDRs":null,"AllowNondistributableArtifactsHostnames":null,"IndexConfigs":null,"InsecureRegistryCIDRs":null,"Mirrors":null}`

docs/api/version-history.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ keywords: "API, Docker, rcli, REST, documentation"
2323
This option is mutually exclusive with the `manifests` option.
2424
* `GET /info` now returns a `FirewallBackend` containing information about
2525
the daemon's firewalling configuration.
26+
* Deprecated: The `AllowNondistributableArtifactsCIDRs` and `AllowNondistributableArtifactsHostnames`
27+
fields in the `RegistryConfig` struct in the `GET /info` response are omitted
28+
in API v1.49.
2629

2730
## v1.48 API changes
2831

0 commit comments

Comments
 (0)