Skip to content
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

Add support for .enos.vars.hcl in user's home directory #122

Closed
wants to merge 1 commit into from

Conversation

jasonodonnell
Copy link

This adds support for $HOME/.enos.vars.hcl so users can maintain a static vars file. This still supports walking the current directory for vars file, but first checks if the home file exists.

Checklist

  • The commit message includes an explanation of the changes
  • Manual validation of the changes have been performed (if possible)
  • New or modified code has requisite test coverage (if possible)
  • I have performed a self-review of the changes
  • I have made necessary changes and/or pull requests for documentation
  • I have written useful comments in the code

@jasonodonnell jasonodonnell requested a review from a team as a code owner February 27, 2024 17:49
@jasonodonnell jasonodonnell added the changelog/feat New feature or enhancement. Will be included in "New Features" category in release notes. label Feb 27, 2024
func LoadHomeVarsFile() (RawFiles, error) {
rawFiles := RawFiles{}

home, _ := os.UserHomeDir()
Copy link
Collaborator

Choose a reason for hiding this comment

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

We shouldn't swallow the error here. If $HOME (or whatever platform specific variable) isn't set we'll get and should return it and allow the caller to determine if that's a problem.

os.UserHomeDir() doesn't give us a typed error for this, so perhaps it would be best to create our own and wrap it so the caller can determine what to do.

Perhaps something like ErrHomeDirUnset.

@@ -229,7 +230,14 @@ func readFlightPlanConfig(dir string, varFilePaths []string) (*pb.FlightPlan, er

var varsFiles flightplan.RawFiles
if len(varFilePaths) == 0 {
varsFiles, err = flightplan.FindRawFiles(dir, flightplan.VariablesNamePattern)
// Check home directory first and fallback to current directory search.
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should always eval both HOME but our local files should be last writer, which lets us override things locally without making the implementation more complicated. It's been a while but I think two variables being set is okay. Though it's possible you'll get a warning diag, which I think is fine as it bubbles up where we're seeing both values.

This feature seems reasonable but I don't want to lose the ability to have local vars and common vars in a home dir. I find myself changing variables locally often and definitely don't want changing vars for one project to affect another.

Copy link
Author

Choose a reason for hiding this comment

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

It's been a while but I think two variables being set is okay.

It seems this is not the case:

│ Error: Duplicate argument
│
│   on /Users/jasonodonnell/.enos.vars.hcl line 5:
│    5: artifactory_username = "[email protected]"
│
│ Argument "artifactory_username" was already set at
│ /Users/jasonodonnell/Git/vault-enterprise/enos/enos.vars.hcl:5,1-21

@ryancragun ryancragun deleted the enos-vars-home branch March 28, 2024 19:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog/feat New feature or enhancement. Will be included in "New Features" category in release notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants