github.com/naphatkrit/deis@v1.12.3/client/parser/certs.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  // Certs routes certs commands to their specific function.
     9  func Certs(argv []string) error {
    10  	usage := `
    11  Valid commands for certs:
    12  
    13  certs:list            list SSL certificates for an app
    14  certs:add             add an SSL certificate to an app
    15  certs:remove          remove an SSL certificate from an app
    16  
    17  Use 'deis help [command]' to learn more.
    18  `
    19  
    20  	switch argv[0] {
    21  	case "certs:list":
    22  		return certsList(argv)
    23  	case "certs:add":
    24  		return certAdd(argv)
    25  	case "certs:remove":
    26  		return certRemove(argv)
    27  	default:
    28  		if printHelp(argv, usage) {
    29  			return nil
    30  		}
    31  
    32  		if argv[0] == "certs" {
    33  			argv[0] = "certs:list"
    34  			return certsList(argv)
    35  		}
    36  
    37  		PrintUsage()
    38  		return nil
    39  	}
    40  }
    41  
    42  func certsList(argv []string) error {
    43  	usage := `
    44  Show certificate information for an SSL application.
    45  
    46  Usage: deis certs:list [options]
    47  
    48  Options:
    49    -l --limit=<num>
    50      the maximum number of results to display, defaults to config setting
    51  `
    52  
    53  	args, err := docopt.Parse(usage, argv, true, "", false, true)
    54  
    55  	if err != nil {
    56  		return err
    57  	}
    58  
    59  	results, err := responseLimit(safeGetValue(args, "--limit"))
    60  
    61  	if err != nil {
    62  		return err
    63  	}
    64  
    65  	return cmd.CertsList(results)
    66  }
    67  
    68  func certAdd(argv []string) error {
    69  	usage := `
    70  Binds a certificate/key pair to an application.
    71  
    72  Usage: deis certs:add <cert> <key> [options]
    73  
    74  Arguments:
    75    <cert>
    76      The public key of the SSL certificate.
    77    <key>
    78      The private key of the SSL certificate.
    79  
    80  Options:
    81    --common-name=<cname>
    82      The common name of the certificate. If none is provided, the controller will
    83      interpret the common name from the certificate.
    84    --subject-alt-names=<sans>
    85      The subject alternate names (SAN) of the certificate, separated by commas. This will
    86      create multiple Certificate objects in the controller, one for each SAN.
    87  `
    88  
    89  	args, err := docopt.Parse(usage, argv, true, "", false, true)
    90  
    91  	if err != nil {
    92  		return err
    93  	}
    94  
    95  	cert := args["<cert>"].(string)
    96  	key := args["<key>"].(string)
    97  	commonName := safeGetValue(args, "--common-name")
    98  	sans := safeGetValue(args, "--subject-alt-names")
    99  
   100  	return cmd.CertAdd(cert, key, commonName, sans)
   101  }
   102  
   103  func certRemove(argv []string) error {
   104  	usage := `
   105  removes a certificate/key pair from the application.
   106  
   107  Usage: deis certs:remove <cn> [options]
   108  
   109  Arguments:
   110    <cn>
   111      the common name of the cert to remove from the app.
   112  `
   113  
   114  	args, err := docopt.Parse(usage, argv, true, "", false, true)
   115  
   116  	if err != nil {
   117  		return err
   118  	}
   119  
   120  	return cmd.CertRemove(safeGetValue(args, "<cn>"))
   121  }