1
0

acme_dns.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package acme
  2. import (
  3. "github.com/go-acme/lego/v4/challenge"
  4. "imuslab.com/zoraxy/mod/acme/acmedns"
  5. )
  6. func GetDnsChallengeProviderByName(dnsProvider string, dnsCredentials string) (challenge.Provider, error) {
  7. //Original Implementation
  8. /*credentials, err := extractDnsCredentials(dnsCredentials)
  9. if err != nil {
  10. return nil, err
  11. }
  12. setCredentialsIntoEnvironmentVariables(credentials)
  13. provider, err := dns.NewDNSChallengeProviderByName(dnsProvider)
  14. */
  15. //New implementation using acmedns CICD pipeline generated datatype
  16. return acmedns.GetDNSProviderByJsonConfig(dnsProvider, dnsCredentials)
  17. }
  18. /*
  19. Original implementation of DNS ACME using OS.Env as payload
  20. */
  21. /*
  22. func setCredentialsIntoEnvironmentVariables(credentials map[string]string) {
  23. for key, value := range credentials {
  24. err := os.Setenv(key, value)
  25. if err != nil {
  26. log.Println("[ERR] Failed to set environment variable %s: %v", key, err)
  27. } else {
  28. log.Println("[INFO] Environment variable %s set successfully", key)
  29. }
  30. }
  31. }
  32. func extractDnsCredentials(input string) (map[string]string, error) {
  33. result := make(map[string]string)
  34. // Split the input string by newline character
  35. lines := strings.Split(input, "\n")
  36. // Iterate over each line
  37. for _, line := range lines {
  38. // Split the line by "=" character
  39. //use SpliyN to make sure not to split the value if the value is base64
  40. parts := strings.SplitN(line, "=", 1)
  41. // Check if the line is in the correct format
  42. if len(parts) == 2 {
  43. key := strings.TrimSpace(parts[0])
  44. value := strings.TrimSpace(parts[1])
  45. // Add the key-value pair to the map
  46. result[key] = value
  47. if value == "" || key == "" {
  48. //invalid config
  49. return result, errors.New("DNS credential extract failed")
  50. }
  51. }
  52. }
  53. return result, nil
  54. }
  55. */