1
0

acme_dns.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package acme
  2. import (
  3. "encoding/json"
  4. "strconv"
  5. "github.com/go-acme/lego/v4/challenge"
  6. "imuslab.com/zoraxy/mod/acme/acmedns"
  7. )
  8. // Preprocessor function to get DNS challenge provider by name
  9. func GetDnsChallengeProviderByName(dnsProvider string, dnsCredentials string, ppgTimeout int) (challenge.Provider, error) {
  10. //Unpack the dnsCredentials (json string) to map
  11. var dnsCredentialsMap map[string]interface{}
  12. err := json.Unmarshal([]byte(dnsCredentials), &dnsCredentialsMap)
  13. if err != nil {
  14. return nil, err
  15. }
  16. //Clear the PollingInterval and PropagationTimeout field and conert to int
  17. userDefinedPollingIntervalRaw := dnsCredentialsMap["PollingInterval"].(string)
  18. userDefinedPropagationTimeoutRaw := dnsCredentialsMap["PropagationTimeout"].(string)
  19. delete(dnsCredentialsMap, "PollingInterval")
  20. delete(dnsCredentialsMap, "PropagationTimeout")
  21. userDefinedPollingInterval, err := strconv.Atoi(userDefinedPollingIntervalRaw)
  22. if err != nil {
  23. userDefinedPollingInterval = 30
  24. }
  25. userDefinedPropagationTimeout, err := strconv.Atoi(userDefinedPropagationTimeoutRaw)
  26. if err != nil {
  27. userDefinedPropagationTimeout = 300
  28. }
  29. //Restructure dnsCredentials string from map
  30. dnsCredentialsBytes, err := json.Marshal(dnsCredentialsMap)
  31. if err != nil {
  32. return nil, err
  33. }
  34. dnsCredentials = string(dnsCredentialsBytes)
  35. //Using acmedns CICD pipeline generated datatype to optain the DNS provider
  36. return acmedns.GetDNSProviderByJsonConfig(
  37. dnsProvider,
  38. dnsCredentials,
  39. int64(userDefinedPropagationTimeout),
  40. int64(userDefinedPollingInterval),
  41. )
  42. }