[migration] Add support for loading credentials from file provided in command line#422
Conversation
|
Thank you for working on this. I see from the tests that this parses a MySQL-like ini file (rather than kong file etc). I think that's a great level of integration - it wasn't what I had intended but I think works fine. But I have the following suggestions:
|
ha! i completely missed that kong had the ability to parse an arbitrary config file but yeah -- keeping in line with MySQL ini files seems like a good thing to do for consistency with other tooling in the ecosystem
yup -- we're only parsing the client section for these params
host and database make sense: would it be reasonable, then, to also parse port from the config file, as it seems standard to have it defined in its own field in things like the MySQL CLI. I'd assume yes but want to confirm before going too far upfield
so the easy answer here is to make current behavior without the default annotation I could also just shove the default in the help text but that also begs the question: do ya'll care for defaults for these four fields? we could just remove them for these fields and fail when they're not provided in the command line or conf file. I believe that's what part of the code actually checks for here and here but these were never true since the defaults injected by kong would also be non-empty. let me know what you think and i can take another crack 🙇🏽 |
Yes that's fine.
Yes, I agree that's the tradeoff here. The most straight forward way to implement this is to remove kong defaults. We can later parse and substitute in defaults, but as you said it means they won't appear in help output. But I think that's fine. |
|
took another crack with some changes:
Most of the updates are to the change to pointer types for some of these fields. if you prefer a cleaner PR, i can try and figure out another approach |
ce7df67 to
b54ec7c
Compare
| if m.ReplicaMaxLag == 0 { | ||
| m.ReplicaMaxLag = 120 * time.Second | ||
| } | ||
| if m.Host == "" { |
There was a problem hiding this comment.
this would have never been true as a normal course of operation since kong would inject a default at runtime
There was a problem hiding this comment.
This covers a use case we have internally. We use spirit as a library/package and don't rely on kong to inject values.
I think it's fine to remove though, we can find another way to handle this.
| if !strings.Contains(m.Host, ":") { | ||
| m.Host = fmt.Sprintf("%s:%d", m.Host, 3306) | ||
| } | ||
| if m.Database == "" { |
There was a problem hiding this comment.
same goes here: kong would inject the default of test.
pkg/migration/migration.go
Outdated
| Host *string `name:"host" help:"Hostname" optional:""` | ||
| Username *string `name:"username" help:"User" optional:""` | ||
| Password *string `name:"password" help:"Password" optional:""` | ||
| Database *string `name:"database" help:"Database" optional:""` |
There was a problem hiding this comment.
I'm sure there's a reason, but can you explain the *string change? Is it to differentiate between not set, and set to empty?
If we can avoid it, that would be ideal of course.
There was a problem hiding this comment.
ah -- so this was a carry over of trying to keep the default values within kong's purview which ended up not working out and then eventually convincing myself that it was cleaner to represent a value not being passed in as a nil pointer than an empty string. Happy to keep these as strings to make the PR smaller. lmk!
There was a problem hiding this comment.
Yes, I think it's better as strings. If you can make this change back, I think this PR is much smaller/we don't have to consider the side effects here from *string.
There was a problem hiding this comment.
question: do you still want to support passing the literal string "" as a password on the CLI and file? I could see that being a legitimate use-case for password test databases. if so, that would necessitate switching just that field to be a pointer since we'd need to make the distinction between "" and not being provided at all.
There was a problem hiding this comment.
Good point. Yes, I guess we need to support passing an empty string for the password.
There was a problem hiding this comment.
cool -- i'll update to support that
976b379 to
0fc5420
Compare
|
LGTM on first glance - I'm OOO tomorrow, but can take a look next week. If you get a chance to add support for the new TLS options from #443 , I think this further supports the use case of why config files are handy. |
i'll take a look! |
…word from file. CLI args take precedence over what's defined in file if they both exist. Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
ab5ea33 to
e3cd0c6
Compare
|
an interesting thing to note: the parameters for |
I think this is fine for now. We could accept the MySQL names in a mysql config file if we decide to. We named these options |
…RY tests Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
e3263f3 to
7802372
Compare
|
Just a few linter errors if you don't mind fixing. Otherwise LGTM: |
Signed-off-by: Brian Ramos <brirams@users.noreply.github.com>
|
LGTM, thank you again for the contribution. |
Summary
Fixes #421. This PR adds support for loading host, port, username, password, database, tls mode and tls certificate path from a
--conffile argument to spirit. It expects the path to exist, as enforced by kong'sexistingfiletype annotation and usego-inito load credentials from theclientsection. Adds test to verify basic functionality.Changes
Migrationnow has aConffield, which is populated by kong using the--confargument. I chose a name that seemed natural to me but open to any better suggestions. InormalizeOptionsloads the file using go-ini and checks for aclientsection and uses the mysql standardhost,user,password,databaseandportnames for these arguments . Usingtls-*instead of MySQL'sssl-*for tls settings. Args for--host,--username,--password,--database,--tls-caand--tls-modetake precedence over what's in fileTesting