Skip to content

feat: add TOML store#2031

Draft
jcmfernandes wants to merge 7 commits intogetsops:mainfrom
bckground:toml-store
Draft

feat: add TOML store#2031
jcmfernandes wants to merge 7 commits intogetsops:mainfrom
bckground:toml-store

Conversation

@jcmfernandes
Copy link

@jcmfernandes jcmfernandes commented Jan 2, 2026

Fixes #369. Supersedes #812 (that in turn superseded #533). Hopefully, the third time's the charm.

Uses github.com/pelletier/go-toml/v2. It discards comments.

Signed-off-by: João Fernandes <joao@bckground.com>
Signed-off-by: João Fernandes <joao@bckground.com>
Signed-off-by: João Fernandes <joao@bckground.com>
Signed-off-by: João Fernandes <joao@bckground.com>
Signed-off-by: João Fernandes <joao@bckground.com>
@jcmfernandes jcmfernandes force-pushed the toml-store branch 2 times, most recently from e3b5072 to d0bf7b4 Compare January 3, 2026 18:00
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 picking this up! It would be great if this store could also handle comments, but it seems the library doesn't really handle them yet.


// Sort each group independently.
sortKeysNaturally(simpleKeys)
sortKeysNaturally(complexKeys)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is a good idea to sort keys. I as a SOPS user expect a store to not modify the key order.

// mapToTreeBranch converts a map[string]any to a sops.TreeBranch.
func mapToTreeBranch(m map[string]any) (sops.TreeBranch, error) {
// Separate keys by type: simple values first, then complex types
// (tables/arrays).
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the rationale for this?

}

// Replace single quotes with double quotes for string values.
result := bytes.ReplaceAll(buf.Bytes(), []byte("'"), []byte("\""))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this?


[2]
21 = [21.1, 21.2]
22 = 22
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to make the indentation configurable?

Copy link
Author

Choose a reason for hiding this comment

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

Unfortunately, no, when using the "normal" API. Please check #2031 (comment) - it might be possible if I go for a different approach.

@jcmfernandes
Copy link
Author

Thanks for picking this up! It would be great if this store could also handle comments, but it seems the library doesn't really handle them yet.

Happy to contribute!

I have good and bad news: the good news is that, to some extent, it's possible to handle comments. Being specific, it's possible to handle start-of-the-line comments, but not end-of-the-line comments, i.e.,

# We can handle these
xpto = 42 # But we can't handle these

The bad news is that this requires using the unstable API and results in significantly more complex code. Should I give it a try?

@felixfontein
Copy link
Contributor

Hmm, good question... Do you know whether the marshaller supports comments (at least start-of-line ones) as well? If it does not, then I guess it doesn't make sense - yet - to support them.

@jcmfernandes
Copy link
Author

Hmm, good question... Do you know whether the marshaller supports comments (at least start-of-line ones) as well? If it does not, then I guess it doesn't make sense - yet - to support them.

The marshaler, i.e., the "normal" github.com/pelletier/go-toml/v2 package does not support marshaling comments. The unstable API does support comments, but only start-of-the-line comments. I can give it a try! It will be more complex, and the unstable API is, well, unstable, making updates possibly more complicated.

@felixfontein
Copy link
Contributor

I can only see parsing code in the unstable API. Can you point me to the unstable API that allows creating TOML files with start-of-the-line comments?

@germandiagogomez
Copy link

Is this patch going to be merged? I need this badly to onboard sops :)

Otherwise I will have to find alternatives for my toml files.

@felixfontein
Copy link
Contributor

That depends. Right now the PR is not mergable because not all commits are signed off. I'm also curious on the answer to my question, I was not able to find code in the library that allows to create TOML files with comments (but then, I didn't search very intensely).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support TOML?

3 participants