diff --git a/pkg/autosync/autosync.go b/pkg/autosync/autosync.go index 36095c8e..ec827a5d 100644 --- a/pkg/autosync/autosync.go +++ b/pkg/autosync/autosync.go @@ -12,13 +12,6 @@ import ( // in case where user specific values that are defined in granted.yml's `templateValues` are not available. // this is done so that users are aware of required keys when granted's credential-process is used through the AWS CLI. func Run(ctx context.Context, interactive bool) { - if registry.IsOutdatedConfig() { - clio.Warn("Outdated Profile Registry Configuration. Use `granted registry migrate` to update your configuration.") - - clio.Warn("Skipping Profile Registry sync.") - - return - } registries, err := registry.GetProfileRegistries(interactive) if err != nil { @@ -26,6 +19,12 @@ func Run(ctx context.Context, interactive bool) { return } + if len(registries) > 0 { + clio.Warn("Outdated Profile Registry Configuration. Use `granted registry migrate` to update your configuration.") + clio.Warn("Skipping Profile Registry sync.") + return + } + // check if registry has been configured or not. // should skip registry sync if no profile registry. if len(registries) == 0 { diff --git a/pkg/autosync/registry.go b/pkg/autosync/registry.go index 357fdbdb..2d14b177 100644 --- a/pkg/autosync/registry.go +++ b/pkg/autosync/registry.go @@ -9,14 +9,6 @@ import ( "github.com/common-fate/granted/pkg/granted/registry" ) -type RegistrySyncError struct { - err error -} - -func (e *RegistrySyncError) Error() string { - return fmt.Sprintf("error syncing profile registry with err: %s", e.err.Error()) -} - func runSync(ctx context.Context, rc RegistrySyncConfig, interactive bool) error { clio.Info("Syncing Profile Registries") err := registry.SyncProfileRegistries(ctx, interactive) diff --git a/pkg/granted/awsmerge/merge_from_registry.go b/pkg/granted/awsmerge/merge_from_registry.go index bd0f08b3..d6b06faf 100644 --- a/pkg/granted/awsmerge/merge_from_registry.go +++ b/pkg/granted/awsmerge/merge_from_registry.go @@ -46,7 +46,7 @@ func autoGeneratedMsg() string { // [granted_registry_start test] // // ... // [granted_registry_end test] -func (m Merger) WithRegistry(src *ini.File, dst *ini.File, opts RegistryOpts) (*ini.File, error) { +func WithRegistry(src *ini.File, dst *ini.File, opts RegistryOpts) (*ini.File, error) { namespace := opts.Name // create a temporary ini structure, so that we leave 'dst' untouched if we run into diff --git a/pkg/granted/awsmerge/merge_from_registry_test.go b/pkg/granted/awsmerge/merge_from_registry_test.go index aa68a2e6..781a20d9 100644 --- a/pkg/granted/awsmerge/merge_from_registry_test.go +++ b/pkg/granted/awsmerge/merge_from_registry_test.go @@ -307,8 +307,7 @@ key1 = value2 t.Fatal(err) } - m := Merger{} - out, err := m.WithRegistry(src, dst, tt.args.opts) + out, err := WithRegistry(src, dst, tt.args.opts) if (err != nil) != tt.wantErr { t.Fatalf("Merger.WithRegistry() error = %v, wantErr %v", err, tt.wantErr) } diff --git a/pkg/granted/awsmerge/merger.go b/pkg/granted/awsmerge/merger.go deleted file mode 100644 index d8842c34..00000000 --- a/pkg/granted/awsmerge/merger.go +++ /dev/null @@ -1,6 +0,0 @@ -// Package awsmerge contains logic to merge multiple AWS config files -// together. In Granted this is used to power the Profile Registry feature. -package awsmerge - -type Merger struct { -} diff --git a/pkg/granted/awsmerge/remove_registry.go b/pkg/granted/awsmerge/remove_registry.go index 762f1a08..5727ce5f 100644 --- a/pkg/granted/awsmerge/remove_registry.go +++ b/pkg/granted/awsmerge/remove_registry.go @@ -13,7 +13,7 @@ import ( // [granted_registry_start test] // // ... // [granted_registry_end test] -func (m Merger) RemoveRegistry(src *ini.File, name string) { +func RemoveRegistry(src *ini.File, name string) { // replace any existing generated profiles which match the name of the registry existing := getGrantedGeneratedSections(src, name) for _, p := range existing { diff --git a/pkg/granted/registry/add.go b/pkg/granted/registry/add.go index 6e55ece2..759026ef 100644 --- a/pkg/granted/registry/add.go +++ b/pkg/granted/registry/add.go @@ -108,9 +108,7 @@ var AddCommand = cli.Command{ return err } - m := awsmerge.Merger{} - - merged, err := m.WithRegistry(src, dst, awsmerge.RegistryOpts{ + merged, err := awsmerge.WithRegistry(src, dst, awsmerge.RegistryOpts{ Name: name, PrefixAllProfiles: prefixAllProfiles, PrefixDuplicateProfiles: prefixDuplicateProfiles, @@ -140,7 +138,7 @@ var AddCommand = cli.Command{ registryConfig.PrefixDuplicateProfiles = true // try and merge again - merged, err = m.WithRegistry(src, dst, awsmerge.RegistryOpts{ + merged, err = awsmerge.WithRegistry(src, dst, awsmerge.RegistryOpts{ Name: name, PrefixAllProfiles: prefixAllProfiles, PrefixDuplicateProfiles: true, @@ -184,9 +182,7 @@ var AddCommand = cli.Command{ return err } - m := awsmerge.Merger{} - - merged, err := m.WithRegistry(src, dst, awsmerge.RegistryOpts{ + merged, err := awsmerge.WithRegistry(src, dst, awsmerge.RegistryOpts{ Name: name, PrefixAllProfiles: prefixAllProfiles, PrefixDuplicateProfiles: prefixDuplicateProfiles, @@ -216,7 +212,7 @@ var AddCommand = cli.Command{ registryConfig.PrefixDuplicateProfiles = true // try and merge again - merged, err = m.WithRegistry(src, dst, awsmerge.RegistryOpts{ + merged, err = awsmerge.WithRegistry(src, dst, awsmerge.RegistryOpts{ Name: name, PrefixAllProfiles: prefixAllProfiles, PrefixDuplicateProfiles: true, diff --git a/pkg/granted/registry/migrate.go b/pkg/granted/registry/migrate.go index 63110c9b..2638c88e 100644 --- a/pkg/granted/registry/migrate.go +++ b/pkg/granted/registry/migrate.go @@ -65,17 +65,3 @@ var MigrateCommand = cli.Command{ return nil }, } - -func IsOutdatedConfig() bool { - gConf, err := grantedConfig.Load() - if err != nil { - clio.Debug(err.Error()) - return true - } - - if len(gConf.ProfileRegistryURLS) > 0 { - return true - } - - return false -} diff --git a/pkg/granted/registry/remove.go b/pkg/granted/registry/remove.go index 59e604fa..9642b325 100644 --- a/pkg/granted/registry/remove.go +++ b/pkg/granted/registry/remove.go @@ -57,14 +57,12 @@ var RemoveCommand = cli.Command{ return err } - m := awsmerge.Merger{} - configFile, awsConfigPath, err := loadAWSConfigFile() if err != nil { return err } - m.RemoveRegistry(configFile, selectedRegistry.Name) + awsmerge.RemoveRegistry(configFile, selectedRegistry.Name) err = configFile.SaveTo(awsConfigPath) if err != nil { diff --git a/pkg/granted/registry/sync.go b/pkg/granted/registry/sync.go index aab61f99..993b51d3 100644 --- a/pkg/granted/registry/sync.go +++ b/pkg/granted/registry/sync.go @@ -55,15 +55,13 @@ func SyncProfileRegistries(ctx context.Context, interactive bool) error { return nil } - m := awsmerge.Merger{} - for _, r := range registries { src, err := r.Registry.AWSProfiles(ctx, interactive) if err != nil { return fmt.Errorf("error retrieving AWS profiles for registry %s: %w", r.Config.Name, err) } - merged, err := m.WithRegistry(src, configFile, awsmerge.RegistryOpts{ + merged, err := awsmerge.WithRegistry(src, configFile, awsmerge.RegistryOpts{ Name: r.Config.Name, PrefixAllProfiles: r.Config.PrefixAllProfiles, PrefixDuplicateProfiles: r.Config.PrefixDuplicateProfiles, @@ -92,7 +90,7 @@ func SyncProfileRegistries(ctx context.Context, interactive bool) error { } // try and merge again - merged, err = m.WithRegistry(src, configFile, awsmerge.RegistryOpts{ + merged, err = awsmerge.WithRegistry(src, configFile, awsmerge.RegistryOpts{ Name: r.Config.Name, PrefixAllProfiles: r.Config.PrefixAllProfiles, PrefixDuplicateProfiles: true,