зеркало из https://github.com/getsops/sops.git
Renamed Load to Unmarshal and Dump to Marshal
This commit is contained in:
Родитель
58dec6fbf2
Коммит
323db94104
|
@ -182,7 +182,7 @@ func store(path string) sops.Store {
|
|||
|
||||
func decryptFile(store sops.Store, fileBytes []byte, ignoreMac bool) (sops.Tree, error) {
|
||||
var tree sops.Tree
|
||||
metadata, err := store.LoadMetadata(fileBytes)
|
||||
metadata, err := store.UnmarshalMetadata(fileBytes)
|
||||
if err != nil {
|
||||
return tree, cli.NewExitError(fmt.Sprintf("Error loading file: %s", err), exitCouldNotReadInputFile)
|
||||
}
|
||||
|
@ -190,7 +190,7 @@ func decryptFile(store sops.Store, fileBytes []byte, ignoreMac bool) (sops.Tree,
|
|||
if err != nil {
|
||||
return tree, cli.NewExitError(err.Error(), exitCouldNotRetrieveKey)
|
||||
}
|
||||
branch, err := store.Load(fileBytes)
|
||||
branch, err := store.Unmarshal(fileBytes)
|
||||
if err != nil {
|
||||
return tree, cli.NewExitError(fmt.Sprintf("Error loading file: %s", err), exitCouldNotReadInputFile)
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ func decrypt(c *cli.Context, file string, fileBytes []byte, output io.Writer) er
|
|||
return nil
|
||||
}
|
||||
}
|
||||
out, err := store.Dump(tree.Branch)
|
||||
out, err := store.Marshal(tree.Branch)
|
||||
if err != nil {
|
||||
return cli.NewExitError(fmt.Sprintf("Error dumping file: %s", err), exitErrorDumpingTree)
|
||||
}
|
||||
|
@ -256,7 +256,7 @@ func generateKey(tree *sops.Tree) ([]byte, error) {
|
|||
|
||||
func encrypt(c *cli.Context, file string, fileBytes []byte, output io.Writer) error {
|
||||
store := store(file)
|
||||
branch, err := store.Load(fileBytes)
|
||||
branch, err := store.Unmarshal(fileBytes)
|
||||
if err != nil {
|
||||
return cli.NewExitError(fmt.Sprintf("Error loading file: %s", err), exitCouldNotReadInputFile)
|
||||
}
|
||||
|
@ -311,7 +311,7 @@ func encrypt(c *cli.Context, file string, fileBytes []byte, output io.Writer) er
|
|||
return cli.NewExitError(fmt.Sprintf("Could not encrypt MAC: %s", err), exitErrorEncryptingTree)
|
||||
}
|
||||
metadata.MessageAuthenticationCode = encryptedMac
|
||||
out, err := store.DumpWithMetadata(tree.Branch, metadata)
|
||||
out, err := store.MarshalWithMetadata(tree.Branch, metadata)
|
||||
_, err = output.Write([]byte(out))
|
||||
if err != nil {
|
||||
return cli.NewExitError(fmt.Sprintf("Could not write to output stream: %s", err), exitCouldNotWriteOutputFile)
|
||||
|
@ -339,7 +339,7 @@ func rotate(c *cli.Context, file string, fileBytes []byte, output io.Writer) err
|
|||
tree.Metadata.RemoveKMSMasterKeys(c.String("rm-kms"))
|
||||
tree.Metadata.RemovePGPMasterKeys(c.String("rm-pgp"))
|
||||
tree.Metadata.UpdateMasterKeys(newKey)
|
||||
out, err := store.DumpWithMetadata(tree.Branch, tree.Metadata)
|
||||
out, err := store.MarshalWithMetadata(tree.Branch, tree.Metadata)
|
||||
|
||||
_, err = output.Write([]byte(out))
|
||||
if err != nil {
|
||||
|
|
|
@ -14,8 +14,8 @@ import (
|
|||
type Store struct {
|
||||
}
|
||||
|
||||
// Load takes an input json string and returns a sops tree branch
|
||||
func (store Store) Load(in []byte) (sops.TreeBranch, error) {
|
||||
// Unmarshal takes an input json string and returns a sops tree branch
|
||||
func (store Store) Unmarshal(in []byte) (sops.TreeBranch, error) {
|
||||
var branch sops.TreeBranch
|
||||
err := json.Unmarshal(in, branch)
|
||||
if err != nil {
|
||||
|
@ -29,8 +29,8 @@ func (store Store) Load(in []byte) (sops.TreeBranch, error) {
|
|||
return branch, nil
|
||||
}
|
||||
|
||||
// Dump performs the opposite operation to Load, it takes a sops tree branch and returns a json formatted string
|
||||
func (store Store) Dump(tree sops.TreeBranch) ([]byte, error) {
|
||||
// Marshal takes a sops tree branch and returns a json formatted string
|
||||
func (store Store) Marshal(tree sops.TreeBranch) ([]byte, error) {
|
||||
out, err := json.Marshal(tree)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Error marshaling to json: %s", err)
|
||||
|
@ -38,8 +38,8 @@ func (store Store) Dump(tree sops.TreeBranch) ([]byte, error) {
|
|||
return out, nil
|
||||
}
|
||||
|
||||
// DumpWithMetadata takes a sops tree branch and sops metadata and marshals them to json.
|
||||
func (store Store) DumpWithMetadata(tree sops.TreeBranch, metadata sops.Metadata) ([]byte, error) {
|
||||
// MarshalWithMetadata takes a sops tree branch and sops metadata and marshals them to json.
|
||||
func (store Store) MarshalWithMetadata(tree sops.TreeBranch, metadata sops.Metadata) ([]byte, error) {
|
||||
tree = append(tree, sops.TreeItem{Key: "sops", Value: metadata.ToMap()})
|
||||
out, err := json.Marshal(tree)
|
||||
if err != nil {
|
||||
|
@ -48,8 +48,8 @@ func (store Store) DumpWithMetadata(tree sops.TreeBranch, metadata sops.Metadata
|
|||
return out, nil
|
||||
}
|
||||
|
||||
// LoadMetadata takes a json string and extracts sops' metadata from it
|
||||
func (store Store) LoadMetadata(in []byte) (sops.Metadata, error) {
|
||||
// UnmarshalMetadata takes a json string and extracts sops' metadata from it
|
||||
func (store Store) UnmarshalMetadata(in []byte) (sops.Metadata, error) {
|
||||
var ok bool
|
||||
var metadata sops.Metadata
|
||||
data := make(map[string]interface{})
|
||||
|
|
8
sops.go
8
sops.go
|
@ -208,10 +208,10 @@ type MasterKey interface {
|
|||
|
||||
// Store provides a way to load and save the sops tree along with metadata
|
||||
type Store interface {
|
||||
Load(in []byte) (TreeBranch, error)
|
||||
LoadMetadata(in []byte) (Metadata, error)
|
||||
Dump(TreeBranch) ([]byte, error)
|
||||
DumpWithMetadata(TreeBranch, Metadata) ([]byte, error)
|
||||
Unmarshal(in []byte) (TreeBranch, error)
|
||||
UnmarshalMetadata(in []byte) (Metadata, error)
|
||||
Marshal(TreeBranch) ([]byte, error)
|
||||
MarshalWithMetadata(TreeBranch, Metadata) ([]byte, error)
|
||||
}
|
||||
|
||||
// MasterKeyCount returns the number of master keys available
|
||||
|
|
|
@ -25,8 +25,8 @@ func (store Store) mapSliceToTreeBranch(in yaml.MapSlice) sops.TreeBranch {
|
|||
return branch
|
||||
}
|
||||
|
||||
// Load takes a YAML document as input and unmarshals it into a sops tree, returning the tree
|
||||
func (store Store) Load(in []byte) (sops.TreeBranch, error) {
|
||||
// Unmarshal takes a YAML document as input and unmarshals it into a sops tree, returning the tree
|
||||
func (store Store) Unmarshal(in []byte) (sops.TreeBranch, error) {
|
||||
var data yaml.MapSlice
|
||||
if err := yaml.Unmarshal(in, &data); err != nil {
|
||||
return nil, fmt.Errorf("Error unmarshaling input YAML: %s", err)
|
||||
|
@ -96,8 +96,8 @@ func (store Store) treeBranchToYamlMap(in sops.TreeBranch) yaml.MapSlice {
|
|||
return branch
|
||||
}
|
||||
|
||||
// Dump takes a sops tree branch and marshals it into a yaml document
|
||||
func (store Store) Dump(tree sops.TreeBranch) ([]byte, error) {
|
||||
// Marshal takes a sops tree branch and marshals it into a yaml document
|
||||
func (store Store) Marshal(tree sops.TreeBranch) ([]byte, error) {
|
||||
yamlMap := store.treeBranchToYamlMap(tree)
|
||||
out, err := yaml.Marshal(yamlMap)
|
||||
if err != nil {
|
||||
|
@ -106,8 +106,8 @@ func (store Store) Dump(tree sops.TreeBranch) ([]byte, error) {
|
|||
return out, nil
|
||||
}
|
||||
|
||||
// DumpWithMetadata takes a sops tree branch and metadata and marshals them into a yaml document
|
||||
func (store Store) DumpWithMetadata(tree sops.TreeBranch, metadata sops.Metadata) ([]byte, error) {
|
||||
// MarshalWithMetadata takes a sops tree branch and metadata and marshals them into a yaml document
|
||||
func (store Store) MarshalWithMetadata(tree sops.TreeBranch, metadata sops.Metadata) ([]byte, error) {
|
||||
yamlMap := store.treeBranchToYamlMap(tree)
|
||||
yamlMap = append(yamlMap, yaml.MapItem{Key: "sops", Value: metadata.ToMap()})
|
||||
out, err := yaml.Marshal(yamlMap)
|
||||
|
@ -117,8 +117,8 @@ func (store Store) DumpWithMetadata(tree sops.TreeBranch, metadata sops.Metadata
|
|||
return out, nil
|
||||
}
|
||||
|
||||
// LoadMetadata takes a yaml document as a string and extracts sops' metadata from it
|
||||
func (store *Store) LoadMetadata(in []byte) (sops.Metadata, error) {
|
||||
// UnmarshalMetadata takes a yaml document as a string and extracts sops' metadata from it
|
||||
func (store *Store) UnmarshalMetadata(in []byte) (sops.Metadata, error) {
|
||||
var metadata sops.Metadata
|
||||
var ok bool
|
||||
data := make(map[interface{}]interface{})
|
||||
|
|
Загрузка…
Ссылка в новой задаче