Skip to content

Commit

Permalink
Merge pull request #124 from pinpt/auth-command
Browse files Browse the repository at this point in the history
Add encrypt and decrypt commands 🔐
  • Loading branch information
Robin Diddams authored Nov 6, 2020
2 parents 8dca493 + e0fcf20 commit 0a6a6b4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
.DS_Store
.idea
.vscode
45 changes: 45 additions & 0 deletions cmd/auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cmd

import (
"os"

"github.com/pinpt/go-common/v10/auth"
"github.com/spf13/cobra"
)

var decryptStringCmd = &cobra.Command{
Use: "decrypt <string> <password>",
Short: "decrypt a string",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
slug := args[0]
password := args[1]
result, err := auth.DecryptString(slug, password)
if err != nil {
os.Stderr.WriteString(err.Error())
os.Exit(1)
}
os.Stdout.WriteString(result)
},
}

var encryptStringCmd = &cobra.Command{
Use: "encrypt <string> <password>",
Short: "encrypt a string",
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
slug := args[0]
password := args[1]
result, err := auth.EncryptString(slug, password)
if err != nil {
os.Stderr.WriteString(err.Error())
os.Exit(1)
}
os.Stdout.WriteString(result)
},
}

func init() {
rootCmd.AddCommand(decryptStringCmd)
rootCmd.AddCommand(encryptStringCmd)
}

0 comments on commit 0a6a6b4

Please sign in to comment.