Add workaround to keep docker hosts structs private
Signed-off-by: Maksym Pavlenko <pavlenko.maksym@gmail.com>
This commit is contained in:
parent
9e19a29847
commit
6866b36ab6
@ -275,9 +275,7 @@ func loadHostDir(ctx context.Context, hostsDir string) ([]hostConfig, error) {
|
|||||||
return hosts, nil
|
return hosts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// HostFileConfig describes a single host section within TOML file.
|
type hostFileConfig struct {
|
||||||
// Note: This struct needs to be public in order to be properly deserialized by TOML library.
|
|
||||||
type HostFileConfig struct {
|
|
||||||
// Capabilities determine what operations a host is
|
// Capabilities determine what operations a host is
|
||||||
// capable of performing. Allowed values
|
// capable of performing. Allowed values
|
||||||
// - pull
|
// - pull
|
||||||
@ -300,27 +298,26 @@ type HostFileConfig struct {
|
|||||||
// Credentials: helper? name? username? alternate domain? token?
|
// Credentials: helper? name? username? alternate domain? token?
|
||||||
}
|
}
|
||||||
|
|
||||||
type configFile struct {
|
|
||||||
// hostConfig holds defaults for all hosts as well as
|
|
||||||
// for the default server
|
|
||||||
HostFileConfig
|
|
||||||
|
|
||||||
// Server specifies the default server. When `host` is
|
|
||||||
// also specified, those hosts are tried first.
|
|
||||||
Server string `toml:"server"`
|
|
||||||
|
|
||||||
// HostConfigs store the per-host configuration
|
|
||||||
HostConfigs map[string]HostFileConfig `toml:"host"`
|
|
||||||
}
|
|
||||||
|
|
||||||
func parseHostsFile(baseDir string, b []byte) ([]hostConfig, error) {
|
func parseHostsFile(baseDir string, b []byte) ([]hostConfig, error) {
|
||||||
tree, err := toml.LoadBytes(b)
|
tree, err := toml.LoadBytes(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "failed to parse TOML")
|
return nil, errors.Wrap(err, "failed to parse TOML")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HACK: we want to keep toml parsing structures private in this package, however go-toml ignores private embedded types.
|
||||||
|
// so we remap it to a public type within the func body, so technically it's public, but not possible to import elsewhere.
|
||||||
|
type HostFileConfig = hostFileConfig
|
||||||
|
|
||||||
|
c := struct {
|
||||||
|
HostFileConfig
|
||||||
|
// Server specifies the default server. When `host` is
|
||||||
|
// also specified, those hosts are tried first.
|
||||||
|
Server string `toml:"server"`
|
||||||
|
// HostConfigs store the per-host configuration
|
||||||
|
HostConfigs map[string]hostFileConfig `toml:"host"`
|
||||||
|
}{}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
c configFile
|
|
||||||
hosts []hostConfig
|
hosts []hostConfig
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -347,7 +344,7 @@ func parseHostsFile(baseDir string, b []byte) ([]hostConfig, error) {
|
|||||||
return hosts, nil
|
return hosts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseHostConfig(server string, baseDir string, config HostFileConfig) (hostConfig, error) {
|
func parseHostConfig(server string, baseDir string, config hostFileConfig) (hostConfig, error) {
|
||||||
var (
|
var (
|
||||||
result = hostConfig{}
|
result = hostConfig{}
|
||||||
err error
|
err error
|
||||||
|
Loading…
Reference in New Issue
Block a user