aboutsummaryrefslogtreecommitdiff
path: root/cli.go
diff options
context:
space:
mode:
authorQuentin <quentin@dufour.io>2023-09-26 06:44:36 +0000
committerQuentin <quentin@dufour.io>2023-09-26 06:44:36 +0000
commit49d8e81fbea0d4703a33e87a807927169a8060ac (patch)
treed0b655454d5e13ed2238060fee27fc0d951d64c8 /cli.go
parent1e75c21b65021da0c3c5a8be9be12114a2327464 (diff)
parent706ff58a6f6608719feda15075d50f978df39c5b (diff)
downloadguichet-49d8e81fbea0d4703a33e87a807927169a8060ac.tar.gz
guichet-49d8e81fbea0d4703a33e87a807927169a8060ac.zip
Merge pull request 'An API for Guichet' (#23) from api into main
Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/guichet/pulls/23
Diffstat (limited to 'cli.go')
-rw-r--r--cli.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/cli.go b/cli.go
new file mode 100644
index 0000000..2d45a4c
--- /dev/null
+++ b/cli.go
@@ -0,0 +1,44 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "golang.org/x/term"
+ "os"
+ "syscall"
+)
+
+var fsCli = flag.NewFlagSet("cli", flag.ContinueOnError)
+var passFlag = fsCli.Bool("passwd", false, "Tool to generate a guichet-compatible password hash")
+
+func cliMain(args []string) {
+ if err := fsCli.Parse(args); err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+
+ if *passFlag {
+ cliPasswd()
+ } else {
+ fsCli.PrintDefaults()
+ os.Exit(1)
+ }
+}
+
+func cliPasswd() {
+ fmt.Print("Password: ")
+ bytepw, err := term.ReadPassword(int(syscall.Stdin))
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+ pass := string(bytepw)
+
+ hash, err := SSHAEncode(pass)
+ if err != nil {
+ fmt.Println(err)
+ os.Exit(1)
+ }
+
+ fmt.Println(hash)
+}