|
| 1 | +package ucloud |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + |
| 6 | + "github.com/go-acme/lego/v4/challenge" |
| 7 | + "github.com/go-acme/lego/v4/providers/dns/ucloud" |
| 8 | + |
| 9 | + "dillmann.com.br/nginx-ignition/certificate/letsencrypt/dns" |
| 10 | + "dillmann.com.br/nginx-ignition/core/common/dynamicfields" |
| 11 | + "dillmann.com.br/nginx-ignition/core/common/i18n" |
| 12 | +) |
| 13 | + |
| 14 | +const ( |
| 15 | + publicKeyFieldID = "uCloudPublicKey" |
| 16 | + privateKeyFieldID = "uCloudPrivateKey" |
| 17 | + regionFieldID = "uCloudRegion" |
| 18 | + projectIDFieldID = "uCloudProjectId" |
| 19 | +) |
| 20 | + |
| 21 | +type Provider struct{} |
| 22 | + |
| 23 | +func (p *Provider) ID() string { |
| 24 | + return "UCLOUD" |
| 25 | +} |
| 26 | + |
| 27 | +func (p *Provider) Name(ctx context.Context) *i18n.Message { |
| 28 | + return i18n.M(ctx, i18n.K.CertificateLetsencryptDnsUcloudName) |
| 29 | +} |
| 30 | + |
| 31 | +func (p *Provider) DynamicFields(ctx context.Context) []dynamicfields.DynamicField { |
| 32 | + return dns.LinkedToProvider(p.ID(), []dynamicfields.DynamicField{ |
| 33 | + { |
| 34 | + ID: publicKeyFieldID, |
| 35 | + Description: i18n.M(ctx, i18n.K.CertificateLetsencryptDnsUcloudPublicKey), |
| 36 | + Required: true, |
| 37 | + Sensitive: true, |
| 38 | + Type: dynamicfields.SingleLineTextType, |
| 39 | + }, |
| 40 | + { |
| 41 | + ID: privateKeyFieldID, |
| 42 | + Description: i18n.M(ctx, i18n.K.CertificateLetsencryptDnsUcloudPrivateKey), |
| 43 | + Required: true, |
| 44 | + Sensitive: true, |
| 45 | + Type: dynamicfields.SingleLineTextType, |
| 46 | + }, |
| 47 | + { |
| 48 | + ID: regionFieldID, |
| 49 | + Description: i18n.M(ctx, i18n.K.CertificateLetsencryptDnsUcloudRegion), |
| 50 | + Required: false, |
| 51 | + Type: dynamicfields.SingleLineTextType, |
| 52 | + }, |
| 53 | + { |
| 54 | + ID: projectIDFieldID, |
| 55 | + Description: i18n.M(ctx, i18n.K.CertificateLetsencryptDnsUcloudProjectId), |
| 56 | + Required: false, |
| 57 | + Type: dynamicfields.SingleLineTextType, |
| 58 | + }, |
| 59 | + }) |
| 60 | +} |
| 61 | + |
| 62 | +func (p *Provider) ChallengeProvider( |
| 63 | + _ context.Context, |
| 64 | + _ []string, |
| 65 | + parameters map[string]any, |
| 66 | +) (challenge.Provider, error) { |
| 67 | + publicKey, _ := parameters[publicKeyFieldID].(string) |
| 68 | + privateKey, _ := parameters[privateKeyFieldID].(string) |
| 69 | + region, _ := parameters[regionFieldID].(string) |
| 70 | + projectID, _ := parameters[projectIDFieldID].(string) |
| 71 | + |
| 72 | + cfg := ucloud.NewDefaultConfig() |
| 73 | + cfg.PublicKey = publicKey |
| 74 | + cfg.PrivateKey = privateKey |
| 75 | + cfg.Region = region |
| 76 | + cfg.ProjectID = projectID |
| 77 | + cfg.TTL = dns.TTL |
| 78 | + cfg.PropagationTimeout = dns.PropagationTimeout |
| 79 | + cfg.PollingInterval = dns.PollingInterval |
| 80 | + |
| 81 | + return ucloud.NewDNSProviderConfig(cfg) |
| 82 | +} |
0 commit comments