diff --git a/README.rst b/README.rst index cce88cbc54..c6151315c8 100644 --- a/README.rst +++ b/README.rst @@ -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 @@ -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 ~~~~~~~~~~~~~~~~ diff --git a/cmd/sops/main.go b/cmd/sops/main.go index 9dfb63e6da..a1d4807a11 100644 --- a/cmd/sops/main.go +++ b/cmd/sops/main.go @@ -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")) diff --git a/config/config.go b/config/config.go index 8ab15c235a..6432686824 100644 --- a/config/config.go +++ b/config/config.go @@ -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"` @@ -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 } diff --git a/stores/json/store.go b/stores/json/store.go index 3744563bca..cbecd83624 100644 --- a/stores/json/store.go +++ b/stores/json/store.go @@ -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