github.com/naphatkrit/deis@v1.12.3/client/parser/perms.go (about) 1 package parser 2 3 import ( 4 "github.com/deis/deis/client/cmd" 5 docopt "github.com/docopt/docopt-go" 6 ) 7 8 // Perms routes perms commands to their specific function. 9 func Perms(argv []string) error { 10 usage := ` 11 Valid commands for perms: 12 13 perms:list list permissions granted on an app 14 perms:create create a new permission for a user 15 perms:delete delete a permission for a user 16 17 Use 'deis help perms:[command]' to learn more. 18 ` 19 switch argv[0] { 20 case "perms:list": 21 return permsList(argv) 22 case "perms:create": 23 return permCreate(argv) 24 case "perms:delete": 25 return permDelete(argv) 26 default: 27 if printHelp(argv, usage) { 28 return nil 29 } 30 31 if argv[0] == "perms" { 32 argv[0] = "perms:list" 33 return permsList(argv) 34 } 35 36 PrintUsage() 37 return nil 38 } 39 } 40 41 func permsList(argv []string) error { 42 usage := ` 43 Lists all users with permission to use an app, or lists all users with system 44 administrator privileges. 45 46 Usage: deis perms:list [-a --app=<app>|--admin|--admin --limit=<num>] 47 48 Options: 49 -a --app=<app> 50 lists all users with permission to <app>. <app> is the uniquely identifiable name 51 for the application. 52 --admin 53 lists all users with system administrator privileges. 54 -l --limit=<num> 55 the maximum number of results to display, defaults to config setting 56 ` 57 58 args, err := docopt.Parse(usage, argv, true, "", false, true) 59 60 if err != nil { 61 return err 62 } 63 64 admin := args["--admin"].(bool) 65 66 results, err := responseLimit(safeGetValue(args, "--limit")) 67 68 if err != nil { 69 return err 70 } 71 72 return cmd.PermsList(safeGetValue(args, "--app"), admin, results) 73 } 74 75 func permCreate(argv []string) error { 76 usage := ` 77 Gives another user permission to use an app, or gives another user 78 system administrator privileges. 79 80 Usage: deis perms:create <username> [-a --app=<app>|--admin] 81 82 Arguments: 83 <username> 84 the name of the new user. 85 86 Options: 87 -a --app=<app> 88 grants <username> permission to use <app>. <app> is the uniquely identifiable name 89 for the application. 90 --admin 91 grants <username> system administrator privileges. 92 ` 93 94 args, err := docopt.Parse(usage, argv, true, "", false, true) 95 96 if err != nil { 97 return err 98 } 99 100 app := safeGetValue(args, "--app") 101 username := args["<username>"].(string) 102 admin := args["--admin"].(bool) 103 104 return cmd.PermCreate(app, username, admin) 105 } 106 107 func permDelete(argv []string) error { 108 usage := ` 109 Revokes another user's permission to use an app, or revokes another user's system 110 administrator privileges. 111 112 Usage: deis perms:delete <username> [-a --app=<app>|--admin] 113 114 Arguments: 115 <username> 116 the name of the user. 117 118 Options: 119 -a --app=<app> 120 revokes <username> permission to use <app>. <app> is the uniquely identifiable name 121 for the application. 122 --admin 123 revokes <username> system administrator privileges. 124 ` 125 126 args, err := docopt.Parse(usage, argv, true, "", false, true) 127 128 if err != nil { 129 return err 130 } 131 132 app := safeGetValue(args, "--app") 133 username := args["<username>"].(string) 134 admin := args["--admin"].(bool) 135 136 return cmd.PermDelete(app, username, admin) 137 }