Write per-host config info to hosts.yml instead of config.yml#1077
Write per-host config info to hosts.yml instead of config.yml#1077
hosts.yml instead of config.yml#1077Conversation
It's not being depended on anywhere right now, so this minimizes the public interface.
Previously we would trigger OAuth flow when the config file did not exist. Now we will let an empty Config object be initialized in that case, but trigger OAuth flow when the Context caller requests an AuthToken.
We dynamically add hosts on `Set`, so this `hosts` cache might fall out of date. We could ensure to keep it updated, but I'm not convinced it's necessary for speed right now.
Read from and write to the `hosts.yml` file every time `config.yml` is accessed. Everything that before went under the `hosts:` map now belongs to `hosts.yml`.
internal/config/config_file.go
Outdated
| var hosts map[string][]map[string]string | ||
| err = yaml.Unmarshal(b, &hosts) |
There was a problem hiding this comment.
migrateConfig was simplified to write to a new blank config and have all internal YAML- or write-related logic handled by fileConfig implementation
| // TODO this sucks. It precludes us laying out a nice config with comments and such. | ||
| type yamlConfig struct { | ||
| Hosts map[string]map[string]string | ||
| } | ||
|
|
||
| yamlHosts := map[string]map[string]string{} | ||
| yamlHosts[oauthHost] = map[string]string{} | ||
| yamlHosts[oauthHost]["user"] = userLogin | ||
| yamlHosts[oauthHost]["oauth_token"] = token |
| if nodes[i].Value == "hosts" { | ||
| hostsData.Content = append(hostsData.Content, nodes[i+1].Content...) | ||
| } else { | ||
| mainData.Content = append(mainData.Content, nodes[i], nodes[i+1]) |
There was a problem hiding this comment.
Splitting config into config.yml and hosts.yml is done at Write time
vilmibm
left a comment
There was a problem hiding this comment.
I like how this came out and just had one minor nitpick.
We should keep in mind as a team that until users re-authenticate or set a config value, their configs will not be split. I think that's ok for now but it's something that anyone responding to support issues is going to be want to be aware of.
internal/config/config_setup.go
Outdated
| return token, nil | ||
| } | ||
|
|
||
| func AuthFlow(oauthHost, notice string) (string, string, error) { |
There was a problem hiding this comment.
should this still be its own function? or at least made non-exported? I only see it used in AuthFlowWithConfig
There was a problem hiding this comment.
Good call! I'll make it private.
probablycorey
left a comment
There was a problem hiding this comment.
The biggest functional change that I've done as part of this PR is that accessing the Config object does not trigger authentication process anymore if the config file is missing.
Nice!
This works great.
internal/config/config_file.go
Outdated
| return err | ||
| } | ||
|
|
||
| cfgFile, err := os.OpenFile(fn, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) // cargo coded from setup |
There was a problem hiding this comment.
I thought fn was a function for a bit and was very confused. Maybe filename or just f?
@vilmibm Do you think that we should split it immediately on read when we detect "legacy" format like we did with |
I'm fine with not splitting immediately; I was just pointing out that whatever we do we (ie the people that field support requests via issues) should all be aware of it. |
|
Thanks very much for that comment @vilmibm - I was initially disappointed the token was still there post-1.0, but then saw this merge and wasn't sure what I needed to do in order to get it out. For anyone else: |
All per-host configuration info, including authentication credentials, is now written to
hosts.ymlinstead of toconfig.yml. This is to makeconfig.ymlsafe to check into version control and share. The migration from old to new config style is done whenever new configuration is written to disk.The biggest functional change that I've done as part of this PR is that accessing the Config object does not trigger authentication process anymore if the config file is missing. Instead, a blank Config object is returned. This is to facilitate reading configuration such as aliases #970 without triggering any side-effects.
Authentication is now triggered whenever
context.AuthToken()is accessed, but when there is nooauth_tokenfor the current hostname.Another change in this PR is that the config implementation does not hardcode
github.comanymore and handles well when other hostnames are written to and read from. This is mainly to pave the way to Enterprise compatibility #273.Fixes #937