mirror of
https://github.com/go-acme/lego
synced 2026-03-14 14:35:48 +01:00
refactor: isolate client configuration creation
This commit is contained in:
parent
46417ee016
commit
01345cf589
1 changed files with 14 additions and 10 deletions
24
cmd/setup.go
24
cmd/setup.go
|
|
@ -47,6 +47,19 @@ func setupAccount(ctx context.Context, cmd *cli.Command, accountsStorage *storag
|
|||
}
|
||||
|
||||
func newClient(cmd *cli.Command, acc registration.User, keyType certcrypto.KeyType) *lego.Client {
|
||||
client, err := lego.NewClient(newClientConfig(cmd, acc, keyType))
|
||||
if err != nil {
|
||||
log.Fatal("Could not create client.", log.ErrorAttr(err))
|
||||
}
|
||||
|
||||
if client.GetExternalAccountRequired() && !cmd.IsSet(flgEAB) { // TODO(ldez): handle this flag.
|
||||
log.Fatal(fmt.Sprintf("Server requires External Account Binding. Use --%s with --%s and --%s.", flgEAB, flgKID, flgHMAC))
|
||||
}
|
||||
|
||||
return client
|
||||
}
|
||||
|
||||
func newClientConfig(cmd *cli.Command, acc registration.User, keyType certcrypto.KeyType) *lego.Config {
|
||||
config := lego.NewConfig(acc)
|
||||
config.CADirURL = cmd.String(flgServer)
|
||||
|
||||
|
|
@ -83,16 +96,7 @@ func newClient(cmd *cli.Command, acc registration.User, keyType certcrypto.KeyTy
|
|||
|
||||
config.HTTPClient = retryClient.StandardClient()
|
||||
|
||||
client, err := lego.NewClient(config)
|
||||
if err != nil {
|
||||
log.Fatal("Could not create client.", log.ErrorAttr(err))
|
||||
}
|
||||
|
||||
if client.GetExternalAccountRequired() && !cmd.IsSet(flgEAB) {
|
||||
log.Fatal(fmt.Sprintf("Server requires External Account Binding. Use --%s with --%s and --%s.", flgEAB, flgKID, flgHMAC))
|
||||
}
|
||||
|
||||
return client
|
||||
return config
|
||||
}
|
||||
|
||||
// getKeyType the type from which private keys should be generated.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue