Repository navigation
Allow declaring a file containing the proxy userinfo via the environment #570
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -287,25 +287,39 @@ func setConfigFromFile(config *Config, path string) error { | |||||||||||||||||||
| return nil | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| // setConfigFromEnv sets Config fields based on environment variables. | ||||||||||||||||||||
| func setConfigFromEnv(config *Config) error { | ||||||||||||||||||||
| if value, ok := os.LookupEnv("GEOIPUPDATE_ACCOUNT_ID"); ok { | ||||||||||||||||||||
| // getValueFromEnvFile returns the value associated to an env variable or from a file containing it. | ||||||||||||||||||||
| func getValueFromEnvFile(key string) (string, bool, error) { | ||||||||||||||||||||
| var res string | ||||||||||||||||||||
| var found bool | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if value, ok := os.LookupEnv(key); ok { | ||||||||||||||||||||
| res = value | ||||||||||||||||||||
| found = true | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if value := os.Getenv(key + "_FILE"); value != "" { | ||||||||||||||||||||
| var err error | ||||||||||||||||||||
| config.AccountID, err = strconv.Atoi(value) | ||||||||||||||||||||
|
|
||||||||||||||||||||
| content, err := os.ReadFile(filepath.Clean(value)) | ||||||||||||||||||||
|
Comment on lines
+300
to
+303
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Suppress the confirmed G703 diagnostic for the operator-selected file path. The configured Go lint command reports G703 for this Suggested fix- content, err := os.ReadFile(filepath.Clean(value))
+ content, err := os.ReadFile(filepath.Clean(value)) //nolint:gosec // Path is operator-supplied via environment.📝 Committable suggestion
Suggested change
🧰 Tools🪛 golangci-lint (2.14.0)[high] 303-303: G703: Path traversal via taint analysis (gosec) 🤖 Prompt for AI Agents |
||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
| return errors.New("invalid account ID format") | ||||||||||||||||||||
| return "", true, fmt.Errorf("failed to open %s_FILE: %w", key, err) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| found = true | ||||||||||||||||||||
| res = strings.TrimSpace(string(content)) | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if value := os.Getenv("GEOIPUPDATE_ACCOUNT_ID_FILE"); value != "" { | ||||||||||||||||||||
| var err error | ||||||||||||||||||||
| return res, found, nil | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| accountID, err := os.ReadFile(filepath.Clean(value)) | ||||||||||||||||||||
| // setConfigFromEnv sets Config fields based on environment variables. | ||||||||||||||||||||
| func setConfigFromEnv(config *Config) error { | ||||||||||||||||||||
| if value, found, err := getValueFromEnvFile("GEOIPUPDATE_ACCOUNT_ID"); found { | ||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
| return fmt.Errorf("failed to open GEOIPUPDATE_ACCOUNT_ID_FILE: %w", err) | ||||||||||||||||||||
| return err | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| config.AccountID, err = strconv.Atoi(strings.TrimSpace(string(accountID))) | ||||||||||||||||||||
| config.AccountID, err = strconv.Atoi(value) | ||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
| return errors.New("invalid account ID format") | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
@@ -330,19 +344,12 @@ func setConfigFromEnv(config *Config) error { | |||||||||||||||||||
| config.URL = u.String() | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if value, ok := os.LookupEnv("GEOIPUPDATE_LICENSE_KEY"); ok { | ||||||||||||||||||||
| config.LicenseKey = value | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if value := os.Getenv("GEOIPUPDATE_LICENSE_KEY_FILE"); value != "" { | ||||||||||||||||||||
| var err error | ||||||||||||||||||||
|
|
||||||||||||||||||||
| licenseKey, err := os.ReadFile(filepath.Clean(value)) | ||||||||||||||||||||
| if value, found, err := getValueFromEnvFile("GEOIPUPDATE_LICENSE_KEY"); found { | ||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
| return fmt.Errorf("failed to open GEOIPUPDATE_LICENSE_KEY_FILE: %w", err) | ||||||||||||||||||||
| return err | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| config.LicenseKey = strings.TrimSpace(string(licenseKey)) | ||||||||||||||||||||
| config.LicenseKey = value | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if value, ok := os.LookupEnv("GEOIPUPDATE_LOCK_FILE"); ok { | ||||||||||||||||||||
|
|
@@ -371,7 +378,11 @@ func setConfigFromEnv(config *Config) error { | |||||||||||||||||||
| config.proxyURL = value | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| if value, ok := os.LookupEnv("GEOIPUPDATE_PROXY_USER_PASSWORD"); ok { | ||||||||||||||||||||
| if value, found, err := getValueFromEnvFile("GEOIPUPDATE_PROXY_USER_PASSWORD"); found { | ||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||
| return err | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
| config.proxyUserInfo = value | ||||||||||||||||||||
| } | ||||||||||||||||||||
|
|
||||||||||||||||||||
|
|
||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.