forked from jriou/coller
feat: Rename password by encryption key
Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
parent
634326190c
commit
8e1dd686d3
16 changed files with 118 additions and 117 deletions
|
@ -11,6 +11,6 @@ copier -help
|
|||
# Examples
|
||||
|
||||
```
|
||||
copier -password PASSWORD URL
|
||||
copier -ask-password URL
|
||||
copier -encryption-key ENCRYPTION_KEY URL
|
||||
copier -ask-encryption-key URL
|
||||
```
|
|
@ -9,8 +9,9 @@ import (
|
|||
"os"
|
||||
"syscall"
|
||||
|
||||
"git.riou.xyz/jriou/coller/internal"
|
||||
"golang.org/x/term"
|
||||
|
||||
"git.riou.xyz/jriou/coller/internal"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -28,8 +29,8 @@ func handleMain() int {
|
|||
quiet := flag.Bool("quiet", false, "Log errors only")
|
||||
verbose := flag.Bool("verbose", false, "Print more logs")
|
||||
debug := flag.Bool("debug", false, "Print even more logs")
|
||||
password := flag.String("password", os.Getenv("COLLER_PASSWORD"), "Password to decrypt the note")
|
||||
askPassword := flag.Bool("ask-password", false, "Read password from input")
|
||||
encryptionKey := flag.String("encryption-key", os.Getenv("COLLER_ENCRYPTION_KEY"), "Key to decrypt the note")
|
||||
askEncryptionKey := flag.Bool("ask-encryption-key", false, "Read encryption key from input")
|
||||
fileName := flag.String("file", "", "Write content of the note to a file")
|
||||
bearer := flag.String("bearer", os.Getenv("COLLER_BEARER"), "Bearer token")
|
||||
askBearer := flag.Bool("ask-bearer", false, "Read bearer token from input")
|
||||
|
@ -60,13 +61,13 @@ func handleMain() int {
|
|||
}
|
||||
logger := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{Level: level}))
|
||||
|
||||
if *askPassword {
|
||||
fmt.Print("Password: ")
|
||||
if *askEncryptionKey {
|
||||
fmt.Print("Encryption key: ")
|
||||
p, err := term.ReadPassword(int(syscall.Stdin))
|
||||
if err != nil {
|
||||
return internal.ReturnError(logger, "could not read password", err)
|
||||
return internal.ReturnError(logger, "could not read encryption key", err)
|
||||
}
|
||||
*password = string(p)
|
||||
*encryptionKey = string(p)
|
||||
fmt.Print("\n")
|
||||
}
|
||||
|
||||
|
@ -102,11 +103,11 @@ func handleMain() int {
|
|||
}
|
||||
|
||||
var content []byte
|
||||
if *password != "" {
|
||||
if *encryptionKey != "" {
|
||||
logger.Debug("decrypting note")
|
||||
content, err = internal.Decrypt(body, *password)
|
||||
content, err = internal.Decrypt(body, *encryptionKey)
|
||||
if err != nil {
|
||||
return internal.ReturnError(logger, "could not decrypt paste", err)
|
||||
return internal.ReturnError(logger, "could not decrypt note", err)
|
||||
}
|
||||
} else {
|
||||
content = body
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue