Skip to content

Commit

Permalink
Add some additional debug output for SOPS decryption (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
dee-kryvenko authored Mar 17, 2023
1 parent a95b480 commit 1c0b237
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.1.4] - 2023-03-16

### Added

- Add some additional debug output for SOPS decryption

## [0.1.3] - 2023-02-15

### Fixed
Expand Down
12 changes: 10 additions & 2 deletions crypt/sops.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package crypt

import (
"fmt"
"log"
"os"
"strconv"

Expand Down Expand Up @@ -70,17 +71,24 @@ func (p *SOPSEncryptionProvider) Encrypt(data []byte) ([]byte, error) {
// Decrypt will decrypt the data in buffer.
func (p *SOPSEncryptionProvider) Decrypt(data []byte) ([]byte, error) {
inputStore := &sopsjson.Store{}
tree, _ := inputStore.LoadEncryptedFile(data)
tree, err := inputStore.LoadEncryptedFile(data)
if err != nil {
return nil, err
}

if tree.Metadata.Version == "" {
log.Println("SOPS metadata version was not set, assuming state was not previously encrypted and returning as-is document")
return data, nil
}

_, _ = common.DecryptTree(common.DecryptTreeOpts{
_, err = common.DecryptTree(common.DecryptTreeOpts{
Cipher: aes.NewCipher(),
Tree: &tree,
KeyServices: []keyservice.KeyServiceClient{keyservice.NewLocalClient()},
})
if err != nil {
return nil, err
}

outputStore := &sopsjson.Store{}
return outputStore.EmitPlainFile(tree.Branches)
Expand Down

0 comments on commit 1c0b237

Please sign in to comment.