Add sops config subcommand to print matched .sops.yaml rules as JSON#2190
Open
djgoku wants to merge 3 commits into
Open
Add sops config subcommand to print matched .sops.yaml rules as JSON#2190djgoku wants to merge 3 commits into
sops config subcommand to print matched .sops.yaml rules as JSON#2190djgoku wants to merge 3 commits into
Conversation
A pure, file-IO-free helper that returns which creation_rule and destination_rule from .sops.yaml apply to a given absolute file path. Mirrors parseCreationRuleForFile's first-match-wins semantics; uses filepath.Rel for platform-aware path normalization. Also adds NoRulesMatched (62) to the codes package for an upcoming 'sops config --require-match' flag.
Wraps MatchRulesForFile and emits a versioned JSON view (schema_version: 1) of the creation_rule and destination_rule that apply to a given file. The --require-match flag exits with codes.NoRulesMatched (62) when no rule applies while still printing the empty result. Output omits dead recipient fields when key_groups is set (sops's parser uses one or the other), and splits Azure Key Vault URLs into vaultUrl/key/version to match azkv.NewMasterKeyFromURL's parsing.
Exercises path normalization through Run using t.TempDir() fixtures: absolute paths inside/outside the config tree, nested subdirs, non-existent paths, and the --config override. Includes a contract test pinning codes.NoRulesMatched to 62.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sops config <file>prints the.sops.yamlrules (creation anddestination) that apply to a given file path, as JSON. Useful for
previewing which keys would encrypt a file, debugging which
path_regexrule wins, and tooling integration. Only the path is used — the file
does not need to exist on disk.
Example
With
--require-match, exits with newcodes.NoRulesMatched(62) whenno rule applies, while still printing the empty JSON.
Related
Partially addresses #1758 — the no-match case is now introspectable via
sops configeven thoughfilestatusitself is unchanged.