mirror of
https://github.com/moby/moby.git
synced 2026-08-03 22:51:03 +00:00
Merge pull request #50737 from thaJeztah/28.x_backport_client_remove_getDockerOS
[28.x backport] client: remove getDockerOS utility in favor of "Ostype" header
This commit is contained in:
@@ -28,7 +28,7 @@ func (cli *Client) ContainerStats(ctx context.Context, containerID string, strea
|
||||
|
||||
return container.StatsResponseReader{
|
||||
Body: resp.Body,
|
||||
OSType: getDockerOS(resp.Header.Get("Server")),
|
||||
OSType: resp.Header.Get("Ostype"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -51,6 +51,6 @@ func (cli *Client) ContainerStatsOneShot(ctx context.Context, containerID string
|
||||
|
||||
return container.StatsResponseReader{
|
||||
Body: resp.Body,
|
||||
OSType: getDockerOS(resp.Header.Get("Server")),
|
||||
OSType: resp.Header.Get("Ostype"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func (cli *Client) ImageBuild(ctx context.Context, buildContext io.Reader, optio
|
||||
|
||||
return build.ImageBuildResponse{
|
||||
Body: resp.Body,
|
||||
OSType: getDockerOS(resp.Header.Get("Server")),
|
||||
OSType: resp.Header.Get("Ostype"),
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -191,7 +191,7 @@ func TestImageBuild(t *testing.T) {
|
||||
}
|
||||
|
||||
headers := http.Header{}
|
||||
headers.Add("Server", "Docker/v1.23 (MyOS)")
|
||||
headers.Add("Ostype", "MyOS")
|
||||
return &http.Response{
|
||||
StatusCode: http.StatusOK,
|
||||
Body: io.NopCloser(bytes.NewReader([]byte("body"))),
|
||||
@@ -208,15 +208,3 @@ func TestImageBuild(t *testing.T) {
|
||||
assert.Check(t, is.Equal(string(response), "body"))
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetDockerOS(t *testing.T) {
|
||||
cases := map[string]string{
|
||||
"Docker/v1.22 (linux)": "linux",
|
||||
"Docker/v1.22 (windows)": "windows",
|
||||
"Foo/v1.22 (bar)": "",
|
||||
}
|
||||
for header, os := range cases {
|
||||
g := getDockerOS(header)
|
||||
assert.Check(t, is.Equal(g, os))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,9 @@ import (
|
||||
|
||||
cerrdefs "github.com/containerd/errdefs"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/internal/lazyregexp"
|
||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
||||
)
|
||||
|
||||
var headerRegexp = lazyregexp.New(`\ADocker/.+\s\((.+)\)\z`)
|
||||
|
||||
type emptyIDError string
|
||||
|
||||
func (e emptyIDError) InvalidParameter() {}
|
||||
@@ -31,16 +28,6 @@ func trimID(objType, id string) (string, error) {
|
||||
return id, nil
|
||||
}
|
||||
|
||||
// getDockerOS returns the operating system based on the server header from the daemon.
|
||||
func getDockerOS(serverHeader string) string {
|
||||
var osType string
|
||||
matches := headerRegexp.FindStringSubmatch(serverHeader)
|
||||
if len(matches) > 0 {
|
||||
osType = matches[1]
|
||||
}
|
||||
return osType
|
||||
}
|
||||
|
||||
// getFiltersQuery returns a url query with "filters" query term, based on the
|
||||
// filters provided.
|
||||
func getFiltersQuery(f filters.Args) (url.Values, error) {
|
||||
|
||||
Reference in New Issue
Block a user