mirror of
https://github.com/woodchen-ink/certimate.git
synced 2025-07-18 17:31:55 +08:00
chore: improve error messages
This commit is contained in:
parent
eb4d5ddfd5
commit
ecff16c89d
@ -89,7 +89,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||||||
|
|
||||||
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("baiducloud: %w", err)
|
return fmt.Errorf("baiducloud: could not find zone for domain %q: %w", domain, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
||||||
@ -109,7 +109,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
|||||||
|
|
||||||
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("baiducloud: %w", err)
|
return fmt.Errorf("baiducloud: could not find zone for domain %q: %w", domain, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
||||||
|
@ -93,7 +93,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||||||
|
|
||||||
zoneName, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
zoneName, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cmccecloud: %w", err)
|
return fmt.Errorf("cmccecloud: could not find zone for domain %q: %w", domain, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, zoneName)
|
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, zoneName)
|
||||||
@ -108,33 +108,33 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if record == nil {
|
if record == nil {
|
||||||
// add new record
|
|
||||||
resp, err := d.client.CreateRecordOpenapi(&model.CreateRecordOpenapiRequest{
|
resp, err := d.client.CreateRecordOpenapi(&model.CreateRecordOpenapiRequest{
|
||||||
CreateRecordOpenapiBody: &model.CreateRecordOpenapiBody{
|
CreateRecordOpenapiBody: &model.CreateRecordOpenapiBody{
|
||||||
LineId: "0", // 默认线路
|
LineId: "0", // 默认线路
|
||||||
Rr: subDomain,
|
Rr: subDomain,
|
||||||
DomainName: readDomain,
|
DomainName: readDomain,
|
||||||
Description: "from certimate",
|
Description: "certimate acme",
|
||||||
Type: model.CreateRecordOpenapiBodyTypeEnumTxt,
|
Type: model.CreateRecordOpenapiBodyTypeEnumTxt,
|
||||||
Value: info.Value,
|
Value: info.Value,
|
||||||
Ttl: &d.config.TTL,
|
Ttl: &d.config.TTL,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("lego: %w", err)
|
return fmt.Errorf("cmccecloud: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.State != model.CreateRecordOpenapiResponseStateEnumOk {
|
if resp.State != model.CreateRecordOpenapiResponseStateEnumOk {
|
||||||
return fmt.Errorf("lego: create record failed, response state: %s, message: %s, code: %s", resp.State, resp.ErrorMessage, resp.ErrorCode)
|
return fmt.Errorf("cmccecloud: create record failed, response state: %s, message: %s, code: %s", resp.State, resp.ErrorMessage, resp.ErrorCode)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
} else {
|
} else {
|
||||||
// update record
|
|
||||||
resp, err := d.client.ModifyRecordOpenapi(&model.ModifyRecordOpenapiRequest{
|
resp, err := d.client.ModifyRecordOpenapi(&model.ModifyRecordOpenapiRequest{
|
||||||
ModifyRecordOpenapiBody: &model.ModifyRecordOpenapiBody{
|
ModifyRecordOpenapiBody: &model.ModifyRecordOpenapiBody{
|
||||||
RecordId: record.RecordId,
|
RecordId: record.RecordId,
|
||||||
Rr: subDomain,
|
Rr: subDomain,
|
||||||
DomainName: readDomain,
|
DomainName: readDomain,
|
||||||
Description: "from certmate",
|
Description: "certmate acme",
|
||||||
LineId: "0",
|
LineId: "0",
|
||||||
Type: model.ModifyRecordOpenapiBodyTypeEnumTxt,
|
Type: model.ModifyRecordOpenapiBodyTypeEnumTxt,
|
||||||
Value: info.Value,
|
Value: info.Value,
|
||||||
@ -142,44 +142,52 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("lego: %w", err)
|
return fmt.Errorf("cmccecloud: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.State != model.ModifyRecordOpenapiResponseStateEnumOk {
|
if resp.State != model.ModifyRecordOpenapiResponseStateEnumOk {
|
||||||
return fmt.Errorf("lego: create record failed, response state: %s", resp.State)
|
return fmt.Errorf("cmccecloud: create record failed, response state: %s", resp.State)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
||||||
challengeInfo := dns01.GetChallengeInfo(domain, keyAuth)
|
challengeInfo := dns01.GetChallengeInfo(domain, keyAuth)
|
||||||
|
|
||||||
zoneName, err := dns01.FindZoneByFqdn(challengeInfo.FQDN)
|
zoneName, err := dns01.FindZoneByFqdn(challengeInfo.FQDN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cmccecloud: %w", err)
|
return fmt.Errorf("cmccecloud: could not find zone for domain %q: %w", domain, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subDomain, err := dns01.ExtractSubDomain(challengeInfo.FQDN, zoneName)
|
subDomain, err := dns01.ExtractSubDomain(challengeInfo.FQDN, zoneName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cmccecloud: %w", err)
|
return fmt.Errorf("cmccecloud: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
readDomain := strings.Trim(zoneName, ".")
|
readDomain := strings.Trim(zoneName, ".")
|
||||||
record, err := d.getDomainRecord(readDomain, subDomain)
|
record, err := d.getDomainRecord(readDomain, subDomain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if record == nil {
|
if record == nil {
|
||||||
return nil
|
return nil
|
||||||
|
} else {
|
||||||
|
resp, err := d.client.DeleteRecordOpenapi(&model.DeleteRecordOpenapiRequest{
|
||||||
|
DeleteRecordOpenapiBody: &model.DeleteRecordOpenapiBody{
|
||||||
|
RecordIdList: []string{record.RecordId},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("cmccecloud: %w", err)
|
||||||
|
}
|
||||||
|
if resp.State != model.DeleteRecordOpenapiResponseStateEnumOk {
|
||||||
|
return fmt.Errorf("cmccecloud: delete record failed, unexpected response state: %s", resp.State)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
resp, err := d.client.DeleteRecordOpenapi(&model.DeleteRecordOpenapiRequest{
|
|
||||||
DeleteRecordOpenapiBody: &model.DeleteRecordOpenapiBody{
|
|
||||||
RecordIdList: []string{record.RecordId},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("lego: %w", err)
|
|
||||||
}
|
|
||||||
if resp.State != model.DeleteRecordOpenapiResponseStateEnumOk {
|
|
||||||
return fmt.Errorf("lego: delete record failed, response state: %s", resp.State)
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,8 +213,9 @@ func (d *DNSProvider) getDomainRecord(domain string, rr string) (*model.ListReco
|
|||||||
}
|
}
|
||||||
if resp.State != model.ListRecordOpenapiResponseStateEnumOk {
|
if resp.State != model.ListRecordOpenapiResponseStateEnumOk {
|
||||||
respStr, _ := json.Marshal(resp)
|
respStr, _ := json.Marshal(resp)
|
||||||
return nil, fmt.Errorf("request error. %s", string(respStr))
|
return nil, fmt.Errorf("cmccecloud: request error: %s", string(respStr))
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.Body.Data != nil {
|
if resp.Body.Data != nil {
|
||||||
for _, item := range *resp.Body.Data {
|
for _, item := range *resp.Body.Data {
|
||||||
if item.Rr == rr {
|
if item.Rr == rr {
|
||||||
@ -214,9 +223,11 @@ func (d *DNSProvider) getDomainRecord(domain string, rr string) (*model.ListReco
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.Body.TotalPages == nil || page >= *resp.Body.TotalPages {
|
if resp.Body.TotalPages == nil || page >= *resp.Body.TotalPages {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
page++
|
page++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||||||
|
|
||||||
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("dnsla: %w", err)
|
return fmt.Errorf("dnsla: could not find zone for domain %q: %w", domain, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
||||||
@ -103,7 +103,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
|||||||
|
|
||||||
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("dnsla: %w", err)
|
return fmt.Errorf("dnsla: could not find zone for domain %q: %w", domain, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
||||||
|
@ -76,7 +76,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||||||
|
|
||||||
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("dynv6: %w", err)
|
return fmt.Errorf("dynv6: could not find zone for domain %q: %w", domain, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
||||||
@ -96,7 +96,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
|||||||
|
|
||||||
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("dynv6: %w", err)
|
return fmt.Errorf("dynv6: could not find zone for domain %q: %w", domain, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
||||||
|
@ -82,7 +82,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||||||
|
|
||||||
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("gname: %w", err)
|
return fmt.Errorf("gname: could not find zone for domain %q: %w", domain, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
||||||
@ -102,7 +102,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
|||||||
|
|
||||||
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("gname: %w", err)
|
return fmt.Errorf("gname: could not find zone for domain %q: %w", domain, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
||||||
|
@ -91,7 +91,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
|
|||||||
|
|
||||||
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("jdcloud: %w", err)
|
return fmt.Errorf("jdcloud: could not find zone for domain %q: %w", domain, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
||||||
@ -111,7 +111,7 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
|
|||||||
|
|
||||||
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("jdcloud: %w", err)
|
return fmt.Errorf("jdcloud: could not find zone for domain %q: %w", domain, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
subDomain, err := dns01.ExtractSubDomain(info.EffectiveFQDN, authZone)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user