-
Notifications
You must be signed in to change notification settings - Fork 48
Try to fix set array values in Gateway config.toml #940
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
base: main
Are you sure you want to change the base?
Conversation
|
|
WalkthroughA new function Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ❌ 3❌ Failed checks (3 warnings)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@gateway/gateway-controller/pkg/config/config.go`:
- Around line 422-434: The AuthUser struct fields used by
loadBasicAuthUsersFromEnv are missing encoding/json tags so snake_case keys
(e.g. password_hashed) in the APIP_GW_GATEWAY_CONTROLLER_AUTH_BASIC_USERS_JSON
env JSON are ignored; update the AuthUser type to add appropriate json tags
(e.g. map Username, Password, PasswordHashed to "username", "password",
"password_hashed") so json.Unmarshal in loadBasicAuthUsersFromEnv correctly sets
PasswordHashed and preserves hashed-password auth behavior.
| func loadBasicAuthUsersFromEnv(k *koanf.Koanf) error { | ||
| envKey := EnvPrefix + "GATEWAY_CONTROLLER_AUTH_BASIC_USERS_JSON" | ||
|
|
||
| raw := os.Getenv(envKey) | ||
| if strings.TrimSpace(raw) == "" { | ||
| return nil // env var not set - do nothing | ||
| } | ||
|
|
||
| var users []AuthUser | ||
| if err := json.Unmarshal([]byte(raw), &users); err != nil { | ||
| return fmt.Errorf( | ||
| "invalid JSON in %s: %w", envKey, err, | ||
| ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
# Find the AuthUser struct definition
rg -A 5 "type AuthUser struct" gateway/Repository: wso2/api-platform
Length of output: 884
🏁 Script executed:
# Find the loadBasicAuthUsersFromEnv function
rg -B 2 -A 15 "func loadBasicAuthUsersFromEnv" gateway/Repository: wso2/api-platform
Length of output: 1359
🏁 Script executed:
# Check the full context of the configuration file around the mentioned lines
sed -n '420,450p' gateway/gateway-controller/pkg/config/config.goRepository: wso2/api-platform
Length of output: 851
🏁 Script executed:
# Look for where AuthUser is defined in the codebase
fd "config.go" gateway/ | xargs grep -l "type AuthUser"Repository: wso2/api-platform
Length of output: 108
🏁 Script executed:
# Verify the EnvPrefix value to confirm the environment variable name
rg -B 2 -A 2 "EnvPrefix\s*=" gateway/gateway-controller/pkg/config/config.go | head -20Repository: wso2/api-platform
Length of output: 190
🏁 Script executed:
# Check if there are any tests for loadBasicAuthUsersFromEnv that might reveal the expected behavior
rg -l "loadBasicAuthUsersFromEnv" gateway/ --type goRepository: wso2/api-platform
Length of output: 108
🏁 Script executed:
# Verify the file is in the right path for the guideline
fd "config.go" gateway/gateway-controller/Repository: wso2/api-platform
Length of output: 163
Add JSON tags so password_hashed is honored in env JSON.
encoding/json.Unmarshal is case-sensitive and ignores koanf tags. Without json tags, snake_case keys like password_hashed won't map to the PasswordHashed field, causing it to silently default to false. This breaks hashed password authentication when users are loaded from APIP_GW_GATEWAY_CONTROLLER_AUTH_BASIC_USERS_JSON. Add json tags to AuthUser to maintain snake_case compatibility.
🔧 Proposed fix (add JSON tags to AuthUser)
type AuthUser struct {
- Username string `koanf:"username"`
- Password string `koanf:"password"` // plain or hashed value depending on PasswordHashed
- PasswordHashed bool `koanf:"password_hashed"` // true when Password is a bcrypt hash
- Roles []string `koanf:"roles"`
+ Username string `koanf:"username" json:"username"`
+ Password string `koanf:"password" json:"password"` // plain or hashed value depending on PasswordHashed
+ PasswordHashed bool `koanf:"password_hashed" json:"password_hashed"` // true when Password is a bcrypt hash
+ Roles []string `koanf:"roles" json:"roles"`
}After merging, rebuild Docker images using cd gateway && make build-local.
🤖 Prompt for AI Agents
In `@gateway/gateway-controller/pkg/config/config.go` around lines 422 - 434, The
AuthUser struct fields used by loadBasicAuthUsersFromEnv are missing
encoding/json tags so snake_case keys (e.g. password_hashed) in the
APIP_GW_GATEWAY_CONTROLLER_AUTH_BASIC_USERS_JSON env JSON are ignored; update
the AuthUser type to add appropriate json tags (e.g. map Username, Password,
PasswordHashed to "username", "password", "password_hashed") so json.Unmarshal
in loadBasicAuthUsersFromEnv correctly sets PasswordHashed and preserves
hashed-password auth behavior.
Purpose
The Gateway Controller fails to initialize the SQLite database on Windows due to a CGO limitation. This prevents the gateway from starting and blocks testing on Windows systems.
Resolves issue: SQLite initialization fails on Windows due to CGO_DISABLED.
Goals
Allow developers to run and test the Gateway Controller on Windows without needing to build the binary from source with CGO enabled. Provide clear instructions and configuration for database compatibility.
Summary by CodeRabbit
Release Notes