|
| 1 | +package parser |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/deis/workflow-cli/cmd" |
| 5 | + docopt "github.com/docopt/docopt-go" |
| 6 | +) |
| 7 | + |
| 8 | +// Whitelist displays all relevant commands for `deis whitelist`. |
| 9 | +func Whitelist(argv []string, cmdr cmd.Commander) error { |
| 10 | + usage := ` |
| 11 | +Valid commands for whitelist: |
| 12 | +
|
| 13 | +whitelist:add adds addresses to the application's whitelist |
| 14 | +whitelist:list list addresses in the application's whitelist |
| 15 | +whitelist:remove remove addresses from the application's whitelist |
| 16 | +
|
| 17 | +Use 'deis help [command]' to learn more. |
| 18 | +` |
| 19 | + |
| 20 | + switch argv[0] { |
| 21 | + case "whitelist:add": |
| 22 | + return whitelistAdd(argv, cmdr) |
| 23 | + case "whitelist:list": |
| 24 | + return whitelistList(argv, cmdr) |
| 25 | + case "whitelist:remove": |
| 26 | + return whitelistRemove(argv, cmdr) |
| 27 | + default: |
| 28 | + if printHelp(argv, usage) { |
| 29 | + return nil |
| 30 | + } |
| 31 | + |
| 32 | + if argv[0] == "whitelist" { |
| 33 | + argv[0] = "whitelist:list" |
| 34 | + return whitelistList(argv, cmdr) |
| 35 | + } |
| 36 | + |
| 37 | + PrintUsage(cmdr) |
| 38 | + return nil |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +func whitelistAdd(argv []string, cmdr cmd.Commander) error { |
| 43 | + usage := ` |
| 44 | +Adds addresses to an application whitelist. |
| 45 | +
|
| 46 | +Usage: deis whitelist:add <addresses> [options] |
| 47 | +
|
| 48 | +Arguments: |
| 49 | + <addresses> |
| 50 | + comma-delimited list of addresses(using IP or CIDR notation) to be whitelisted for the application, such as '1.2.3.4' or '1.2.3.4,0.0.0.0/0'. |
| 51 | +
|
| 52 | +Options: |
| 53 | + -a --app=<app> |
| 54 | + the uniquely identifiable name for the application. |
| 55 | +` |
| 56 | + |
| 57 | + args, err := docopt.Parse(usage, argv, true, "", false, true) |
| 58 | + |
| 59 | + if err != nil { |
| 60 | + return err |
| 61 | + } |
| 62 | + |
| 63 | + app := safeGetValue(args, "--app") |
| 64 | + addresses := safeGetValue(args, "<addresses>") |
| 65 | + |
| 66 | + return cmdr.WhitelistAdd(app, addresses) |
| 67 | +} |
| 68 | + |
| 69 | +func whitelistList(argv []string, cmdr cmd.Commander) error { |
| 70 | + usage := ` |
| 71 | +Lists whitelisted addresses for an application. |
| 72 | +
|
| 73 | +Usage: deis whitelist:list [options] |
| 74 | +
|
| 75 | +Options: |
| 76 | + -a --app=<app> |
| 77 | + the uniquely identifiable name for the application. |
| 78 | +` |
| 79 | + |
| 80 | + args, err := docopt.Parse(usage, argv, true, "", false, true) |
| 81 | + |
| 82 | + if err != nil { |
| 83 | + return err |
| 84 | + } |
| 85 | + |
| 86 | + if err != nil { |
| 87 | + return err |
| 88 | + } |
| 89 | + app := safeGetValue(args, "--app") |
| 90 | + |
| 91 | + return cmdr.WhitelistList(app) |
| 92 | +} |
| 93 | + |
| 94 | +func whitelistRemove(argv []string, cmdr cmd.Commander) error { |
| 95 | + usage := ` |
| 96 | +Removes addresses from an application whitelist. |
| 97 | +
|
| 98 | +Usage: deis whitelist:remove <addresses> [options] |
| 99 | +
|
| 100 | +Arguments: |
| 101 | + <addresses> |
| 102 | + comma-delimited list of addresses(using IP or CIDR notation) to be whitelisted for the application, such as '1.2.3.4' or "1.2.3.4,0.0.0.0/0". |
| 103 | +
|
| 104 | +Options: |
| 105 | + -a --app=<app> |
| 106 | + the uniquely identifiable name for the application. |
| 107 | +` |
| 108 | + |
| 109 | + args, err := docopt.Parse(usage, argv, true, "", false, true) |
| 110 | + |
| 111 | + if err != nil { |
| 112 | + return err |
| 113 | + } |
| 114 | + |
| 115 | + app := safeGetValue(args, "--app") |
| 116 | + addresses := safeGetValue(args, "<addresses>") |
| 117 | + |
| 118 | + return cmdr.WhitelistRemove(app, addresses) |
| 119 | +} |
0 commit comments