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

Adds check to ensure config file exists. Fixes: #4513 #5387

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mesembria
Copy link
Contributor

Summary

Added to check to ensure config file actually exists if flag is used.

Fixes #4513

Change Type

Mark the type of change your PR introduces:

  • Bug fix (resolves an issue without affecting existing features)
  • Feature (adds new functionality without breaking changes)
  • Breaking change (may impact existing functionalities or require documentation updates)
  • Documentation (updates or additions to documentation)
  • Refactoring or test improvements (no bug fixes or new functionality)

Testing

No flag (minder auth login) - SAME AS PREVIOUSLY
Works as intended

Flag + no file (minder auth login --config) - SAME AS PREVIOUSLY
Usage
“Details: flag needs an argument: --config”

Flag + non-existant file (minder auth login --config blah) - FIXED
Message: Config file does not exist
Details: file blah not found

Flag + valid file (minder auth login --config config.yaml) - SAME AS PREVIOUSLY
Works as intended

Flag + invalid file(minder auth login --config go.sum) - SAME AS PREVIOUSLY
Error reading config file: While parsing config: yaml: unmarshal errors:
line 1: cannot unmarshal !!str buf.bui... into map[string]interface {}
Still took user to login page

Flag + invalid file (minder auth login --config LICENSE) - SAME AS PREVIOUSLY
yaml: line 92: mapping values are not allowed in this context

Review Checklist:

  • Reviewed my own code for quality and clarity.
  • Added comments to complex or tricky code sections.
  • Updated any affected documentation.
  • Included tests that validate the fix or feature.
  • Checked that related changes are merged.

@mesembria mesembria requested a review from a team as a code owner January 31, 2025 10:52
@mesembria mesembria linked an issue Jan 31, 2025 that may be closed by this pull request
@JAORMX
Copy link
Contributor

JAORMX commented Jan 31, 2025

The test failure seems legit

@mesembria mesembria force-pushed the 4513-minder-should-validate-the-config-exists branch from 24d5e3d to fbbeef1 Compare January 31, 2025 13:04
Comment on lines +38 to +43
// If config file is specified but doesn't exist, that's an error
if configFile := v.GetString("config"); configFile != "" {
if _, err := os.Stat(configFile); os.IsNotExist(err) {
return cli.MessageAndError("Config file does not exist", fmt.Errorf("file %s not found", configFile))
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Why is this only on auth login and not on other commands (i.e. in ReadConfigFromViper)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea. I'll move the logic up to that function and update the unit test as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Review
Development

Successfully merging this pull request may close these issues.

Minder should validate the config exists
3 participants