This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
84 lines (71 loc) · 1.82 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"bufio"
"fmt"
"log"
"os"
"github.com/HemmeligOrg/hemmelig-cli/core"
"github.com/urfave/cli/v2"
)
func input() string {
data := ""
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
data += scanner.Text() + "\n"
}
if err := scanner.Err(); err != nil {
fmt.Fprintln(os.Stderr, "reading standard input:", err)
}
return data
}
func createSecret(c *cli.Context) error {
if c.Int("ttl") < 0 || c.Int("ttl") > 604800 {
log.Fatal("Sorry, the TTL is expected to be from 0 - 605800 seconds")
}
data := ""
secret := c.Args().Get(0)
if secret == "" {
data += input()
} else {
data += secret
}
url, err := core.CreateSecret(data, c.String("password"), c.String("ttl"), c.String("url"))
if err != nil {
log.Fatal(err)
}
fmt.Println("The secret URL: " + url)
return nil
}
func main() {
app := &cli.App{
Name: "[he`m:(ə)li]",
HelpName: "hemmelig",
Usage: "Create a secret URL directly from your CLI.",
UsageText: "cat your_secret_file.txt | hemmelig --password=cantguessthislol \nOr just pass it as the first argument: hemmelig \"This is my secret\" --password=secret",
Copyright: fmt.Sprintf("(c) %d Hemmelig.app", core.Year()),
Flags: []cli.Flag{
&cli.StringFlag{
Name: "password",
Value: "",
Usage: "Set a password to protect the secret",
Aliases: []string{"p"},
},
&cli.StringFlag{
Name: "ttl",
Value: "14400",
Usage: "Secret expiration time in seconds. 0 - 605800 seconds.",
Aliases: []string{"t"},
},
&cli.StringFlag{
Name: "url",
Value: "https://hemmelig.app/",
Usage: "Override the Hemmelig app URL if you host it yourself",
Aliases: []string{"u"},
},
},
Action: createSecret,
}
if err := app.Run(os.Args); err != nil {
log.Fatalf("Error starting hemmelig cli: %v", err)
}
}