Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SOPS: Secrets OPerationS
========================

**SOPS** is an editor of encrypted files that supports YAML, JSON, ENV, INI and BINARY
**SOPS** is an editor of encrypted files that supports YAML, JSON, XML, ENV, INI and BINARY
formats and encrypts with AWS KMS, GCP KMS, Azure Key Vault, HuaweiCloud KMS, age, and PGP.
(`demo <https://www.youtube.com/watch?v=YTEVyLXFiq0>`_)

Expand Down
6 changes: 6 additions & 0 deletions cmd/sops/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/getsops/sops/v3/stores/dotenv"
"github.com/getsops/sops/v3/stores/ini"
"github.com/getsops/sops/v3/stores/json"
"github.com/getsops/sops/v3/stores/xml"
"github.com/getsops/sops/v3/stores/yaml"
"github.com/getsops/sops/v3/version"
"github.com/mitchellh/go-wordwrap"
Expand Down Expand Up @@ -55,6 +56,10 @@ func newJsonStore(c *config.StoresConfig) Store {
return json.NewStore(&c.JSON)
}

func newXmlStore(c *config.StoresConfig) Store {
return xml.NewStore(&c.XML)
}

func newYamlStore(c *config.StoresConfig) Store {
return yaml.NewStore(&c.YAML)
}
Expand All @@ -64,6 +69,7 @@ var storeConstructors = map[Format]storeConstructor{
Dotenv: newDotenvStore,
Ini: newIniStore,
Json: newJsonStore,
Xml: newXmlStore,
Yaml: newYamlStore,
}

Expand Down
9 changes: 9 additions & 0 deletions cmd/sops/formats/formats.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
Dotenv
Ini
Json
Xml
Yaml
)

Expand All @@ -18,6 +19,7 @@ var stringToFormat = map[string]Format{
"dotenv": Dotenv,
"ini": Ini,
"json": Json,
"xml": Xml,
"yaml": Yaml,
}

Expand Down Expand Up @@ -51,6 +53,11 @@ func IsIniFile(path string) bool {
return strings.HasSuffix(path, ".ini")
}

// IsXMLFile returns true if a given file path corresponds to a XML file
func IsXMLFile(path string) bool {
return strings.HasSuffix(path, ".xml")
}

// FormatForPath returns the correct format given the path to a file
func FormatForPath(path string) Format {
format := Binary // default
Expand All @@ -62,6 +69,8 @@ func FormatForPath(path string) Format {
format = Dotenv
} else if IsIniFile(path) {
format = Ini
} else if IsXMLFile(path) {
format = Xml
}
return format
}
Expand Down
37 changes: 19 additions & 18 deletions cmd/sops/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,11 @@ func main() {
},
cli.StringFlag{
Name: "input-type",
Usage: "currently ini, json, yaml, dotenv and binary are supported. If not set, sops will use the file's extension to determine the type",
Usage: "currently ini, json, xml, yaml, dotenv and binary are supported. If not set, sops will use the file's extension to determine the type",
},
cli.StringFlag{
Name: "output-type",
Usage: "currently ini, json, yaml, dotenv and binary are supported. If not set, sops will use the input file's extension to determine the output format",
Usage: "currently ini, json, xml, yaml, dotenv and binary are supported. If not set, sops will use the input file's extension to determine the output format",
},
cli.StringFlag{
Name: "filename",
Expand Down Expand Up @@ -517,7 +517,7 @@ func main() {
Flags: []cli.Flag{
cli.StringFlag{
Name: "input-type",
Usage: "currently ini, json, yaml, dotenv and binary are supported. If not set, sops will use the file's extension to determine the type",
Usage: "currently ini, json, xml, yaml, dotenv and binary are supported. If not set, sops will use the file's extension to determine the type",
},
},
Action: func(c *cli.Context) error {
Expand Down Expand Up @@ -732,7 +732,7 @@ func main() {
},
cli.StringFlag{
Name: "input-type",
Usage: "currently ini, json, yaml, dotenv and binary are supported. If not set, sops will use the file's extension to determine the type",
Usage: "currently ini, json, xml, yaml, dotenv and binary are supported. If not set, sops will use the file's extension to determine the type",
},
}, keyserviceFlags...),
Action: func(c *cli.Context) error {
Expand Down Expand Up @@ -801,11 +801,11 @@ func main() {
},
cli.StringFlag{
Name: "input-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
},
cli.StringFlag{
Name: "output-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
},
cli.BoolFlag{
Name: "ignore-mac",
Expand Down Expand Up @@ -972,11 +972,11 @@ func main() {
},
cli.StringFlag{
Name: "input-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
},
cli.StringFlag{
Name: "output-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
},
cli.StringFlag{
Name: "unencrypted-suffix",
Expand Down Expand Up @@ -1125,11 +1125,11 @@ func main() {
},
cli.StringFlag{
Name: "input-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
},
cli.StringFlag{
Name: "output-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
},
cli.StringFlag{
Name: "encryption-context",
Expand Down Expand Up @@ -1331,11 +1331,11 @@ func main() {
},
cli.StringFlag{
Name: "input-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
},
cli.StringFlag{
Name: "output-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
},
cli.StringFlag{
Name: "unencrypted-suffix",
Expand Down Expand Up @@ -1457,11 +1457,11 @@ func main() {
Flags: append([]cli.Flag{
cli.StringFlag{
Name: "input-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
},
cli.StringFlag{
Name: "output-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
},
cli.BoolFlag{
Name: "value-file",
Expand Down Expand Up @@ -1593,11 +1593,11 @@ func main() {
Flags: append([]cli.Flag{
cli.StringFlag{
Name: "input-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
},
cli.StringFlag{
Name: "output-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
},
cli.IntFlag{
Name: "shamir-secret-sharing-threshold",
Expand Down Expand Up @@ -1752,11 +1752,11 @@ func main() {
},
cli.StringFlag{
Name: "input-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the file's extension to determine the type",
},
cli.StringFlag{
Name: "output-type",
Usage: "currently json, yaml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
Usage: "currently json, yaml, xml, dotenv, ini and binary are supported. If not set, sops will use the input file's extension to determine the output format",
},
cli.BoolFlag{
Name: "show-master-keys, s",
Expand Down Expand Up @@ -2401,6 +2401,7 @@ func outputStore(context *cli.Context, path string) (common.Store, error) {
storesConf.YAML.Indent = indent
storesConf.JSON.Indent = indent
storesConf.JSONBinary.Indent = indent
storesConf.XML.Indent = indent
}

return common.DefaultStoreForPathOrFormat(storesConf, path, context.String("output-type")), nil
Expand Down
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,17 @@ type YAMLStoreConfig struct {
Indent int `yaml:"indent"`
}

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

type StoresConfig struct {
Dotenv DotenvStoreConfig `yaml:"dotenv"`
INI INIStoreConfig `yaml:"ini"`
JSONBinary JSONBinaryStoreConfig `yaml:"json_binary"`
JSON JSONStoreConfig `yaml:"json"`
YAML YAMLStoreConfig `yaml:"yaml"`
XML XMLStoreConfig `yaml:"xml"`
}

type configFile struct {
Expand Down Expand Up @@ -263,6 +268,7 @@ func NewStoresConfig() *StoresConfig {
storesConfig := &StoresConfig{}
storesConfig.JSON.Indent = -1
storesConfig.JSONBinary.Indent = -1
storesConfig.XML.Indent = -1
return storesConfig
}

Expand Down
Loading
Loading