Skip to content

Commit

Permalink
Merge branch 'master' into pr/3
Browse files Browse the repository at this point in the history
  • Loading branch information
usarise committed Nov 22, 2024
2 parents 87b7e71 + 7342389 commit cb6188f
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 5 deletions.
19 changes: 15 additions & 4 deletions cmd/accounts_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const (
// │ └── root accounts directory
// └── "path" option
type AccountsStorage struct {
noEmail bool
userID string
rootPath string
rootUserPath string
Expand All @@ -68,8 +69,14 @@ type AccountsStorage struct {

// NewAccountsStorage Creates a new AccountsStorage.
func NewAccountsStorage(ctx *cli.Context) *AccountsStorage {
// TODO: move to account struct? Currently MUST pass email.
email := getEmail(ctx)
var userID string
noEmail := ctx.IsSet(flgNoEmail)
if noEmail {
userID = "default"
} else {
// TODO: move to account struct?
userID = getEmail(ctx)
}

serverURL, err := url.Parse(ctx.String(flgServer))
if err != nil {
Expand All @@ -79,10 +86,11 @@ func NewAccountsStorage(ctx *cli.Context) *AccountsStorage {
rootPath := filepath.Join(ctx.String(flgPath), baseAccountsRootFolderName)
serverPath := strings.NewReplacer(":", "_", "/", string(os.PathSeparator)).Replace(serverURL.Host)
accountsPath := filepath.Join(rootPath, serverPath)
rootUserPath := filepath.Join(accountsPath, email)
rootUserPath := filepath.Join(accountsPath, userID)

return &AccountsStorage{
userID: email,
noEmail: noEmail,
userID: userID,
rootPath: rootPath,
rootUserPath: rootUserPath,
keysPath: filepath.Join(rootUserPath, baseKeysFolderName),
Expand Down Expand Up @@ -110,6 +118,9 @@ func (s *AccountsStorage) GetRootUserPath() string {
}

func (s *AccountsStorage) GetUserID() string {
if s.noEmail {
return ""
}
return s.userID
}

Expand Down
7 changes: 7 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const (
flgServer = "server"
flgAcceptTOS = "accept-tos"
flgEmail = "email"
flgNoEmail = "no-email"
flgCSR = "csr"
flgEAB = "eab"
flgKID = "kid"
Expand Down Expand Up @@ -73,6 +74,12 @@ func CreateFlags(defaultPath string) []cli.Flag {
Aliases: []string{"m"},
Usage: "Email used for registration and recovery contact.",
},
&cli.BoolFlag{
Name: flgNoEmail,
Aliases: []string{"M"},
EnvVars: []string{"LEGO_NO_EMAIL"},
Usage: "Create an ACME request without including an email address.",
},
&cli.StringFlag{
Name: flgCSR,
Aliases: []string{"c"},
Expand Down
2 changes: 1 addition & 1 deletion cmd/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func getKeyType(ctx *cli.Context) certcrypto.KeyType {
func getEmail(ctx *cli.Context) string {
email := ctx.String(flgEmail)
if email == "" {
log.Fatalf("You have to pass an account (email address) to the program using --%s or -m", flgEmail)
log.Fatalf("You have to pass an account (email address) to the program using --%s or -m, or use --%s or -M to disable including an email in the ACME request.", flgEmail, flgNoEmail)
}
return email
}
Expand Down
1 change: 1 addition & 0 deletions docs/data/zz_cli_help.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ GLOBAL OPTIONS:
--server value, -s value CA hostname (and optionally :port). The server certificate must be trusted in order to avoid further modifications to the client. (default: "https://acme-v02.api.letsencrypt.org/directory") [$LEGO_SERVER]
--accept-tos, -a By setting this flag to true you indicate that you accept the current Let's Encrypt terms of service. (default: false)
--email value, -m value Email used for registration and recovery contact.
--no-email, -M Create an ACME request without including an email address. (default: false) [$LEGO_NO_EMAIL]
--csr value, -c value Certificate signing request filename, if an external CSR is to be used.
--eab Use External Account Binding for account registration. Requires --kid and --hmac. (default: false) [$LEGO_EAB]
--kid value Key identifier from External CA. Used for External Account Binding. [$LEGO_EAB_KID]
Expand Down
64 changes: 64 additions & 0 deletions providers/dns/westcn/westcn_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<<<<<<<< HEAD:providers/dns/westcn/westcn_test.go
package westcn
========
package technitium
>>>>>>>> master:providers/dns/technitium/technitium_test.go

import (
"testing"
Expand All @@ -9,7 +13,11 @@ import (

const envDomain = envNamespace + "DOMAIN"

<<<<<<<< HEAD:providers/dns/westcn/westcn_test.go
var envTest = tester.NewEnvTest(EnvUsername, EnvPassword).WithDomain(envDomain)
========
var envTest = tester.NewEnvTest(EnvServerBaseURL, EnvAPIToken).WithDomain(envDomain)
>>>>>>>> master:providers/dns/technitium/technitium_test.go

func TestNewDNSProvider(t *testing.T) {
testCases := []struct {
Expand All @@ -20,6 +28,7 @@ func TestNewDNSProvider(t *testing.T) {
{
desc: "success",
envVars: map[string]string{
<<<<<<<< HEAD:providers/dns/westcn/westcn_test.go
EnvUsername: "user",
EnvPassword: "secret",
},
Expand All @@ -39,11 +48,36 @@ func TestNewDNSProvider(t *testing.T) {
EnvPassword: "",
},
expected: "westcn: some credentials information are missing: WESTCN_PASSWORD",
========
EnvServerBaseURL: "https://localhost:5380",
EnvAPIToken: "secret",
},
},
{
desc: "missing server base URL",
envVars: map[string]string{
EnvServerBaseURL: "",
EnvAPIToken: "secret",
},
expected: "technitium: some credentials information are missing: TECHNITIUM_SERVER_BASE_URL",
},
{
desc: "missing token",
envVars: map[string]string{
EnvServerBaseURL: "https://localhost:5380",
EnvAPIToken: "",
},
expected: "technitium: some credentials information are missing: TECHNITIUM_API_TOKEN",
>>>>>>>> master:providers/dns/technitium/technitium_test.go
},
{
desc: "missing credentials",
envVars: map[string]string{},
<<<<<<<< HEAD:providers/dns/westcn/westcn_test.go
expected: "westcn: some credentials information are missing: WESTCN_USERNAME,WESTCN_PASSWORD",
========
expected: "technitium: some credentials information are missing: TECHNITIUM_SERVER_BASE_URL,TECHNITIUM_API_TOKEN",
>>>>>>>> master:providers/dns/technitium/technitium_test.go
},
}

Expand Down Expand Up @@ -71,6 +105,7 @@ func TestNewDNSProvider(t *testing.T) {
func TestNewDNSProviderConfig(t *testing.T) {
testCases := []struct {
desc string
<<<<<<<< HEAD:providers/dns/westcn/westcn_test.go
username string
password string
expected string
Expand All @@ -93,14 +128,43 @@ func TestNewDNSProviderConfig(t *testing.T) {
{
desc: "missing credentials",
expected: "westcn: credentials missing",
========
baseURL string
token string
expected string
}{
{
desc: "success",
baseURL: "https://localhost:5380",
token: "secret",
},
{
desc: "missing server base URL",
token: "secret",
expected: "technitium: missing server URL",
},
{
desc: "missing token",
baseURL: "https://localhost:5380",
expected: "technitium: missing credentials",
},
{
desc: "missing credentials",
expected: "technitium: missing credentials",
>>>>>>>> master:providers/dns/technitium/technitium_test.go
},
}

for _, test := range testCases {
t.Run(test.desc, func(t *testing.T) {
config := NewDefaultConfig()
<<<<<<<< HEAD:providers/dns/westcn/westcn_test.go
config.Username = test.username
config.Password = test.password
========
config.BaseURL = test.baseURL
config.APIToken = test.token
>>>>>>>> master:providers/dns/technitium/technitium_test.go

p, err := NewDNSProviderConfig(config)

Expand Down

0 comments on commit cb6188f

Please sign in to comment.