Skip to content

Commit 0a6a6b4

Browse files
author
Robin Diddams
authored
Merge pull request #124 from pinpt/auth-command
Add encrypt and decrypt commands 🔐
2 parents 8dca493 + e0fcf20 commit 0a6a6b4

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor
22
.DS_Store
33
.idea
4+
.vscode

cmd/auth.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package cmd
2+
3+
import (
4+
"os"
5+
6+
"github.com/pinpt/go-common/v10/auth"
7+
"github.com/spf13/cobra"
8+
)
9+
10+
var decryptStringCmd = &cobra.Command{
11+
Use: "decrypt <string> <password>",
12+
Short: "decrypt a string",
13+
Args: cobra.ExactArgs(2),
14+
Run: func(cmd *cobra.Command, args []string) {
15+
slug := args[0]
16+
password := args[1]
17+
result, err := auth.DecryptString(slug, password)
18+
if err != nil {
19+
os.Stderr.WriteString(err.Error())
20+
os.Exit(1)
21+
}
22+
os.Stdout.WriteString(result)
23+
},
24+
}
25+
26+
var encryptStringCmd = &cobra.Command{
27+
Use: "encrypt <string> <password>",
28+
Short: "encrypt a string",
29+
Args: cobra.ExactArgs(2),
30+
Run: func(cmd *cobra.Command, args []string) {
31+
slug := args[0]
32+
password := args[1]
33+
result, err := auth.EncryptString(slug, password)
34+
if err != nil {
35+
os.Stderr.WriteString(err.Error())
36+
os.Exit(1)
37+
}
38+
os.Stdout.WriteString(result)
39+
},
40+
}
41+
42+
func init() {
43+
rootCmd.AddCommand(decryptStringCmd)
44+
rootCmd.AddCommand(encryptStringCmd)
45+
}

0 commit comments

Comments
 (0)