Skip to content

Commit

Permalink
Remove ClientInfo as it is not practically used.
Browse files Browse the repository at this point in the history
The information in this struct was basically fixed (there's
some discrepancy around the "DefaultVersion" which, probably,
should never vary, and always be set to the Default (maximum)
API version supported by the client.

Experimental is now always enabled, so this information did
not require any dynamic info as well.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
  • Loading branch information
thaJeztah committed Mar 4, 2022
1 parent c61452c commit 257f614
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 59 deletions.
43 changes: 2 additions & 41 deletions cli/command/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ type Cli interface {
Apply(ops ...DockerCliOption) error
ConfigFile() *configfile.ConfigFile
ServerInfo() ServerInfo
ClientInfo() ClientInfo
NotaryClient(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error)
DefaultVersion() string
ManifestStore() manifeststore.Store
Expand All @@ -73,17 +72,16 @@ type DockerCli struct {
err io.Writer
client client.APIClient
serverInfo ServerInfo
clientInfo *ClientInfo
contentTrust bool
contextStore store.Store
currentContext string
dockerEndpoint docker.Endpoint
contextStoreConfig store.Config
}

// DefaultVersion returns api.defaultVersion or DOCKER_API_VERSION if specified.
// DefaultVersion returns api.defaultVersion.
func (cli *DockerCli) DefaultVersion() string {
return cli.ClientInfo().DefaultVersion
return api.DefaultVersion
}

// Client returns the APIClient
Expand Down Expand Up @@ -138,30 +136,6 @@ func (cli *DockerCli) ServerInfo() ServerInfo {
return cli.serverInfo
}

// ClientInfo returns the client details for the cli
func (cli *DockerCli) ClientInfo() ClientInfo {
if cli.clientInfo == nil {
if err := cli.loadClientInfo(); err != nil {
panic(err)
}
}
return *cli.clientInfo
}

func (cli *DockerCli) loadClientInfo() error {
var v string
if cli.client != nil {
v = cli.client.ClientVersion()
} else {
v = api.DefaultVersion
}
cli.clientInfo = &ClientInfo{
DefaultVersion: v,
HasExperimental: true,
}
return nil
}

// ContentTrustEnabled returns whether content trust has been enabled by an
// environment variable.
func (cli *DockerCli) ContentTrustEnabled() bool {
Expand Down Expand Up @@ -260,11 +234,6 @@ func (cli *DockerCli) Initialize(opts *cliflags.ClientOptions, ops ...Initialize
}
}
cli.initializeFromClient()

if err := cli.loadClientInfo(); err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -410,14 +379,6 @@ type ServerInfo struct {
BuildkitVersion types.BuilderVersion
}

// ClientInfo stores details about the supported features of the client
type ClientInfo struct {
// Deprecated: experimental CLI features always enabled. This field is kept
// for backward-compatibility, and is always "true".
HasExperimental bool
DefaultVersion string
}

// NewDockerCli returns a DockerCli instance with all operators applied on it.
// It applies by default the standard streams, and the content trust from
// environment.
Expand Down
2 changes: 0 additions & 2 deletions cli/command/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,6 @@ func TestExperimentalCLI(t *testing.T) {
cliconfig.SetDir(dir.Path())
err := cli.Initialize(flags.NewClientOptions())
assert.NilError(t, err)
// For backward-compatibility, HasExperimental will always be "true"
assert.Equal(t, cli.ClientInfo().HasExperimental, true)
})
}
}
Expand Down
1 change: 0 additions & 1 deletion cmd/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,6 @@ func main() {

type versionDetails interface {
Client() client.APIClient
ClientInfo() command.ClientInfo
ServerInfo() command.ServerInfo
}

Expand Down
15 changes: 0 additions & 15 deletions internal/test/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (

// NotaryClientFuncType defines a function that returns a fake notary client
type NotaryClientFuncType func(imgRefAndAuth trust.ImageRefAndAuth, actions []string) (notaryclient.Repository, error)
type clientInfoFuncType func() command.ClientInfo

// FakeCli emulates the default DockerCli
type FakeCli struct {
Expand All @@ -32,7 +31,6 @@ type FakeCli struct {
err *bytes.Buffer
in *streams.In
server command.ServerInfo
clientInfoFunc clientInfoFuncType
notaryClientFunc NotaryClientFuncType
manifestStore manifeststore.Store
registryClient registryclient.RegistryClient
Expand Down Expand Up @@ -143,19 +141,6 @@ func (c *FakeCli) ServerInfo() command.ServerInfo {
return c.server
}

// ClientInfo returns client information
func (c *FakeCli) ClientInfo() command.ClientInfo {
if c.clientInfoFunc != nil {
return c.clientInfoFunc()
}
return c.DockerCli.ClientInfo()
}

// SetClientInfo sets the internal getter for retrieving a ClientInfo
func (c *FakeCli) SetClientInfo(clientInfoFunc clientInfoFuncType) {
c.clientInfoFunc = clientInfoFunc
}

// OutBuffer returns the stdout buffer
func (c *FakeCli) OutBuffer() *bytes.Buffer {
return c.outBuffer
Expand Down

0 comments on commit 257f614

Please sign in to comment.