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
14 changes: 13 additions & 1 deletion pkg/providers/sops/sops.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
type provider struct {
log *log.Logger

Encode string
// KeyType is either "filepath"(default) or "base64".
KeyType string
// Format is --input-type of sops
Expand All @@ -39,6 +40,10 @@ func New(l *log.Logger, cfg api.StaticConfig, awsLogLevel string) *provider {
p := &provider{
log: l,
}
p.Encode = cfg.String("encode")
if p.Encode == "" {
p.Encode = "raw"
}
p.Format = cfg.String("format")
p.KeyType = cfg.String("key_type")
if p.KeyType == "" {
Expand All @@ -60,7 +65,14 @@ func (p *provider) GetString(key string) (string, error) {
if err != nil {
return "", err
}
return string(cleartext), nil
switch p.Encode {
case "raw":
return string(cleartext), nil
case "base64":
return base64.StdEncoding.EncodeToString(cleartext), nil
Comment on lines +68 to +72
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New encode behavior in GetString isn’t covered by unit tests (no tests call GetString in this package). Please add a test that exercises encode=base64 (verifies output matches base64.StdEncoding.EncodeToString of decrypted bytes) and the unsupported encode error path; this may require making decrypt stub-able (e.g., via an injectable function field) or adding a small helper that can be tested directly.

Copilot uses AI. Check for mistakes.
default:
return "", fmt.Errorf("Unsupported encode parameter: '%s'.", p.Encode)
}
}

func (p *provider) GetStringMap(key string) (map[string]interface{}, error) {
Expand Down
24 changes: 24 additions & 0 deletions pkg/providers/sops/sops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,30 @@ func TestNewProviderDefaultKeyType(t *testing.T) {
}
}

func TestNewProviderDefaultEncode(t *testing.T) {
cfg := config.MapConfig{M: map[string]interface{}{}}

p := New(log.New(log.Config{}), cfg, "")

if p.Encode != "raw" {
t.Errorf("Encode = %q, want %q (default)", p.Encode, "raw")
}
}

func TestNewProviderReadsEncodeBase64(t *testing.T) {
cfg := config.MapConfig{
M: map[string]interface{}{
"encode": "base64",
},
}

p := New(log.New(log.Config{}), cfg, "")

if p.Encode != "base64" {
t.Errorf("Encode = %q, want %q", p.Encode, "base64")
}
Comment on lines +251 to +262
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests validate that New reads encode, but they don’t validate the externally observable behavior (that GetString returns base64 when encode=base64). Consider extending coverage to assert the actual returned value/error for each encode mode, so regressions in GetString aren’t missed.

Copilot uses AI. Check for mistakes.
}

// staticCredProvider is a no-op aws.CredentialsProvider used in tests.
type staticCredProvider struct{}

Expand Down
Loading