// Load loads a sops config file into a temporary struct func (f *configFile) load(bytes []byte) error { err := yaml.Unmarshal(bytes, f) if err != nil { return fmt.Errorf("Could not unmarshal config file: %s", err) } return nil }
// 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) } for i, item := range data { if item.Key == "sops" { data = append(data[:i], data[i+1:]...) } } return store.mapSliceToTreeBranch(data), nil }
// 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{}) err := yaml.Unmarshal(in, &data) if err != nil { return metadata, fmt.Errorf("Error unmarshalling input yaml: %s", err) } if data, ok = data["sops"].(map[interface{}]interface{}); !ok { return metadata, sops.MetadataNotFound } metadata.MessageAuthenticationCode = data["mac"].(string) lastModified, err := time.Parse(time.RFC3339, data["lastmodified"].(string)) if err != nil { return metadata, fmt.Errorf("Could not parse last modified date: %s", err) } metadata.LastModified = lastModified metadata.UnencryptedSuffix = data["unencrypted_suffix"].(string) if metadata.Version, ok = data["version"].(string); !ok { metadata.Version = strconv.FormatFloat(data["version"].(float64), 'f', -1, 64) } if k, ok := data["kms"].([]interface{}); ok { ks, err := store.kmsEntries(k) if err == nil { metadata.KeySources = append(metadata.KeySources, ks) } } if pgp, ok := data["pgp"].([]interface{}); ok { ks, err := store.pgpEntries(pgp) if err == nil { metadata.KeySources = append(metadata.KeySources, ks) } } return metadata, nil }