Skip to content
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

New config layout #414

Merged
merged 5 commits into from
Sep 6, 2020
Merged

New config layout #414

merged 5 commits into from
Sep 6, 2020

Conversation

prarit
Copy link
Collaborator

@prarit prarit commented Sep 2, 2020

WIP: New config layout

@prarit prarit changed the title New config layout WIP: New config layout Sep 2, 2020
@prarit prarit force-pushed the new_config_layout branch 8 times, most recently from f92f33f to 7ac7b53 Compare September 2, 2020 18:44
@prarit prarit mentioned this pull request Sep 2, 2020
@codecov
Copy link

codecov bot commented Sep 2, 2020

Codecov Report

Merging #414 into master will decrease coverage by 1.15%.
The diff coverage is 22.35%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #414      +/-   ##
==========================================
- Coverage   63.33%   62.17%   -1.16%     
==========================================
  Files          50       50              
  Lines        3060     3141      +81     
==========================================
+ Hits         1938     1953      +15     
- Misses        972     1034      +62     
- Partials      150      154       +4     
Impacted Files Coverage Δ
internal/config/config.go 28.00% <18.51%> (-17.46%) ⬇️
cmd/issue_show.go 92.00% <100.00%> (ø)
cmd/mr_show.go 81.11% <100.00%> (ø)
cmd/snippet_browse.go 81.48% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update eae04b7...6d8163f. Read the comment docs.

main.go Outdated Show resolved Hide resolved
main.go Outdated Show resolved Hide resolved
@prarit
Copy link
Collaborator Author

prarit commented Sep 3, 2020

I see that using viper.WriteConfig() here don't replace all options not viper.Set()'ed like it did when using HCL format. Was it also an issue with the format?

Oh, that's a bug then. If viper.WriteConfig() doesn't write out all the config then yes, I have to use viper.WriteConfigAs(). I'll double check the behaviour.

@prarit prarit force-pushed the new_config_layout branch 2 times, most recently from 21c1169 to 873fec5 Compare September 3, 2020 01:01
@zaquestion
Copy link
Owner

I don't know why codecov is commenting every 5 lines on the stuff that isn't covered by tests ... Super noisy, sorry folks I try to find out how to disable that (unless it's just me?)

Copy link
Owner

@zaquestion zaquestion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking great already, I should have time tomorrow to weigh in more and catch up on the other stuff. Thanks for taking this on, huge improvement, and I never expected we'd migrate the original configs so that's a nice bonus

fmt.Println("Warning: Could not delete old config file", oldconfig)
}

// HACK
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw, it doesn't surprise me at all that we had to do this. Should be fine since lab configs have remained simple, essentially for this reason too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why codecov is commenting every 5 lines on the stuff that isn't covered by tests ... Super noisy, sorry folks I try to find out how to disable that (unless it's just me?)

Hmm ... I'm by no means an expert in codecov. We do have a few engineers who are familiar with it. Let me see if I can ping someone to take a look.

@prarit prarit changed the title WIP: New config layout WIP: New config layout (SAVE YOUR ~/.config/lab.hcl BEFORE RUNNING THIS CODE) Sep 3, 2020
@bmeneg
Copy link
Collaborator

bmeneg commented Sep 3, 2020

Nicely done @prarit !
I've tested all cases I could think of in this new push you did and things seem to be working pretty well.

Switch to using TOML format for the config files as the first step
of rehauling the Config setup.  TOML provides better viper support and is
closer to the standard git config file format.

HCL format is broken in viper and requires a small hack to convert double
square brackets to single square brackets in the viper TOML file format.

The test code extensively uses HCL and employs several viper HCL
workarounds.  The test code has been modified to remove HCL code and those
workarounds.

Before this change the ~/.config/lab.hcl contains

"core" = {
  "host" = "https://gitlab.com"

  "token" = "abcdef12345"

  "user" = "prarit"
}

After this change the ~/.config/lab/lab.toml contains

[core]
  host = "https://gitlab.com"
  token = "abcdef12345"
  user = "prarit"

Also move the new config files into their own directories in
~/.config and the local .git.

Convert config files from HCL to TOML and move them into their own
~/.config/lab and .git/lab/ directories.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
The existing config code uses a lot of workarounds for viper's issues with
the HCL format.  With the move TOML format for the config files, a lot of
this code can be eliminated by using standard viper calls.

Rework the config code to remove workarounds and reorganize the config
function.

Suggested-by: Zaq? Wiedmann <zaquestion@gmail.com>
Signed-off-by: Prarit Bhargava <prarit@redaht.com>
Move the config initialization code from main.go to
internal/config/config.go.

Suggested-by: Bruno Meneguele <bmeneg@redhat.com>
Signed-off-by: Prarit Bhargava <prarit@redhat.com>
As noted in issue zaquestion#152 ("Accept self signed certificates"), the
certificate code is no longer working.  This is because the certificate
code was executed before the configuration was loaded.

The code is need of a massive clean up, and with the transition of the
config files to TOML format, the code to get the certificate can easily be
incorporated into the main configuration code.

Fix and clean up the certifcate code.

Signed-off-by: Prarit Bhargava <prarit@redhat.com>
@prarit prarit changed the title WIP: New config layout (SAVE YOUR ~/.config/lab.hcl BEFORE RUNNING THIS CODE) New config layout Sep 4, 2020
@prarit
Copy link
Collaborator Author

prarit commented Sep 4, 2020

@zaquestion, I've dropped WIP from the description and the patches. This code is ready for review IMO.

@prarit prarit linked an issue Sep 4, 2020 that may be closed by this pull request
@zaquestion
Copy link
Owner

I'll be doing a deep dive over the weekend, thanks @prarit !

Copy link
Collaborator

@bmeneg bmeneg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICT the changes are working as expected and the code is pretty sane and clean.
Thanks @prarit .

@zaquestion
Copy link
Owner

Looking solid, I took it for a spin locally and saw my configs convert seamlessly. I added a simple test for the convert func, after the tests pass lets move forward and bring this in.

note: confpath convert was reordered to happen first to mitigate a very unlikely edge case where lab is run in `.config` causing the converted toml file to land in `.config` instead of `.config/lab/`
@zaquestion
Copy link
Owner

@prarit I'll let you do the honors 👍

zaquestion added a commit that referenced this pull request Sep 6, 2020
When running lab in GitLab CI, lab will attempt to autoconfigure to use
the CI credentials. While this is a useful feature for consumers of lab,
it's working against us here. I've used the lab env vars which currently
take precedence over the CI config, but when #414 comes in, I believe
it'll break again, so we'll need to revisit then.

The ssh config make it so lab can clone repos over ssh, as that key is
attached to the `lab-testing` user
@prarit prarit merged commit 084623b into zaquestion:master Sep 6, 2020
@prarit prarit deleted the new_config_layout branch January 21, 2021 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Rehaul Configuration
3 participants