-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added user defined polling and propagation timeout option in ACME - Updated lego and added a few new DNS challenge providers - Updated code gen to support new parameters
- Loading branch information
Showing
10 changed files
with
1,547 additions
and
1,197 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,56 @@ | ||
package acme | ||
|
||
import ( | ||
"encoding/json" | ||
"strconv" | ||
|
||
"github.com/go-acme/lego/v4/challenge" | ||
"imuslab.com/zoraxy/mod/acme/acmedns" | ||
) | ||
|
||
func GetDnsChallengeProviderByName(dnsProvider string, dnsCredentials string) (challenge.Provider, error) { | ||
|
||
//Original Implementation | ||
/*credentials, err := extractDnsCredentials(dnsCredentials) | ||
// Preprocessor function to get DNS challenge provider by name | ||
func GetDnsChallengeProviderByName(dnsProvider string, dnsCredentials string, ppgTimeout int) (challenge.Provider, error) { | ||
//Unpack the dnsCredentials (json string) to map | ||
var dnsCredentialsMap map[string]interface{} | ||
err := json.Unmarshal([]byte(dnsCredentials), &dnsCredentialsMap) | ||
if err != nil { | ||
return nil, err | ||
} | ||
setCredentialsIntoEnvironmentVariables(credentials) | ||
provider, err := dns.NewDNSChallengeProviderByName(dnsProvider) | ||
*/ | ||
|
||
//New implementation using acmedns CICD pipeline generated datatype | ||
return acmedns.GetDNSProviderByJsonConfig(dnsProvider, dnsCredentials) | ||
} | ||
|
||
/* | ||
Original implementation of DNS ACME using OS.Env as payload | ||
*/ | ||
/* | ||
func setCredentialsIntoEnvironmentVariables(credentials map[string]string) { | ||
for key, value := range credentials { | ||
err := os.Setenv(key, value) | ||
if err != nil { | ||
log.Println("[ERR] Failed to set environment variable %s: %v", key, err) | ||
} else { | ||
log.Println("[INFO] Environment variable %s set successfully", key) | ||
//Clear the PollingInterval and PropagationTimeout field and conert to int | ||
userDefinedPollingInterval := 30 | ||
if dnsCredentialsMap["PollingInterval"] != nil { | ||
userDefinedPollingIntervalRaw := dnsCredentialsMap["PollingInterval"].(string) | ||
delete(dnsCredentialsMap, "PollingInterval") | ||
convertedPollingInterval, err := strconv.Atoi(userDefinedPollingIntervalRaw) | ||
if err == nil { | ||
userDefinedPollingInterval = convertedPollingInterval | ||
} | ||
} | ||
} | ||
func extractDnsCredentials(input string) (map[string]string, error) { | ||
result := make(map[string]string) | ||
|
||
// Split the input string by newline character | ||
lines := strings.Split(input, "\n") | ||
// Iterate over each line | ||
for _, line := range lines { | ||
// Split the line by "=" character | ||
//use SpliyN to make sure not to split the value if the value is base64 | ||
parts := strings.SplitN(line, "=", 1) | ||
// Check if the line is in the correct format | ||
if len(parts) == 2 { | ||
key := strings.TrimSpace(parts[0]) | ||
value := strings.TrimSpace(parts[1]) | ||
// Add the key-value pair to the map | ||
result[key] = value | ||
if value == "" || key == "" { | ||
//invalid config | ||
return result, errors.New("DNS credential extract failed") | ||
} | ||
userDefinedPropagationTimeout := ppgTimeout | ||
if dnsCredentialsMap["PropagationTimeout"] != nil { | ||
userDefinedPropagationTimeoutRaw := dnsCredentialsMap["PropagationTimeout"].(string) | ||
delete(dnsCredentialsMap, "PropagationTimeout") | ||
convertedPropagationTimeout, err := strconv.Atoi(userDefinedPropagationTimeoutRaw) | ||
if err == nil { | ||
//Overwrite the default propagation timeout if it is requeted from UI | ||
userDefinedPropagationTimeout = convertedPropagationTimeout | ||
} | ||
} | ||
|
||
return result, nil | ||
//Restructure dnsCredentials string from map | ||
dnsCredentialsBytes, err := json.Marshal(dnsCredentialsMap) | ||
if err != nil { | ||
return nil, err | ||
} | ||
dnsCredentials = string(dnsCredentialsBytes) | ||
|
||
//Using acmedns CICD pipeline generated datatype to optain the DNS provider | ||
return acmedns.GetDNSProviderByJsonConfig( | ||
dnsProvider, | ||
dnsCredentials, | ||
int64(userDefinedPropagationTimeout), | ||
int64(userDefinedPollingInterval), | ||
) | ||
} | ||
*/ |
Oops, something went wrong.