Skip to content

Commit

Permalink
fix: allow only standard registry by default if no policy file is set
Browse files Browse the repository at this point in the history
  • Loading branch information
suzuki-shunsuke committed Jan 3, 2023
1 parent 54ab8c7 commit e9428a5
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pkg/policy/config_reader.go
Expand Up @@ -32,6 +32,9 @@ func (reader *MockConfigReader) Read(files []string) ([]*Config, error) {
}

func (reader *ConfigReaderImpl) Read(files []string) ([]*Config, error) {
if len(files) == 0 {
return reader.readDefault()
}
policyCfgs := make([]*Config, len(files))
for i, cfgFilePath := range files {
policyCfg := &Config{
Expand All @@ -46,6 +49,31 @@ func (reader *ConfigReaderImpl) Read(files []string) ([]*Config, error) {
return policyCfgs, nil
}

func (reader *ConfigReaderImpl) readDefault() ([]*Config, error) {
// https://github.com/aquaproj/aqua/issues/1404
// If no policy file is set, only standard registry is allowed by default.
cfg := &Config{
YAML: &ConfigYAML{
Registries: []*Registry{
{
Type: "standard",
},
},
Packages: []*Package{
{
RegistryName: "standard",
},
},
},
}
if err := cfg.Init(); err != nil {
return nil, err
}
return []*Config{
cfg,
}, nil
}

func (reader *ConfigReaderImpl) read(cfg *Config) error {
file, err := reader.fs.Open(cfg.Path)
if err != nil {
Expand Down

0 comments on commit e9428a5

Please sign in to comment.