feat: autoseal file in current dir
This commit is contained in:
parent
1ac25d1792
commit
7525654ad3
1 changed files with 46 additions and 2 deletions
48
main.go
48
main.go
|
@ -1,7 +1,51 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("hello world")
|
||||
entries, err := os.ReadDir("./")
|
||||
if err != nil {
|
||||
log.Fatal("unable to read current directory:", err)
|
||||
}
|
||||
|
||||
for _, e := range entries {
|
||||
name := e.Name()
|
||||
ext := filepath.Ext(name)
|
||||
nameNoExt := name[0 : len(name)-len(ext)]
|
||||
if !strings.HasSuffix(nameNoExt, ".sealme") {
|
||||
continue
|
||||
}
|
||||
naked := nameNoExt[0 : len(nameNoExt)-len(".sealme")]
|
||||
|
||||
out := naked + ext
|
||||
fmt.Println("sealing", name, "to", out)
|
||||
cmd := exec.Command("kubeseal", "-o", "yaml", "--controller-namespace=flux-system")
|
||||
|
||||
inf, err := os.Open(name)
|
||||
if err != nil {
|
||||
log.Println("failed to open", name+":", err)
|
||||
continue
|
||||
}
|
||||
defer inf.Close()
|
||||
cmd.Stdin = inf
|
||||
|
||||
outf, err := os.Create(out)
|
||||
if err != nil {
|
||||
log.Println("failed to create", name+":", err)
|
||||
continue
|
||||
}
|
||||
defer outf.Close()
|
||||
cmd.Stdout = outf
|
||||
|
||||
if err = cmd.Run(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue