-
Notifications
You must be signed in to change notification settings - Fork 286
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
Add spanner emulator env var detection #574
Conversation
@@ -84,3 +88,15 @@ func (smd SpannerMigrationDriver) Close() error { | |||
} | |||
|
|||
var _ migrate.Driver = SpannerMigrationDriver{} | |||
|
|||
func detectEmulatorSetting() (string, bool) { | |||
for _, env := range os.Environ() { |
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.
viper knows the env prefix we use - we pass it around as programName
and configure viper with it:
spicedb/pkg/cmd/server/defaults.go
Line 53 in 7bd2af5
cobrautil.SyncViperPreRunE(programName), |
I'm not overly familiar with viper but it seems like there should be a way to directly ask for this value instead of manually flipping through the environment variables.
Does something like viper.Get("SPANNER_EMULATOR_HOST")
work? Maybe @jzelinskie has some suggestions?
4f2cb84
to
5297edd
Compare
5297edd
to
da16644
Compare
@@ -58,6 +59,11 @@ func NewSpannerDatastore(database string, opts ...Option) (datastore.Datastore, | |||
return nil, fmt.Errorf(errUnableToInstantiate, err) | |||
} | |||
|
|||
setting, found := detectEmulatorSetting() |
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.
couldn't this be another Option
on the spanner datastore (so that we don't have to read env vars here), and then re-use the implementation from the migrate command for the serve command?
f6726be
to
95ce218
Compare
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.
LGTM
even though this adds a new flag that's only used for tests, I like that it's more discoverable than undocumented env vars
95ce218
to
f531819
Compare
f531819
to
c92578f
Compare
Detect prefixed spanner emulator env var config and set the actual env var.