2015-06-08 00:36:07 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
"path"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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}
|
|
|
|
}
|
|
|
|
|
|
|
|
// RsaBits returns the current set RSA bit length for private keys
|
|
|
|
func (c *Configuration) RsaBits() int {
|
|
|
|
return c.context.GlobalInt("rsa-key-size")
|
|
|
|
}
|
|
|
|
|
2015-12-27 17:30:04 +00:00
|
|
|
func (c *Configuration) ExcludedSolvers() []string {
|
|
|
|
return c.context.GlobalStringSlice("exclude")
|
2015-06-12 22:16:49 +00:00
|
|
|
}
|
|
|
|
|
2015-06-08 00:36:07 +00: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 18:00:19 +00:00
|
|
|
srvStr := strings.Replace(srv.Host, ":", "_", -1)
|
2015-06-08 00:36:07 +00:00
|
|
|
return strings.Replace(srvStr, "/", string(os.PathSeparator), -1)
|
|
|
|
}
|
|
|
|
|
2015-06-13 01:56:34 +00:00
|
|
|
func (c *Configuration) CertPath() string {
|
|
|
|
return path.Join(c.context.GlobalString("path"), "certificates")
|
|
|
|
}
|
|
|
|
|
2015-06-08 00:36:07 +00:00
|
|
|
// AccountsPath returns the OS dependent path to the
|
|
|
|
// local accounts for a specific CA
|
|
|
|
func (c *Configuration) AccountsPath() string {
|
2015-06-12 21:34:49 +00:00
|
|
|
return path.Join(c.context.GlobalString("path"), "accounts", c.ServerPath())
|
2015-06-08 00:36:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// AccountPath returns the OS dependent path to a particular account
|
|
|
|
func (c *Configuration) AccountPath(acc string) string {
|
|
|
|
return path.Join(c.AccountsPath(), acc)
|
|
|
|
}
|
|
|
|
|
|
|
|
// AccountPath returns the OS dependent path to the keys of a particular account
|
|
|
|
func (c *Configuration) AccountKeysPath(acc string) string {
|
|
|
|
return path.Join(c.AccountPath(acc), "keys")
|
|
|
|
}
|