Skip to content

Commit

Permalink
Initial commit.
Browse files Browse the repository at this point in the history
  • Loading branch information
alphabet5 committed Feb 7, 2022
1 parent 6516fa0 commit ee58650
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

ks
.DS_Store
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 "<value>" [-s|--secret "<value>" ...]
[-c|--controller "<value>"] [-n|--namespace "<value>"] [--scope
"<value>"]

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
```
7 changes: 7 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module github.com/alphabet5/ks/v2

go 1.17

require (
github.com/akamensky/argparse v1.3.1 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
50 changes: 50 additions & 0 deletions ks.go
Original file line number Diff line number Diff line change
@@ -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))
}

}

0 comments on commit ee58650

Please sign in to comment.