Skip to content

Commit

Permalink
Add indentation settings for json_binary
Browse files Browse the repository at this point in the history
Signed-off-by: Bastien <bastien.wermeille@gmail.com>
  • Loading branch information
Ph0tonic committed Nov 14, 2023
1 parent c83ab24 commit bcd1feb
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
6 changes: 4 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1162,8 +1162,8 @@ When operating on stdin, use the ``--input-type`` and ``--output-type`` flags as
$ cat myfile.json | sops --input-type json --output-type json -d /dev/stdin
JSON indentation
~~~~~~~~~~~~~~~~
JSON and JSON_binary indentation
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SOPS indents ``JSON`` files by default using one ``tab``. However, you can change
this default behaviour to use ``spaces`` by either using the additional ``--indent=2`` CLI option or
Expand All @@ -1176,6 +1176,8 @@ The special value ``0`` disables indentation, and ``-1`` uses a single tab.
stores:
json:
indent: 2
json_binary:
indent: 2
YAML indentation
~~~~~~~~~~~~~~~~
Expand Down
1 change: 1 addition & 0 deletions cmd/sops/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,7 @@ func outputStore(context *cli.Context, path string) common.Store {
indent := context.Int("indent")
storesConf.YAML.Indent = indent
storesConf.JSON.Indent = indent
storesConf.JSONBinary.Indent = indent
}

return common.DefaultStoreForPathOrFormat(storesConf, path, context.String("output-type"))
Expand Down
11 changes: 7 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ type DotenvStoreConfig struct{}

type INIStoreConfig struct{}

type JSONStoreConfig struct{
type JSONStoreConfig struct {
Indent int `yaml:"indent"`
}

type JSONBinaryStoreConfig struct{}
type JSONBinaryStoreConfig struct {
Indent int `yaml:"indent"`
}

type YAMLStoreConfig struct {
Indent int `yaml:"indent"`
Expand Down Expand Up @@ -149,9 +151,10 @@ type creationRule struct {
MACOnlyEncrypted bool `yaml:"mac_only_encrypted"`
}

func NewStoresConfig() *StoresConfig{
storesConfig := &StoresConfig{}
func NewStoresConfig() *StoresConfig {
storesConfig := &StoresConfig{}
storesConfig.JSON.Indent = -1
storesConfig.JSONBinary.Indent = -1
return storesConfig
}

Expand Down
4 changes: 3 additions & 1 deletion stores/json/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ type BinaryStore struct {
}

func NewBinaryStore(c *config.JSONBinaryStoreConfig) *BinaryStore {
return &BinaryStore{config: *c}
return &BinaryStore{config: *c, store: *NewStore(&config.JSONStoreConfig{
Indent: c.Indent,
})}
}

// LoadEncryptedFile loads an encrypted json file onto a sops.Tree object
Expand Down

0 comments on commit bcd1feb

Please sign in to comment.