diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..fccad86 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +ks +.DS_Store diff --git a/README.md b/README.md index 9e305d0..0876715 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,32 @@ # ks Utility to make kubeseal --raw a bit easier. + +## Installation + + + +## Usage + +```bash +% ks +[-s|--secret] is required +usage: print [-h|--help] -s|--secret "" [-s|--secret "" ...] + [-c|--controller ""] [-n|--namespace ""] [--scope + ""] + + Prints provided string to stdout + +Arguments: + + -h --help Print help information + -s --secret Secrets. + -c --controller Sealed secrets controller name.. Default: sealed-secrets + -n --namespace Sealed secrets controller namespace.. Default: + sealed-secrets + --scope Sealed secret scope.. Default: cluster-wide + +``` + +```bash +ks -s secret1 -s secret2 +``` \ No newline at end of file diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..c854a79 --- /dev/null +++ b/go.mod @@ -0,0 +1,7 @@ +module github.com/alphabet5/ks/v2 + +go 1.17 + +require ( + github.com/akamensky/argparse v1.3.1 // indirect +) diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..7456fbf --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/akamensky/argparse v1.3.1 h1:kP6+OyvR0fuBH6UhbE6yh/nskrDEIQgEA1SUXDPjx4g= +github.com/akamensky/argparse v1.3.1/go.mod h1:S5kwC7IuDcEr5VeXtGPRVZ5o/FdhcMlQz4IZQuw64xA= diff --git a/ks.go b/ks.go new file mode 100644 index 0000000..910c34c --- /dev/null +++ b/ks.go @@ -0,0 +1,50 @@ +package main + +import ( + "fmt" + "github.com/akamensky/argparse" + "os" + "os/exec" +) + +func main() { + // Create new parser object + parser := argparse.NewParser("print", "Prints provided string to stdout") + // Create string flag + s := parser.StringList("s", "secret", &argparse.Options{Required: true, Help: "Secrets."}) + c := parser.String("c", "controller", &argparse.Options{Required: false, Default: "sealed-secrets", Help: "Sealed secrets controller name."}) + n := parser.String("n", "namespace", &argparse.Options{Required: false, Default: "sealed-secrets", Help: "Sealed secrets controller namespace."}) + scope := parser.String("", "scope", &argparse.Options{Required: false, Default: "cluster-wide", Help: "Sealed secret scope."}) + // Parse input + err := parser.Parse(os.Args) + if err != nil { + // In case of error print error and print usage + // This can also be done by passing -h or --help flags + fmt.Print(parser.Usage(err)) + } + + input_secrets := *s + input_controller := *c + input_namespace := *n + input_scope := *scope + + for _, secret := range input_secrets { + fmt.Println(secret) + cmd := exec.Command("bash", "-c", + "echo -n \""+secret+ + "\" | kubeseal --controller-namespace "+input_namespace+ + " --raw --scope "+input_scope+ + " --from-file=/dev/stdin --controller-name "+input_controller, + ) + stdout, err := cmd.Output() + + if err != nil { + fmt.Println(err.Error()) + return + } + + // Print the output + fmt.Println(string(stdout)) + } + +} \ No newline at end of file