From 8cfc9a50d6ddb9a1a91631e1223c482d9905c814 Mon Sep 17 00:00:00 2001 From: Bastien Date: Mon, 13 Nov 2023 08:48:52 +0100 Subject: [PATCH] Add indentation settings for json_binary Signed-off-by: Bastien --- README.rst | 6 ++++-- config/config.go | 11 +++++++---- stores/json/store.go | 4 +++- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/README.rst b/README.rst index 2393c47e9c..e60b395d23 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/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