Switched from example text to example tree

This commit is contained in:
Adrian Utrilla 2016-09-07 13:22:16 -07:00
Родитель 8c9f962c28
Коммит 9eaece6594
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 6BA64E6212CDEBE9
1 изменённых файлов: 34 добавлений и 42 удалений

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

@ -364,55 +364,47 @@ func hashFile(filePath string) ([]byte, error) {
return hash.Sum(result), nil
}
const exampleYaml = `
# Welcome to SOPS. This is the default template.
# Remove these lines and add your data.
# Don't modify the 'sops' section, it contains key material.
example_key: example_value
example_array:
- example_value1
- example_value2
example_multiline: |
this is a
multiline
entry
example_number: 1234.5678
example:
nested:
values: delete_me
example_booleans:
- true
- false
`
const exampleJson = `
{
"example_key": "example_value",
"example_array": [
"example_value1",
"example_value2"
],
"example_number": 1234.5678,
"example_booleans": [true, false]
var exampleTree = sops.TreeBranch{
sops.TreeItem{
Key: "hello",
Value: `Welcome to SOPS! Edit this file as you please!`,
},
sops.TreeItem{
Key: "example_key",
Value: "example_value",
},
sops.TreeItem{
Key: "example_array",
Value: []interface{}{
"example_value1",
"example_value2",
},
},
sops.TreeItem{
Key: "example_number",
Value: 1234.56789,
},
sops.TreeItem{
Key: "example_booleans",
Value: []interface{}{true, false},
},
}
`
const exampleBinary = `
Welcome to SOPS!
Remove this text and add your content to the file.
`
func loadExample(c *cli.Context, file string) (sops.Tree, error) {
var in []byte
var tree sops.Tree
if strings.HasSuffix(file, ".yaml") {
in = []byte(exampleYaml)
} else if strings.HasSuffix(file, ".json") {
in = []byte(exampleJson)
fileStore := store(file)
if _, ok := fileStore.(*json.BinaryStore); ok {
// Get the value under the first key
in = []byte(exampleTree[0].Value.(string))
} else {
in = []byte(exampleBinary)
var err error
in, err = fileStore.Marshal(exampleTree)
if err != nil {
return tree, err
}
}
branch, _ := store(file).Unmarshal(in)
branch, _ := fileStore.Unmarshal(in)
tree.Branch = branch
ks, err := getKeysources(c, file)
if err != nil {