github.com/engineyard/workflow-cli@v2.21.6+incompatible/parser/whitelist.go (about)

     1  package parser
     2  
     3  import (
     4  	"github.com/teamhephy/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  	app := safeGetValue(args, "--app")
    87  
    88  	return cmdr.WhitelistList(app)
    89  }
    90  
    91  func whitelistRemove(argv []string, cmdr cmd.Commander) error {
    92  	usage := `
    93  Removes addresses from an application whitelist.
    94  
    95  Usage: deis whitelist:remove <addresses> [options]
    96  
    97  Arguments:
    98    <addresses>
    99      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".
   100  
   101  Options:
   102    -a --app=<app>
   103      the uniquely identifiable name for the application.
   104  `
   105  
   106  	args, err := docopt.Parse(usage, argv, true, "", false, true)
   107  
   108  	if err != nil {
   109  		return err
   110  	}
   111  
   112  	app := safeGetValue(args, "--app")
   113  	addresses := safeGetValue(args, "<addresses>")
   114  
   115  	return cmdr.WhitelistRemove(app, addresses)
   116  }