2015-06-08 02:36:07 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-01-27 03:01:39 +02:00
|
|
|
"fmt"
|
2015-06-08 02:36:07 +02:00
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
|
2016-07-13 21:03:47 +02:00
|
|
|
"github.com/urfave/cli"
|
2016-01-15 06:06:25 +02:00
|
|
|
"github.com/xenolf/lego/acme"
|
2015-06-08 02:36:07 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Configuration type from CLI and config files.
|
|
|
|
type Configuration struct {
|
|
|
|
context *cli.Context
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewConfiguration creates a new configuration from CLI data.
|
|
|
|
func NewConfiguration(c *cli.Context) *Configuration {
|
|
|
|
return &Configuration{context: c}
|
|
|
|
}
|
|
|
|
|
2016-01-27 03:01:39 +02:00
|
|
|
// KeyType the type from which private keys should be generated
|
|
|
|
func (c *Configuration) KeyType() (acme.KeyType, error) {
|
|
|
|
switch strings.ToUpper(c.context.GlobalString("key-type")) {
|
|
|
|
case "RSA2048":
|
|
|
|
return acme.RSA2048, nil
|
|
|
|
case "RSA4096":
|
|
|
|
return acme.RSA4096, nil
|
|
|
|
case "RSA8192":
|
|
|
|
return acme.RSA8192, nil
|
|
|
|
case "EC256":
|
|
|
|
return acme.EC256, nil
|
|
|
|
case "EC384":
|
|
|
|
return acme.EC384, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return "", fmt.Errorf("Unsupported KeyType: %s", c.context.GlobalString("key-type"))
|
2015-06-08 02:36:07 +02:00
|
|
|
}
|
|
|
|
|
2016-02-14 08:24:19 +02:00
|
|
|
// ExcludedSolvers is a list of solvers that are to be excluded.
|
2016-01-15 06:06:25 +02:00
|
|
|
func (c *Configuration) ExcludedSolvers() (cc []acme.Challenge) {
|
|
|
|
for _, s := range c.context.GlobalStringSlice("exclude") {
|
|
|
|
cc = append(cc, acme.Challenge(s))
|
|
|
|
}
|
|
|
|
return
|
2015-06-13 00:16:49 +02:00
|
|
|
}
|
|
|
|
|
2015-06-08 02:36:07 +02:00
|
|
|
// ServerPath returns the OS dependent path to the data for a specific CA
|
|
|
|
func (c *Configuration) ServerPath() string {
|
|
|
|
srv, _ := url.Parse(c.context.GlobalString("server"))
|
2015-09-26 20:00:19 +02:00
|
|
|
srvStr := strings.Replace(srv.Host, ":", "_", -1)
|
2015-06-08 02:36:07 +02:00
|
|
|
return strings.Replace(srvStr, "/", string(os.PathSeparator), -1)
|
|
|
|
}
|
|
|
|
|
2016-02-14 08:24:19 +02:00
|
|
|
// CertPath gets the path for certificates.
|
2015-06-13 03:56:34 +02:00
|
|
|
func (c *Configuration) CertPath() string {
|
|
|
|
return path.Join(c.context.GlobalString("path"), "certificates")
|
|
|
|
}
|
|
|
|
|
2015-06-08 02:36:07 +02:00
|
|
|
// AccountsPath returns the OS dependent path to the
|
|
|
|
// local accounts for a specific CA
|
|
|
|
func (c *Configuration) AccountsPath() string {
|
2015-06-12 23:34:49 +02:00
|
|
|
return path.Join(c.context.GlobalString("path"), "accounts", c.ServerPath())
|
2015-06-08 02:36:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// AccountPath returns the OS dependent path to a particular account
|
|
|
|
func (c *Configuration) AccountPath(acc string) string {
|
|
|
|
return path.Join(c.AccountsPath(), acc)
|
|
|
|
}
|
|
|
|
|
2016-02-14 08:24:19 +02:00
|
|
|
// AccountKeysPath returns the OS dependent path to the keys of a particular account
|
2015-06-08 02:36:07 +02:00
|
|
|
func (c *Configuration) AccountKeysPath(acc string) string {
|
|
|
|
return path.Join(c.AccountPath(acc), "keys")
|
|
|
|
}
|