1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package acme
- import (
- "encoding/json"
- "strconv"
- "github.com/go-acme/lego/v4/challenge"
- "imuslab.com/zoraxy/mod/acme/acmedns"
- )
- // 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
- }
- //Clear the PollingInterval and PropagationTimeout field and conert to int
- userDefinedPollingIntervalRaw := dnsCredentialsMap["PollingInterval"].(string)
- userDefinedPropagationTimeoutRaw := dnsCredentialsMap["PropagationTimeout"].(string)
- delete(dnsCredentialsMap, "PollingInterval")
- delete(dnsCredentialsMap, "PropagationTimeout")
- userDefinedPollingInterval, err := strconv.Atoi(userDefinedPollingIntervalRaw)
- if err != nil {
- userDefinedPollingInterval = 30
- }
- userDefinedPropagationTimeout, err := strconv.Atoi(userDefinedPropagationTimeoutRaw)
- if err != nil {
- userDefinedPropagationTimeout = 300
- }
- //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),
- )
- }
|