mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
The `BridgeNfIptables` and `BridgeNfIp6tables` fields in the
`GET /info` response were deprecated in API v1.48, and are now omitted
in API v1.50.
With this patch, old API version continue to return the field:
curl -s --unix-socket /var/run/docker.sock http://localhost/v1.48/info | jq .BridgeNfIp6tables
false
curl -s --unix-socket /var/run/docker.sock http://localhost/v1.48/info | jq .BridgeNfIptables
false
Omitting the field in API v1.50 and above
curl -s --unix-socket /var/run/docker.sock http://localhost/v1.50/info | jq .BridgeNfIp6tables
null
curl -s --unix-socket /var/run/docker.sock http://localhost/v1.50/info | jq .BridgeNfIptables
null
This reverts commit eacbbdeec6, and re-applies
a variant of 5d2006256f
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
40 lines
957 B
Go
40 lines
957 B
Go
// FIXME(thaJeztah): remove once we are a module; the go:build directive prevents go from downgrading language version to go1.16:
|
|
//go:build go1.23
|
|
|
|
package system
|
|
|
|
import (
|
|
"encoding/json"
|
|
|
|
"github.com/docker/docker/api/types/system"
|
|
)
|
|
|
|
// infoResponse is a wrapper around [system.Info] with a custom
|
|
// marshal function for legacy fields.
|
|
type infoResponse struct {
|
|
*system.Info
|
|
|
|
// extraFields is for internal use to include deprecated fields on older API versions.
|
|
extraFields map[string]any
|
|
}
|
|
|
|
// MarshalJSON implements a custom marshaler to include legacy fields
|
|
// in API responses.
|
|
func (sc *infoResponse) MarshalJSON() ([]byte, error) {
|
|
type tmp *system.Info
|
|
base, err := json.Marshal((tmp)(sc.Info))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(sc.extraFields) == 0 {
|
|
return base, nil
|
|
}
|
|
var merged map[string]any
|
|
_ = json.Unmarshal(base, &merged)
|
|
|
|
for k, v := range sc.extraFields {
|
|
merged[k] = v
|
|
}
|
|
return json.Marshal(merged)
|
|
}
|