obscure: make `rclone osbcure -` ignore newline at end of line

See: https://forum.rclone.org/t/authentification-issues-with-webdav-server/21891
This commit is contained in:
Nick Craig-Wood 2021-01-27 16:24:10 +00:00
parent fe15a2eeeb
commit 8f6f4b053c
1 changed files with 12 additions and 5 deletions

View File

@ -1,9 +1,9 @@
package obscure package obscure
import ( import (
"bufio"
"fmt" "fmt"
"io/ioutil"
"os" "os"
"github.com/rclone/rclone/cmd" "github.com/rclone/rclone/cmd"
@ -30,7 +30,8 @@ the config file. However it is very hard to shoulder surf a 64
character hex token. character hex token.
This command can also accept a password through STDIN instead of an This command can also accept a password through STDIN instead of an
argument by passing a hyphen as an argument. Example: argument by passing a hyphen as an argument. This will use the first
line of STDIN as the password not including the trailing newline.
echo "secretpassword" | rclone obscure - echo "secretpassword" | rclone obscure -
@ -40,13 +41,18 @@ obfuscating the hyphen itself.
If you want to encrypt the config file then please use config file If you want to encrypt the config file then please use config file
encryption - see [rclone config](/commands/rclone_config/) for more encryption - see [rclone config](/commands/rclone_config/) for more
info.`, info.`,
Run: func(command *cobra.Command, args []string) { RunE: func(command *cobra.Command, args []string) error {
cmd.CheckArgs(1, 1, command, args) cmd.CheckArgs(1, 1, command, args)
var password string var password string
fi, _ := os.Stdin.Stat() fi, _ := os.Stdin.Stat()
if args[0] == "-" && (fi.Mode()&os.ModeCharDevice) == 0 { if args[0] == "-" && (fi.Mode()&os.ModeCharDevice) == 0 {
bytes, _ := ioutil.ReadAll(os.Stdin) scanner := bufio.NewScanner(os.Stdin)
password = string(bytes) if scanner.Scan() {
password = scanner.Text()
}
if err := scanner.Err(); err != nil {
return err
}
} else { } else {
password = args[0] password = args[0]
} }
@ -55,5 +61,6 @@ info.`,
fmt.Println(obscured) fmt.Println(obscured)
return nil return nil
}) })
return nil
}, },
} }