-
Notifications
You must be signed in to change notification settings - Fork 804
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
feat: Improve messaging for common cloud config and rpc errors #2885
Conversation
1. Add a UnaryClientInterceptor for all gRPC client connections to catch and rewrite unauthenticated error messages 2. Put the sqlc auth token in the config struct, and add simple validation 3. Add more explanatory error messages in cases where users try to use cloud features without the proper configuration 4. Prevent sending the SQLC_AUTH_TOKEN env var to plugins Resolves #2881 Resolves #2881
func (c *Config) addEnvVars() error { | ||
authToken := os.Getenv("SQLC_AUTH_TOKEN") | ||
if authToken != "" && !strings.HasPrefix(authToken, "sqlc_") { | ||
return fmt.Errorf("$SQLC_AUTH_TOKEN doesn't start with \"sqlc_\"") | ||
} | ||
c.Cloud.AuthToken = authToken | ||
|
||
return nil | ||
} |
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.
I wanted to get away from calling os.Getenv()
all over the place, but I'm not sure this (adding fields to Config
struct and then populating after parse) is the best way to do it.
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.
I think as long as we only do this in one place, here in the config package, it's okay.
if key == "SQLC_AUTH_TOKEN" { | ||
continue | ||
} |
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.
We don't really need this, it just seemed like a reasonable thing to do (prevent users from sending their auth tokens to plugins).
This turned out to have more changes than I expected. A high-level list follows. There are definitely some style choices I made here that I'm not at all attached to, so feel free to recommend changes.
Add a UnaryClientInterceptor for all gRPC client connections to catch and rewrite unauthenticated error messages
Put the sqlc auth token in the config struct, and add simple validation
Add more explanatory error messages in cases where users try to use cloud features without the proper configuration
Prevent sending the SQLC_AUTH_TOKEN env var to plugins
Resolves #2881