Add indentation settings for json_binary

Signed-off-by: Bastien <bastien.wermeille@gmail.com>
This commit is contained in:
Bastien 2023-11-14 07:27:47 +01:00 коммит произвёл Bastien Wermeille
Родитель 8a63bb0d21
Коммит 42018ef4a5
4 изменённых файлов: 15 добавлений и 7 удалений

Просмотреть файл

@ -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
~~~~~~~~~~~~~~~~

Просмотреть файл

@ -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"))

Просмотреть файл

@ -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
}

Просмотреть файл

@ -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