|
| 1 | +package acmedns |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "strings" |
| 6 | + |
| 7 | + "github.com/aws/smithy-go/ptr" |
| 8 | + "github.com/go-acme/lego/v4/challenge" |
| 9 | + legoacmedns "github.com/go-acme/lego/v4/providers/dns/acmedns" |
| 10 | + |
| 11 | + "dillmann.com.br/nginx-ignition/certificate/letsencrypt/dns" |
| 12 | + "dillmann.com.br/nginx-ignition/core/common/dynamic_fields" |
| 13 | +) |
| 14 | + |
| 15 | +const ( |
| 16 | + apiBaseFieldID = "acmednsApiBase" |
| 17 | + allowListFieldID = "acmednsAllowList" |
| 18 | + storagePathFieldID = "acmednsStoragePath" |
| 19 | + storageBaseURLFieldID = "acmednsStorageBaseURL" |
| 20 | +) |
| 21 | + |
| 22 | +type Provider struct{} |
| 23 | + |
| 24 | +func (p *Provider) ID() string { return "ACME_DNS" } |
| 25 | + |
| 26 | +func (p *Provider) Name() string { return "ACME-DNS" } |
| 27 | + |
| 28 | +func (p *Provider) DynamicFields() []*dynamic_fields.DynamicField { |
| 29 | + return dns.LinkedToProvider(p.ID(), []dynamic_fields.DynamicField{ |
| 30 | + { |
| 31 | + ID: apiBaseFieldID, |
| 32 | + Description: "ACME-DNS API base (e.g., https://acmedns.example.com)", |
| 33 | + Required: true, |
| 34 | + Type: dynamic_fields.SingleLineTextType, |
| 35 | + }, |
| 36 | + { |
| 37 | + ID: allowListFieldID, |
| 38 | + Description: "Comma-separated list of CIDR sources allowed to update (optional)", |
| 39 | + Type: dynamic_fields.SingleLineTextType, |
| 40 | + }, |
| 41 | + { |
| 42 | + ID: storagePathFieldID, |
| 43 | + Description: "Local storage file path for ACME-DNS accounts", |
| 44 | + HelpText: ptr.String("Mutually exclusive with storage base URL"), |
| 45 | + Type: dynamic_fields.SingleLineTextType, |
| 46 | + }, |
| 47 | + { |
| 48 | + ID: storageBaseURLFieldID, |
| 49 | + Description: "Remote storage base URL for ACME-DNS accounts", |
| 50 | + HelpText: ptr.String("Mutually exclusive with storage path"), |
| 51 | + Type: dynamic_fields.SingleLineTextType, |
| 52 | + }, |
| 53 | + }) |
| 54 | +} |
| 55 | + |
| 56 | +func (p *Provider) ChallengeProvider( |
| 57 | + _ context.Context, |
| 58 | + _ []string, |
| 59 | + parameters map[string]any, |
| 60 | +) (challenge.Provider, error) { |
| 61 | + apiBase, _ := parameters[apiBaseFieldID].(string) |
| 62 | + allowListStr, _ := parameters[allowListFieldID].(string) |
| 63 | + storagePath, _ := parameters[storagePathFieldID].(string) |
| 64 | + storageBaseURL, _ := parameters[storageBaseURLFieldID].(string) |
| 65 | + |
| 66 | + cfg := &legoacmedns.Config{ |
| 67 | + APIBase: apiBase, |
| 68 | + StoragePath: storagePath, |
| 69 | + StorageBaseURL: storageBaseURL, |
| 70 | + } |
| 71 | + |
| 72 | + if allowListStr != "" { |
| 73 | + var list []string |
| 74 | + for _, raw := range strings.Split(allowListStr, ",") { |
| 75 | + trimmedValue := strings.TrimSpace(raw) |
| 76 | + if trimmedValue != "" { |
| 77 | + list = append(list, trimmedValue) |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + cfg.AllowList = list |
| 82 | + } |
| 83 | + |
| 84 | + return legoacmedns.NewDNSProviderConfig(cfg) |
| 85 | +} |
0 commit comments