-
Notifications
You must be signed in to change notification settings - Fork 19
/
default.go
36 lines (31 loc) · 1.13 KB
/
default.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package dockerconfig
import (
dockercli "github.com/docker/cli/cli/config"
"github.com/mandelsoft/filepath/pkg/filepath"
"github.com/mandelsoft/goutils/errors"
"github.com/mandelsoft/vfs/pkg/osfs"
"github.com/mandelsoft/vfs/pkg/vfs"
"github.com/open-component-model/ocm/pkg/contexts/config"
credcfg "github.com/open-component-model/ocm/pkg/contexts/credentials/config"
"github.com/open-component-model/ocm/pkg/contexts/ocm/utils/defaultconfigregistry"
)
func init() {
defaultconfigregistry.RegisterDefaultConfigHandler(DefaultConfigHandler, desc)
}
func DefaultConfigHandler(cfg config.Context) error {
// use docker config as default config for ocm cli
d := filepath.Join(dockercli.Dir(), dockercli.ConfigFileName)
if ok, err := vfs.FileExists(osfs.New(), d); ok && err == nil {
ccfg := credcfg.New()
ccfg.AddRepository(NewRepositorySpec(d, true))
err = cfg.ApplyConfig(ccfg, d)
if err != nil {
return errors.Wrapf(err, "cannot apply docker config %q", d)
}
}
return nil
}
var desc = `
The docker configuration file at <code>~/.docker/config.json</code> is
read to feed in the configured credentials for OCI registries.
`