Skip to content

Commit a83edf0

Browse files
committed
added version, small refactor
1 parent 2e20213 commit a83edf0

File tree

3 files changed

+37
-19
lines changed

3 files changed

+37
-19
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.DS_Store
22
build
3+
ringo

build.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ set -e
44

55
rm -rf build
66

7+
LATEST_TAG=$(git describe --tags)
8+
79
gox -output 'build/{{.OS}}_{{.Arch}}/ringo' \
810
--os "linux darwin windows" \
911
-arch "386 amd64" \
10-
-osarch '!darwin/386'
12+
-osarch '!darwin/386' \
13+
-ldflags="-X 'main.Version=${LATEST_TAG}'"
1114

1215
for rls in build/{linux,darwin}*; do \
1316
tar czf build/ringo-$(echo ${rls} | cut -f2 -d/).tgz -C ${rls} ringo; \

main.go

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,55 +11,69 @@ import (
1111
"github.com/manifoldco/promptui"
1212
)
1313

14-
var secretsFilename string
14+
var (
15+
Version = "v0.0.0-dev"
16+
secretsFilename string
17+
)
1518

1619
func main() {
20+
showVersion := flag.Bool("version", false, "show ringo version")
1721
flag.StringVar(&secretsFilename, "filename", "config/secrets.yml", "the file containing the secrets to decrypt")
1822
flag.Parse()
1923

24+
if *showVersion {
25+
fmt.Print(Version)
26+
os.Exit(1)
27+
}
28+
2029
if _, err := os.Open(secretsFilename); err != nil {
2130
if errors.Is(err, os.ErrNotExist) {
2231
fmt.Println("'config/secrets.yml' file not found!\nYou can use the -filename flag for a different path")
2332
return
2433
}
25-
panic(err)
34+
fmt.Print(err)
35+
os.Exit(1)
2636
}
2737

2838
if err := biscuit.KmsCallerIdentity(); err != nil {
2939
fmt.Print(err)
3040
os.Exit(1)
3141
}
3242

33-
list, err := biscuit.List(secretsFilename)
43+
secrets, err := biscuit.List(secretsFilename)
3444
if err != nil {
3545
fmt.Print(err)
3646
os.Exit(1)
3747
}
3848

39-
prompt := promptui.Select{
40-
Label: "Select a secret to decrypt",
41-
Items: list,
42-
Size: 10,
43-
Searcher: func(input string, index int) bool {
44-
name := strings.Replace(strings.ToLower(list[index]), " ", "", -1)
45-
input = strings.Replace(strings.ToLower(input), " ", "", -1)
46-
return strings.Contains(name, input)
47-
},
48-
}
49-
50-
_, result, err := prompt.Run()
49+
selectedSecret, err := loadSecretsSelection(secrets)
5150
if err != nil {
5251
// this happens when you ^C the prompt
5352
return
5453
}
5554

56-
fmt.Printf("Decrypting %q\n", result)
57-
58-
res, err := biscuit.Get(secretsFilename, result)
55+
fmt.Printf("Decrypting %q\n", selectedSecret)
56+
res, err := biscuit.Get(secretsFilename, selectedSecret)
5957
if err != nil {
6058
fmt.Print(err)
6159
os.Exit(1)
6260
}
6361

6462
fmt.Println(res)
6563
}
64+
65+
func loadSecretsSelection(secrets []string) (string, error) {
66+
prompt := promptui.Select{
67+
Label: "Select a secret to decrypt",
68+
Items: secrets,
69+
Size: 10,
70+
Searcher: func(input string, index int) bool {
71+
name := strings.Replace(strings.ToLower(secrets[index]), " ", "", -1)
72+
input = strings.Replace(strings.ToLower(input), " ", "", -1)
73+
return strings.Contains(name, input)
74+
},
75+
}
76+
77+
_, result, err := prompt.Run()
78+
return result, err
79+
}

0 commit comments

Comments
 (0)