Skip to content

CLOUDP-332913: [AtlasCLI] Decouple profile from viper #4050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Jul 25, 2025

Conversation

jeroenvervaeke
Copy link
Collaborator

Proposed changes

  • Decoupled profile from viper by introducing config.Store (originally called ConfigStore, but the linter didn't like it)
    • All viper logic now lives in ViperConfigStore, I tried to not touch the logic, mainly copy paste where possible
  • Introduced WithProfile/ProfileFromContext and attached the profile to the context, so in commands you can get the Profile from the context instead of using static variables.
  • Split profile.go into profile.go/identifiers.go (code was unrelated to profile)
  • I had to disable tests in internal/validate/validate_test.go because they directly invoke viper 👎 , will fix them in a followup PR

Jira ticket: CLOUDP-332913

@jeroenvervaeke jeroenvervaeke requested a review from a team as a code owner July 23, 2025 09:42
@@ -141,6 +141,7 @@ func TestObjectID(t *testing.T) {
}
}

/*
Copy link
Collaborator

@fmenezes fmenezes Jul 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of commenting the test you can add t.Skip("Will reenable on ticket CLOUDP-XXX")

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, thanks for the suggestion!

t.Fatalf("NoAPIKeys() expected error\n")
}
})
/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above t.Skip

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Collaborator

@andreaangiolillo andreaangiolillo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. All my comments are not blocking. Great improvement! 💯

Comment on lines +133 to +135
// Configuration needs to be deleted from toml, as viper doesn't support this yet.
// FIXME :: change when https://github.com/spf13/viper/pull/519 is merged.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] can we add a cloudp ticket in backlog so we don't forget about this?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was there since 2018, I didn't want to change the code to make the PR easier to review.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah wow, I am wondering if it is still valid 😅

Comment on lines +165 to +167
// Configuration needs to be deleted from toml, as viper doesn't support this yet.
// FIXME :: change when https://github.com/spf13/viper/pull/519 is merged.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

}

func (*InMemoryStore) RenameProfile(_, _ string) error {
panic("not implemented")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering what is the benefit here of using panic instead of returning the error as the function signature suggests to do 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InMemoryStore is not meant to be used, it's just there to keep tests working. The ultimate goal is to get rid of it. So if someone creates a new test they will realize they shouldn't use the method.

Comment on lines +105 to +112
if !exists {
if err := s.fs.MkdirAll(s.configDir, defaultPermissions); err != nil {
return err
}
}

return s.viper.WriteConfigAs(s.Filename())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think is more readable but feel free to ignore

Suggested change
if !exists {
if err := s.fs.MkdirAll(s.configDir, defaultPermissions); err != nil {
return err
}
}
return s.viper.WriteConfigAs(s.Filename())
if exists {
return s.viper.WriteConfigAs(s.Filename())
}
return s.fs.MkdirAll(s.configDir, defaultPermissions)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will create a ticket to address the actual logic, right now it's just a copy pasted

Copy link
Contributor

Coverage Report 📉

Branch Commit Coverage
SA_refactor_feature_branch 2d6fbbf 26.0%
CLOUDP-332913 84824df 25.7%
Difference -.3%

@jeroenvervaeke jeroenvervaeke merged commit c537834 into SA_refactor_feature_branch Jul 25, 2025
19 checks passed
@jeroenvervaeke jeroenvervaeke deleted the CLOUDP-332913 branch July 25, 2025 09:49
cveticm added a commit that referenced this pull request Aug 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants