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

Merged
merged 4 commits into from
Feb 3, 2025

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
JAORMX previously approved these changes Jan 31, 2025
@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
evankanderson
evankanderson previously approved these changes Jan 31, 2025
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.

@mesembria mesembria dismissed stale reviews from evankanderson and JAORMX via ce720d9 February 3, 2025 14:50
@mesembria
Copy link
Contributor Author

Unit tests continue to fail during CI, but pass locally. I don't know enough to know what's different between the two envs.

eleftherias
eleftherias previously approved these changes Feb 3, 2025
Copy link
Contributor

@eleftherias eleftherias left a comment

Choose a reason for hiding this comment

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

I think #5399 will fix the test failures

cmd/cli/app/auth/auth_login.go Outdated Show resolved Hide resolved
@mesembria mesembria force-pushed the 4513-minder-should-validate-the-config-exists branch from 5a8458b to c75ff4c Compare February 3, 2025 22:12
@coveralls
Copy link

Coverage Status

coverage: 57.48% (-0.03%) from 57.505%
when pulling c75ff4c on 4513-minder-should-validate-the-config-exists
into f5f00ed on main.

@mesembria mesembria merged commit ad750bd into main Feb 3, 2025
26 checks passed
@mesembria mesembria deleted the 4513-minder-should-validate-the-config-exists branch February 3, 2025 22:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Minder should validate the config exists
5 participants