Skip to content

Commit 6866b36

Browse files
committed
Add workaround to keep docker hosts structs private
Signed-off-by: Maksym Pavlenko <[email protected]>
1 parent 9e19a29 commit 6866b36

1 file changed

Lines changed: 15 additions & 18 deletions

File tree

remotes/docker/config/hosts.go

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -275,9 +275,7 @@ func loadHostDir(ctx context.Context, hostsDir string) ([]hostConfig, error) {
275275
return hosts, nil
276276
}
277277

278-
// HostFileConfig describes a single host section within TOML file.
279-
// Note: This struct needs to be public in order to be properly deserialized by TOML library.
280-
type HostFileConfig struct {
278+
type hostFileConfig struct {
281279
// Capabilities determine what operations a host is
282280
// capable of performing. Allowed values
283281
// - pull
@@ -300,27 +298,26 @@ type HostFileConfig struct {
300298
// Credentials: helper? name? username? alternate domain? token?
301299
}
302300

303-
type configFile struct {
304-
// hostConfig holds defaults for all hosts as well as
305-
// for the default server
306-
HostFileConfig
307-
308-
// Server specifies the default server. When `host` is
309-
// also specified, those hosts are tried first.
310-
Server string `toml:"server"`
311-
312-
// HostConfigs store the per-host configuration
313-
HostConfigs map[string]HostFileConfig `toml:"host"`
314-
}
315-
316301
func parseHostsFile(baseDir string, b []byte) ([]hostConfig, error) {
317302
tree, err := toml.LoadBytes(b)
318303
if err != nil {
319304
return nil, errors.Wrap(err, "failed to parse TOML")
320305
}
321306

307+
// HACK: we want to keep toml parsing structures private in this package, however go-toml ignores private embedded types.
308+
// so we remap it to a public type within the func body, so technically it's public, but not possible to import elsewhere.
309+
type HostFileConfig = hostFileConfig
310+
311+
c := struct {
312+
HostFileConfig
313+
// Server specifies the default server. When `host` is
314+
// also specified, those hosts are tried first.
315+
Server string `toml:"server"`
316+
// HostConfigs store the per-host configuration
317+
HostConfigs map[string]hostFileConfig `toml:"host"`
318+
}{}
319+
322320
var (
323-
c configFile
324321
hosts []hostConfig
325322
)
326323

@@ -347,7 +344,7 @@ func parseHostsFile(baseDir string, b []byte) ([]hostConfig, error) {
347344
return hosts, nil
348345
}
349346

350-
func parseHostConfig(server string, baseDir string, config HostFileConfig) (hostConfig, error) {
347+
func parseHostConfig(server string, baseDir string, config hostFileConfig) (hostConfig, error) {
351348
var (
352349
result = hostConfig{}
353350
err error

0 commit comments

Comments
 (0)