comparison cmd/sievemgr/list.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 0cd5a454dfb4
children fc5e6970a0d5
comparison
equal deleted inserted replaced
4:f925f15d8ce5 5:4dff4c3f0fbb
21 21
22 package main 22 package main
23 23
24 import ( 24 import (
25 "fmt" 25 "fmt"
26 "net"
27 ) 26 )
28 27
29 func init() { 28 func init() {
30 cmdList.Flag.StringVar(&username, "u", "", "Set the username") 29 cmdList.Flag.StringVar(&acctName, "a", "", "Select the account")
31 cmdList.Flag.StringVar(&passwordFilename, "P", "",
32 "Set the name of the password file")
33 } 30 }
34 31
35 var cmdList = &command{ 32 var cmdList = &command{
36 UsageLine: "list [options] host[:port]", 33 UsageLine: "list [options]",
37 Run: runList, 34 Run: runList,
38 } 35 }
39 36
40 func runList(cmd *command, args []string) error { 37 func runList(cmd *command, args []string) error {
41 if len(args) != 1 { 38 if len(args) != 0 {
42 return usageError("invalid number of arguments") 39 return usageError("invalid number of arguments")
43 } 40 }
44 41
45 host, port, err := parseHostPort(args[0]) 42 acct, err := getAccount(&conf, acctName)
46 if err != nil { 43 if err != nil {
47 return err 44 return err
48 } 45 }
49 46
50 username, password, err := usernamePassword(host, port, username, 47 if err := lookupHostPort(acct); err != nil {
51 passwordFilename)
52 if err != nil {
53 return err 48 return err
54 } 49 }
55 50
56 c, err := dialPlainAuth(net.JoinHostPort(host, port), username, 51 if err := readPassword(acct); err != nil {
57 password) 52 return err
53 }
54
55 c, err := dialPlainAuth(acct)
58 if err != nil { 56 if err != nil {
59 return err 57 return err
60 } 58 }
61 defer c.Logout() 59 defer c.Logout()
62 60