From 0e857b2fefa92bd7664c6b28ebf8c1101d44bb5b Mon Sep 17 00:00:00 2001 From: xenolf Date: Sun, 27 Dec 2015 18:30:04 +0100 Subject: [PATCH] Adapt CLI to changes in lib - Change explicit include of challenges to explicit exclude - Add CLI switches for HTTP and TLS ports --- acme/client.go | 4 ++-- cli.go | 12 ++++++++++-- cli_handlers.go | 14 +++++++++++++- configuration.go | 4 ++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/acme/client.go b/acme/client.go index f6e56c7e..80105ae1 100644 --- a/acme/client.go +++ b/acme/client.go @@ -104,13 +104,13 @@ func NewClient(caDirURL string, user User, keyBits int) (*Client, error) { } // SetHTTPPort specifies a custom port to be used for HTTP based challenges. -func (c *Client) SetHTTPPort(port int) { +func (c *Client) SetHTTPPort(port string) { /*if chlng, ok := c.solvers["http-01"]; ok { }*/ } // SetHTTPSPort specifies a custom port to be used for HTTPS based challenges. -func (c *Client) SetHTTPSPort(port int) { +func (c *Client) SetHTTPSPort(port string) { /*if chlng, ok := c.solvers["tls-sni-01"]; ok { }*/ } diff --git a/cli.go b/cli.go index 8b9fb485..da902ee9 100644 --- a/cli.go +++ b/cli.go @@ -82,8 +82,16 @@ func main() { Value: defaultPath, }, cli.StringSliceFlag{ - Name: "solvers, S", - Usage: "Add an explicit solver for challenges. Solvers: \"http-01[:port]\", \"tls-sni-01[:port]\".", + Name: "exclude, x", + Usage: "Explicitly disallow solvers by name from being used. Solvers: \"http-01\", \"tls-sni-01\".", + }, + cli.StringFlag{ + Name: "httpPort", + Usage: "Set the port to use for HTTP based challenges to listen on.", + }, + cli.StringFlag{ + Name: "tlsPort", + Usage: "Set the port to use for TLS based challenges to listen on.", }, } diff --git a/cli_handlers.go b/cli_handlers.go index 80229545..b97336ad 100644 --- a/cli_handlers.go +++ b/cli_handlers.go @@ -34,11 +34,23 @@ func setup(c *cli.Context) (*Configuration, *Account, *acme.Client) { //TODO: move to account struct? Currently MUST pass email. acc := NewAccount(c.GlobalString("email"), conf) - client, err := acme.NewClient(c.GlobalString("server"), acc, conf.RsaBits(), conf.Solvers()) + client, err := acme.NewClient(c.GlobalString("server"), acc, conf.RsaBits()) if err != nil { logger().Fatalf("Could not create client: %s", err.Error()) } + if len(c.GlobalStringSlice("exclude")) > 0 { + client.ExcludeChallenges(conf.ExcludedSolvers()) + } + + if c.GlobalIsSet("httpPort") { + client.SetHTTPPort(c.GlobalString("httpPort")) + } + + if c.GlobalIsSet("tlsPort") { + client.SetHTTPPort(c.GlobalString("tlsPort")) + } + return conf, acc, client } diff --git a/configuration.go b/configuration.go index 3f39f281..a47f1011 100644 --- a/configuration.go +++ b/configuration.go @@ -24,8 +24,8 @@ func (c *Configuration) RsaBits() int { return c.context.GlobalInt("rsa-key-size") } -func (c *Configuration) Solvers() []string { - return c.context.GlobalStringSlice("solvers") +func (c *Configuration) ExcludedSolvers() []string { + return c.context.GlobalStringSlice("exclude") } // ServerPath returns the OS dependent path to the data for a specific CA