comparison cmd/sievemgr/delete.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
19 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 19 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 21
22 package main 22 package main
23 23
24 import (
25 "net"
26 )
27
28 func init() { 24 func init() {
29 cmdDelete.Flag.StringVar(&username, "u", "", "Set the username") 25 cmdDelete.Flag.StringVar(&acctName, "a", "", "Select the account")
30 cmdDelete.Flag.StringVar(&passwordFilename, "P", "",
31 "Set the name of the password file")
32 } 26 }
33 27
34 var cmdDelete = &command{ 28 var cmdDelete = &command{
35 UsageLine: "delete [options] host[:port] name", 29 UsageLine: "delete [options] name",
36 Run: runDelete, 30 Run: runDelete,
37 } 31 }
38 32
39 func runDelete(cmd *command, args []string) error { 33 func runDelete(cmd *command, args []string) error {
40 if len(args) != 2 { 34 if len(args) != 1 {
41 return usageError("invalid number of arguments") 35 return usageError("invalid number of arguments")
42 } 36 }
43 37
44 host, port, err := parseHostPort(args[0]) 38 scriptName := args[0]
39
40 acct, err := getAccount(&conf, acctName)
45 if err != nil { 41 if err != nil {
46 return err 42 return err
47 } 43 }
48 44
49 scriptName := args[1] 45 if err := lookupHostPort(acct); err != nil {
50
51 username, password, err := usernamePassword(host, port, username,
52 passwordFilename)
53 if err != nil {
54 return err 46 return err
55 } 47 }
56 48
57 c, err := dialPlainAuth(net.JoinHostPort(host, port), username, 49 if err := readPassword(acct); err != nil {
58 password) 50 return err
51 }
52
53 c, err := dialPlainAuth(acct)
59 if err != nil { 54 if err != nil {
60 return err 55 return err
61 } 56 }
62 defer c.Logout() 57 defer c.Logout()
63 58