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

Allow configuration of indentation for YAML and JSON stores #1273

Merged
merged 10 commits into from
Nov 24, 2023

Conversation

Ph0tonic
Copy link
Contributor

@Ph0tonic Ph0tonic commented Sep 8, 2023

This PR aims to finish the work started in #930, thanks to @jamesgoodhouse.

I added the use of the Indent param in the store as well as a new --indent option in the cli.
Let me know what you think about it.

Fixes #900, fixes #1048 and fixes #1028

cmd/sops/main.go Outdated Show resolved Hide resolved
@hiddeco
Copy link
Member

hiddeco commented Sep 9, 2023

In favor of adding support for this but not before 3.9.0.

@hiddeco hiddeco added this to the v3.9.0 milestone Sep 9, 2023
Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! I've some first comments after glancing over the implementation.

cmd/sops/main.go Outdated Show resolved Hide resolved
cmd/sops/main.go Outdated Show resolved Hide resolved
cmd/sops/common/common.go Outdated Show resolved Hide resolved
@felixfontein
Copy link
Contributor

For some reason this doesn't compile in CI anymore. The only error printed is Error: , which is not exactly helpful. I'm not sure whether this short error output is caused by GHA or by Go itself. In another PR, #1274, the compile steps worked, but the functional tests fail, also with Error: , so this might be related to GHA. Did you try to compile this locally?

@felixfontein
Copy link
Contributor

Meh, actually the problem was on my side - apparently GHA changed some code and the error reports are now loaded from another domain name, which I was blocking by default.

@Ph0tonic
Copy link
Contributor Author

Meh, actually the problem was on my side - apparently GHA changed some code and the error reports are now loaded from another domain name, which I was blocking by default.

I found an issue in main.go which I fixed. 👍

@hiddeco hiddeco changed the title Fixes #900 - Configurable indent param for yaml store Allow configuration of identation for YAML store Sep 13, 2023
@hiddeco hiddeco changed the title Allow configuration of identation for YAML store Allow configuration of indentation for YAML store Sep 13, 2023
@Ph0tonic
Copy link
Contributor Author

I looked at other opened issues and identified #1048 which we could also fix in this PR.
Here is the doc for the json formatter:

The issue asks for the choice of indent character but for the first version we could already use the added cli option --indent for json. What do you think?

@felixfontein
Copy link
Contributor

How about using tabs if no indent is specified, and the amount of spaces if --indent is specified (or the JSON indent value is configured in the config)?

It might also make sense to allow 0 as a valid value for JSON. (IIRC parts of the code assume that not specified == 0.)

@Ph0tonic
Copy link
Contributor Author

How about using tabs if no indent is specified, and the amount of spaces if --indent is specified (or the JSON indent value is configured in the config)?

It might also make sense to allow 0 as a valid value for JSON. (IIRC parts of the code assume that not specified == 0.)

Yes, we could do that, I think it would make sense.
I just see one technical problem if we want to allow 0, I do not think it's possible to differentiate whether zero was provided during the unmarshaling of .sops.yaml or if it was empty and got the default 0 value.

@Ph0tonic Ph0tonic changed the title Allow configuration of indentation for YAML store Allow configuration of indentation for YAML and JSON stores Sep 14, 2023
@Ph0tonic
Copy link
Contributor Author

I applied what we discussed. However, while looking at other issues, #1028 seems to propose having default json indentation with spaces instead of tab to be compatible with yaml parser. I have no idea whether it is a good idea to change the default indentation of json to 4 spaces instead of one tab.
What do you think ?

@felixfontein
Copy link
Contributor

However, while looking at other issues, #1028 seems to propose having default json indentation with spaces instead of tab to be compatible with yaml parser. I have no idea whether it is a good idea to change the default indentation of json to 4 spaces instead of one tab.

I tend a bit to keep the tabs. No idea what the other maintainers think though :)

In any case, as long as it is possible to explicitly configure indentation by tabs (for example by setting indentation to a negative number) I'm ok with the default changing, assuming there is a majority for changing it.

I just see one technical problem if we want to allow 0, I do not think it's possible to differentiate whether zero was provided during the unmarshaling of .sops.yaml or if it was empty and got the default 0 value.

I would expect it is possible to provide a default value. I'm not that familiar with Go's serialization/deserialization mechanism though...

@felixfontein
Copy link
Contributor

I think you can simply assign default values to conf in

sops/config/config.go

Lines 252 to 253 in d46b702

conf := &configFile{}
err = conf.load(confBytes)
before loading, like

	conf := &configFile{}
        conf.Stores.JSON.Indent = -1
	err = conf.load(confBytes)

@Ph0tonic
Copy link
Contributor Author

Great thank you for your feedback, I appreciate it 👍. I implemented a default value of -1 which allows to support no indentation at all if the user provides 0. I think we can keep the tab as the default and then users can configure whatever they prefer. Let's see what other maintainers think of it.

@Ph0tonic
Copy link
Contributor Author

Ph0tonic commented Nov 5, 2023

Note that commit 07c06c7 contains some merge artefacts that are removed again in commit c7b04e1. Would you mind rebasing again to clean up both commits so that the merge artefacts are not part of the commits added to the main branch?

Besides that, I think this PR is ready for merging. @hiddeco @devstein do you have further comments?

Fixed ! 👍

Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

While looking at this again I have some more comments (or maybe I forgot some context from before).

stores/yaml/store.go Outdated Show resolved Hide resolved
stores/json/store.go Outdated Show resolved Hide resolved
stores/json/store.go Show resolved Hide resolved
config/config.go Outdated Show resolved Hide resolved
Copy link
Contributor

@felixfontein felixfontein left a comment

Choose a reason for hiding this comment

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

Besides that, looks good to me!

cmd/sops/main.go Show resolved Hide resolved
@felixfontein
Copy link
Contributor

If nobody objects, I'll merge this during the next few days.

James J. Goodhouse and others added 10 commits November 24, 2023 07:41
this will allow for setting of parameters specific to each store, such
as indentation level for YAML

Co-authored-by: Bastien Wermeille <bastien.wermeille@gmail.com>
Signed-off-by: James J. Goodhouse <jgoodhouse@newrelic.com>
Signed-off-by: Bastien Wermeille <bastien.wermeille@gmail.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
Signed-off-by: Bastien Wermeille <bastien.wermeille@gmail.com>
Signed-off-by: Bastien Wermeille <bastien.wermeille@gmail.com>
Signed-off-by: Bastien Wermeille <bastien.wermeille@gmail.com>
Signed-off-by: Bastien Wermeille <bastien.wermeille@gmail.com>
Signed-off-by: Bastien Wermeille <bastien.wermeille@gmail.com>
Signed-off-by: Bastien <bastien.wermeille@gmail.com>
Signed-off-by: Bastien <bastien.wermeille@gmail.com>
Signed-off-by: Bastien <bastien.wermeille@gmail.com>
@hiddeco hiddeco merged commit 681a386 into getsops:main Nov 24, 2023
10 checks passed
@felixfontein
Copy link
Contributor

@jamesgoodhouse @Ph0tonic thanks a lot for working on this and getting it over the finish line! :)

@consideRatio
Copy link

Wieee happy to learn that the json files are now being valid YAML files by no longer including tabs! Nice work on this @Ph0tonic @jamesgoodhouse and reviewers! 🎉

@felixfontein
Copy link
Contributor

To be precise by default they still use tabs, but now you can configure sops to use spaces instead of tabs :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
7 participants