forked from TrueCloudLab/lego
feat: add a --user-agent flag to lego-cli (#1664)
This commit is contained in:
parent
525ceda150
commit
0e614c1d0b
3 changed files with 10 additions and 3 deletions
|
@ -6,7 +6,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -227,7 +226,7 @@ func tryRecoverRegistration(ctx *cli.Context, privateKey crypto.PrivateKey) (*re
|
||||||
// couldn't load account but got a key. Try to look the account up.
|
// couldn't load account but got a key. Try to look the account up.
|
||||||
config := lego.NewConfig(&Account{key: privateKey})
|
config := lego.NewConfig(&Account{key: privateKey})
|
||||||
config.CADirURL = ctx.String("server")
|
config.CADirURL = ctx.String("server")
|
||||||
config.UserAgent = fmt.Sprintf("lego-cli/%s", ctx.App.Version)
|
config.UserAgent = getUserAgent(ctx)
|
||||||
|
|
||||||
client, err := lego.NewClient(config)
|
client, err := lego.NewClient(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -132,5 +132,9 @@ func CreateFlags(defaultPath string) []cli.Flag {
|
||||||
Usage: "Set the certificate timeout value to a specific value in seconds. Only used when obtaining certificates.",
|
Usage: "Set the certificate timeout value to a specific value in seconds. Only used when obtaining certificates.",
|
||||||
Value: 30,
|
Value: 30,
|
||||||
},
|
},
|
||||||
|
&cli.StringFlag{
|
||||||
|
Name: "user-agent",
|
||||||
|
Usage: "Add to the user-agent sent to the CA to identify an application embedding lego-cli",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ func newClient(ctx *cli.Context, acc registration.User, keyType certcrypto.KeyTy
|
||||||
KeyType: keyType,
|
KeyType: keyType,
|
||||||
Timeout: time.Duration(ctx.Int("cert.timeout")) * time.Second,
|
Timeout: time.Duration(ctx.Int("cert.timeout")) * time.Second,
|
||||||
}
|
}
|
||||||
config.UserAgent = fmt.Sprintf("lego-cli/%s", ctx.App.Version)
|
config.UserAgent = getUserAgent(ctx)
|
||||||
|
|
||||||
if ctx.IsSet("http-timeout") {
|
if ctx.IsSet("http-timeout") {
|
||||||
config.HTTPClient.Timeout = time.Duration(ctx.Int("http-timeout")) * time.Second
|
config.HTTPClient.Timeout = time.Duration(ctx.Int("http-timeout")) * time.Second
|
||||||
|
@ -87,6 +87,10 @@ func getEmail(ctx *cli.Context) string {
|
||||||
return email
|
return email
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getUserAgent(ctx *cli.Context) string {
|
||||||
|
return strings.TrimSpace(fmt.Sprintf("%s lego-cli/%s", ctx.String("user-agent"), ctx.App.Version))
|
||||||
|
}
|
||||||
|
|
||||||
func createNonExistingFolder(path string) error {
|
func createNonExistingFolder(path string) error {
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||||
return os.MkdirAll(path, 0o700)
|
return os.MkdirAll(path, 0o700)
|
||||||
|
|
Loading…
Reference in a new issue