comparison cmd/sievemgr/info.go @ 5:4dff4c3f0fbb

Introduce configuration file where account information is specified Introduce a configuration file where account information must be specified instead of passing it with each invocation on the command line. Each account has a name by which it can be selected and one may be specified as the default account. This is intended to improve usability for productive usage. Enforce strict permissions since passwords may be specified for non-interactive usage. Remove command-line flags for passing account information.
author Guido Berhoerster <guido+sievemgr@berhoerster.name>
date Tue, 03 Nov 2020 23:44:45 +0100
parents 6db34a5344b8
children d14d93d011d7
comparison
equal deleted inserted replaced
4:f925f15d8ce5 5:4dff4c3f0fbb
25 "fmt" 25 "fmt"
26 "net" 26 "net"
27 ) 27 )
28 28
29 func init() { 29 func init() {
30 cmdInfo.Flag.StringVar(&username, "u", "", "Set the username") 30 cmdInfo.Flag.StringVar(&acctName, "a", "", "Select the account")
31 cmdInfo.Flag.StringVar(&passwordFilename, "P", "",
32 "Set the name of the password file")
33 } 31 }
34 32
35 var cmdInfo = &command{ 33 var cmdInfo = &command{
36 UsageLine: "info [options] host[:port]", 34 UsageLine: "info [options]",
37 Run: runInfo, 35 Run: runInfo,
38 } 36 }
39 37
40 func runInfo(cmd *command, args []string) error { 38 func runInfo(cmd *command, args []string) error {
41 if len(args) != 1 { 39 if len(args) != 0 {
42 return usageError("invalid number of arguments") 40 return usageError("invalid number of arguments")
43 } 41 }
44 42
45 host, port, err := parseHostPort(args[0]) 43 acct, err := getAccount(&conf, acctName)
46 if err != nil { 44 if err != nil {
47 return err 45 return err
48 } 46 }
49 47
50 username, password, err := usernamePassword(host, port, username, 48 if err := lookupHostPort(acct); err != nil {
51 passwordFilename)
52 if err != nil {
53 return err 49 return err
54 } 50 }
55 51
56 c, err := dialPlainAuth(net.JoinHostPort(host, port), username, 52 if err := readPassword(acct); err != nil {
57 password) 53 return err
54 }
55
56 c, err := dialPlainAuth(acct)
58 if err != nil { 57 if err != nil {
59 return err 58 return err
60 } 59 }
61 defer c.Logout() 60 defer c.Logout()
62 61
63 fmt.Printf("%s (%s)\n", net.JoinHostPort(host, port), 62 fmt.Printf("%s (%s)\n", net.JoinHostPort(acct.Host, acct.Port),
64 c.Implementation()) 63 c.Implementation())
65 if c.SupportsRFC5804() { 64 if c.SupportsRFC5804() {
66 fmt.Println("RFC5804 supported") 65 fmt.Println("RFC5804 supported")
67 } 66 }
68 if c.SupportsTLS() { 67 if c.SupportsTLS() {