-
Notifications
You must be signed in to change notification settings - Fork 32
/
seal.go
46 lines (40 loc) · 1.16 KB
/
seal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package commands
import (
"fmt"
"github.com/kluctl/kluctl/pkg/deployment"
"github.com/kluctl/kluctl/pkg/seal"
"io/fs"
"path/filepath"
"strings"
)
type SealCommand struct {
c *deployment.DeploymentCollection
}
func NewSealCommand(c *deployment.DeploymentCollection) *SealCommand {
return &SealCommand{
c: c,
}
}
func (cmd *SealCommand) Run(sealer *seal.Sealer) error {
if cmd.c.Project.Config.SealedSecrets.OutputPattern == nil {
return fmt.Errorf("sealedSecrets.outputPattern is not defined")
}
err := filepath.WalkDir(cmd.c.RenderDir, func(p string, d fs.DirEntry, err error) error {
if !strings.HasSuffix(p, deployment.SealmeExt) {
return nil
}
relPath, err := filepath.Rel(cmd.c.RenderDir, p)
if err != nil {
return err
}
targetDir := filepath.Join(cmd.c.Project.SealedSecretsDir, filepath.Dir(relPath))
targetFile := filepath.Join(targetDir, *cmd.c.Project.Config.SealedSecrets.OutputPattern, filepath.Base(p))
targetFile = targetFile[:len(targetFile)-len(deployment.SealmeExt)]
err = sealer.SealFile(p, targetFile)
if err != nil {
return fmt.Errorf("failed sealing %s: %w", filepath.Base(p), err)
}
return nil
})
return err
}