-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
ks | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
|
||
} |