Skip to content

Commit

Permalink
Improve documentation
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 5, 2023
1 parent c79db7c commit dafb043
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
22 changes: 13 additions & 9 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1130,15 +1130,15 @@ Below is an example of publishing to Vault (using token auth with a local dev in
Important information on types
------------------------------
YAML and JSON type extensions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
YAML, JSON, ENV and INI type extensions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SOPS uses the file extension to decide which encryption method to use on the file
content. ``YAML``, ``JSON``, ``ENV``, and ``INI`` files are treated as trees of data, and key/values are
extracted from the files to only encrypt the leaf values. The tree structure is also
used to check the integrity of the file.
Therefore, if a file is encrypted using a specific format, it need to be decrypted
Therefore, if a file is encrypted using a specific format, it needs to be decrypted
in the same format. The easiest way to achieve this is to conserve the original file
extension after encrypting a file. For example:
Expand All @@ -1165,23 +1165,27 @@ When operating on stdin, use the ``--input-type`` and ``--output-type`` flags as
JSON indentation
~~~~~~~~~~~~~~~~
``sops`` indent ``SOPS`` 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
by configuring ``.sops.yaml`` with the code below. (value ``0`` is no 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
by configuring ``.sops.yaml`` with the code below.
The special value ``0`` disables indentation, and ``-1`` uses a single tab.
.. code:: yaml
stores:
json:
indent: 2
YAML indentation
~~~~~~~~~~~~~~~~
``sops`` indent ``YAML`` files by default using 4 spaces. However, you can change
this default behaviour by either using the additional ``--indent=2`` cli option or
by configuring ``.sops.yaml`` with :
SOPS indents ``YAML`` files by default using 4 spaces. However, you can change
this default behaviour by either using the additional ``--indent=2`` CLI option or
by configuring ``.sops.yaml`` with:
.. code:: yaml
stores:
yaml:
indent: 2
Expand Down
4 changes: 2 additions & 2 deletions cmd/sops/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ func main() {
},
cli.IntFlag{
Name: "indent",
Usage: "the number of space to indent YAML encoded file for encryption",
Usage: "the number of spaces to indent YAML or JSON encoded file for encryption",
},
cli.BoolFlag{
Name: "verbose",
Expand Down Expand Up @@ -1077,7 +1077,7 @@ func inputStore(context *cli.Context, path string) common.Store {

func outputStore(context *cli.Context, path string) common.Store {
storesConf, _ := loadStoresConfig(context, path)
if context.Int("indent") != 0 {
if context.IsSet("indent") {
indent := context.Int("indent")
storesConf.YAML.Indent = indent
storesConf.JSON.Indent = indent
Expand Down

0 comments on commit dafb043

Please sign in to comment.