forked from TrueCloudLab/lego
Extract mutation of client into functions
This commit is contained in:
parent
595f684e27
commit
053dc4cfb1
1 changed files with 25 additions and 28 deletions
|
@ -17,9 +17,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// DefaultSolvers is the set of solvers to use if none is given to NewClient.
|
|
||||||
DefaultSolvers = []string{"http-01", "tls-sni-01"}
|
|
||||||
|
|
||||||
// Logger is an optional custom logger.
|
// Logger is an optional custom logger.
|
||||||
Logger *log.Logger
|
Logger *log.Logger
|
||||||
)
|
)
|
||||||
|
@ -66,7 +63,7 @@ type Client struct {
|
||||||
// it is a set of solver names to enable. The "http-01" and "tls-sni-01" solvers
|
// it is a set of solver names to enable. The "http-01" and "tls-sni-01" solvers
|
||||||
// take an optional TCP port to listen on after a colon, e.g. "http-01:80". If
|
// take an optional TCP port to listen on after a colon, e.g. "http-01:80". If
|
||||||
// the port is not specified, the port required by the spec will be used.
|
// the port is not specified, the port required by the spec will be used.
|
||||||
func NewClient(caDirURL string, user User, keyBits int, optSolvers []string) (*Client, error) {
|
func NewClient(caDirURL string, user User, keyBits int) (*Client, error) {
|
||||||
privKey := user.GetPrivateKey()
|
privKey := user.GetPrivateKey()
|
||||||
if privKey == nil {
|
if privKey == nil {
|
||||||
return nil, errors.New("private key was nil")
|
return nil, errors.New("private key was nil")
|
||||||
|
@ -100,34 +97,34 @@ func NewClient(caDirURL string, user User, keyBits int, optSolvers []string) (*C
|
||||||
// Add all available solvers with the right index as per ACME
|
// Add all available solvers with the right index as per ACME
|
||||||
// spec to this map. Otherwise they won`t be found.
|
// spec to this map. Otherwise they won`t be found.
|
||||||
solvers := make(map[string]solver)
|
solvers := make(map[string]solver)
|
||||||
if optSolvers == nil {
|
solvers["http-01"] = &httpChallenge{jws: jws}
|
||||||
optSolvers = DefaultSolvers
|
solvers["tls-sni-01"] = &tlsSNIChallenge{jws: jws}
|
||||||
}
|
|
||||||
for _, s := range optSolvers {
|
|
||||||
ss := strings.SplitN(s, ":", 2)
|
|
||||||
switch ss[0] {
|
|
||||||
case "http-01":
|
|
||||||
optPort := ""
|
|
||||||
if len(ss) > 1 {
|
|
||||||
optPort = ss[1]
|
|
||||||
}
|
|
||||||
solvers["http-01"] = &httpChallenge{jws: jws, validate: validate, optPort: optPort}
|
|
||||||
|
|
||||||
case "tls-sni-01":
|
|
||||||
optPort := ""
|
|
||||||
if len(ss) > 1 {
|
|
||||||
optPort = ss[1]
|
|
||||||
}
|
|
||||||
solvers["tls-sni-01"] = &tlsSNIChallenge{jws: jws, validate: validate, optPort: optPort}
|
|
||||||
|
|
||||||
default:
|
|
||||||
return nil, fmt.Errorf("unknown solver: %s", s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return &Client{directory: dir, user: user, jws: jws, keyBits: keyBits, solvers: solvers}, nil
|
return &Client{directory: dir, user: user, jws: jws, keyBits: keyBits, solvers: solvers}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetHTTPPort specifies a custom port to be used for HTTP based challenges.
|
||||||
|
func (c *Client) SetHTTPPort(port int) {
|
||||||
|
/*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) {
|
||||||
|
/*if chlng, ok := c.solvers["tls-sni-01"]; ok {
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
// ExcludeChallenges explicitly removes challenges from the pool for solving.
|
||||||
|
func (c *Client) ExcludeChallenges(challenges []string) {
|
||||||
|
// Loop through all challenges and delete the requested one if found.
|
||||||
|
for _, challenge := range challenges {
|
||||||
|
if _, ok := c.solvers[challenge]; ok {
|
||||||
|
delete(c.solvers, challenge)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Register the current account to the ACME server.
|
// Register the current account to the ACME server.
|
||||||
func (c *Client) Register() (*RegistrationResource, error) {
|
func (c *Client) Register() (*RegistrationResource, error) {
|
||||||
if c == nil || c.user == nil {
|
if c == nil || c.user == nil {
|
||||||
|
|
Loading…
Reference in a new issue