Skip to content

Commit 9393a43

Browse files
committed
fix lint
1 parent e415128 commit 9393a43

File tree

3 files changed

+81
-54
lines changed

3 files changed

+81
-54
lines changed

internal/services/domain/domains_registration.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,12 @@ func resourceDomainsRegistrationCreate(ctx context.Context, d *schema.ResourceDa
417417
registrarAPI := NewRegistrarDomainAPI(m)
418418

419419
projectID := d.Get("project_id").(string)
420+
420421
domainNames := make([]string, 0)
421422
for _, v := range d.Get("domain_names").([]interface{}) {
422423
domainNames = append(domainNames, v.(string))
423424
}
425+
424426
durationInYears := uint32(d.Get("duration_in_years").(int))
425427

426428
buyDomainsRequest := &domain.RegistrarAPIBuyDomainsRequest{
@@ -430,6 +432,7 @@ func resourceDomainsRegistrationCreate(ctx context.Context, d *schema.ResourceDa
430432
}
431433

432434
ownerContactID := d.Get("owner_contact_id").(string)
435+
433436
if ownerContactID != "" {
434437
buyDomainsRequest.OwnerContactID = &ownerContactID
435438
} else if ownerContacts, ok := d.GetOk("owner_contact"); ok {
@@ -469,6 +472,7 @@ func resourceDomainsRegistrationsRead(ctx context.Context, d *schema.ResourceDat
469472
if err != nil {
470473
return diag.FromErr(err)
471474
}
475+
472476
if len(domainNames) == 0 {
473477
d.SetId("")
474478

@@ -504,7 +508,6 @@ func resourceDomainsRegistrationsRead(ctx context.Context, d *schema.ResourceDat
504508
}
505509

506510
computedDnssec := false
507-
508511
if firstResp.Dnssec.Status == domain.DomainFeatureStatusEnabled {
509512
computedDnssec = true
510513
}
@@ -539,6 +542,7 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
539542
if err != nil {
540543
return diag.FromErr(err)
541544
}
545+
542546
if len(domainNames) == 0 {
543547
d.SetId("")
544548

@@ -547,6 +551,7 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
547551

548552
if d.HasChange("auto_renew") {
549553
newAutoRenew := d.Get("auto_renew").(bool)
554+
550555
for _, domainName := range domainNames {
551556
domainResp, err := registrarAPI.GetDomain(&domain.RegistrarAPIGetDomainRequest{
552557
Domain: domainName,
@@ -556,7 +561,8 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
556561
}
557562

558563
if newAutoRenew {
559-
if domainResp.AutoRenewStatus != domain.DomainFeatureStatusEnabled && domainResp.AutoRenewStatus != domain.DomainFeatureStatusEnabling {
564+
if domainResp.AutoRenewStatus != domain.DomainFeatureStatusEnabled &&
565+
domainResp.AutoRenewStatus != domain.DomainFeatureStatusEnabling {
560566
_, err = registrarAPI.EnableDomainAutoRenew(&domain.RegistrarAPIEnableDomainAutoRenewRequest{
561567
Domain: domainName,
562568
}, scw.WithContext(ctx))
@@ -565,7 +571,8 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
565571
}
566572
}
567573
} else {
568-
if domainResp.AutoRenewStatus == domain.DomainFeatureStatusEnabled || domainResp.AutoRenewStatus == domain.DomainFeatureStatusEnabling {
574+
if domainResp.AutoRenewStatus == domain.DomainFeatureStatusEnabled ||
575+
domainResp.AutoRenewStatus == domain.DomainFeatureStatusEnabling {
569576
_, err = registrarAPI.DisableDomainAutoRenew(&domain.RegistrarAPIDisableDomainAutoRenewRequest{
570577
Domain: domainName,
571578
}, scw.WithContext(ctx))
@@ -574,6 +581,7 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
574581
}
575582
}
576583
}
584+
577585
_, err = waitForAutoRenewStatus(ctx, registrarAPI, domainName, d.Timeout(schema.TimeoutUpdate))
578586
if err != nil {
579587
return diag.FromErr(err)
@@ -583,6 +591,7 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
583591

584592
if d.HasChange("dnssec") {
585593
newDnssec := d.Get("dnssec").(bool)
594+
586595
for _, domainName := range domainNames {
587596
domainResp, err := registrarAPI.GetDomain(&domain.RegistrarAPIGetDomainRequest{
588597
Domain: domainName,
@@ -593,27 +602,31 @@ func resourceDomainsRegistrationUpdate(ctx context.Context, d *schema.ResourceDa
593602

594603
if newDnssec {
595604
var dsRecord *domain.DSRecord
605+
596606
if v, ok := d.GetOk("ds_record"); ok {
597607
dsRecordList := v.([]interface{})
598608
if len(dsRecordList) > 0 && dsRecordList[0] != nil {
599609
dsRecord = ExpandDSRecord(dsRecordList)
600610
}
601611
}
612+
602613
_, err = registrarAPI.EnableDomainDNSSEC(&domain.RegistrarAPIEnableDomainDNSSECRequest{
603614
Domain: domainName,
604615
DsRecord: dsRecord,
605616
}, scw.WithContext(ctx))
606617
if err != nil {
607618
return diag.FromErr(fmt.Errorf("failed to enable dnssec for %s: %w", domainName, err))
608619
}
609-
} else if domainResp.Dnssec != nil && domainResp.Dnssec.Status == domain.DomainFeatureStatusEnabled {
620+
} else if domainResp.Dnssec != nil &&
621+
domainResp.Dnssec.Status == domain.DomainFeatureStatusEnabled {
610622
_, err = registrarAPI.DisableDomainDNSSEC(&domain.RegistrarAPIDisableDomainDNSSECRequest{
611623
Domain: domainName,
612624
}, scw.WithContext(ctx))
613625
if err != nil {
614626
return diag.FromErr(fmt.Errorf("failed to disable dnssec for %s: %w", domainName, err))
615627
}
616628
}
629+
617630
_, err = waitForDNSSECStatus(ctx, registrarAPI, domainName, d.Timeout(schema.TimeoutUpdate))
618631
if err != nil {
619632
return diag.FromErr(err)

internal/services/domain/domains_registration_test.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package domain_test
22

33
import (
4+
"context"
45
"fmt"
56
"testing"
67

@@ -168,7 +169,7 @@ func testAccCheckDomainStatus(tt *acctest.TestTools, expectedAutoRenew, expected
168169
}
169170

170171
registrarAPI := domain.NewRegistrarDomainAPI(tt.Meta)
171-
domainNames, err := domain.ExtractDomainsFromTaskID(nil, rs.Primary.ID, registrarAPI)
172+
domainNames, err := domain.ExtractDomainsFromTaskID(context.TODO(), rs.Primary.ID, registrarAPI)
172173
if err != nil {
173174
return fmt.Errorf("error extracting domains: %w", err)
174175
}
@@ -180,12 +181,10 @@ func testAccCheckDomainStatus(tt *acctest.TestTools, expectedAutoRenew, expected
180181
if getErr != nil {
181182
return fmt.Errorf("failed to get details for domain %s: %w", domainName, getErr)
182183
}
183-
184184
if domainResp.AutoRenewStatus.String() != expectedAutoRenew {
185185
return fmt.Errorf("domain %s has auto_renew status %s, expected %s", domainName, domainResp.AutoRenewStatus, expectedAutoRenew)
186186
}
187187
if domainResp.Dnssec.Status.String() != expectedDNSSEC {
188-
189188
return fmt.Errorf("domain %s has dnssec status %s, expected %s", domainName, domainResp.Dnssec.Status.String(), expectedDNSSEC)
190189
}
191190
}
@@ -204,7 +203,7 @@ func testAccCheckDomainDestroy(tt *acctest.TestTools) resource.TestCheckFunc {
204203

205204
registrarAPI := domain.NewRegistrarDomainAPI(tt.Meta)
206205

207-
domainNames, err := domain.ExtractDomainsFromTaskID(nil, rs.Primary.ID, registrarAPI)
206+
domainNames, err := domain.ExtractDomainsFromTaskID(context.TODO(), rs.Primary.ID, registrarAPI)
208207
if err != nil {
209208
return err
210209
}
@@ -222,7 +221,6 @@ func testAccCheckDomainDestroy(tt *acctest.TestTools) resource.TestCheckFunc {
222221
}
223222

224223
if domainResp.AutoRenewStatus != domainSDK.DomainFeatureStatusDisabled {
225-
226224
return fmt.Errorf(
227225
"domain %s still exists, and auto-renew is not disabled (current: %s)",
228226
domainName,

internal/services/domain/helpers.go

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func NewDomainAPI(m interface{}) *domain.API {
2323
return domain.NewAPI(meta.ExtractScwClient(m))
2424
}
2525

26+
// NewRegistrarDomainAPI returns a new registrar API.
2627
func NewRegistrarDomainAPI(m interface{}) *domain.RegistrarAPI {
2728
return domain.NewRegistrarAPI(meta.ExtractScwClient(m))
2829
}
@@ -116,6 +117,7 @@ func ExpandContact(contactMap map[string]interface{}) *domain.Contact {
116117
contact.ExtensionFr = extension.(*domain.ContactExtensionFR)
117118
}
118119
}
120+
119121
if extEu, ok := contactMap["extension_eu"].(map[string]interface{}); ok && len(extEu) > 0 {
120122
extension := expandContactExtension(extEu, "eu")
121123
if extension != nil {
@@ -148,6 +150,7 @@ func expandContactExtension(extensionMap map[string]interface{}, extensionType s
148150
TrademarkInfo: parseStruct[domain.ContactExtensionFRTrademarkInfo](extensionMap, "trademark_info"),
149151
CodeAuthAfnicInfo: parseStruct[domain.ContactExtensionFRCodeAuthAfnicInfo](extensionMap, "code_auth_afnic_info"),
150152
}
153+
151154
case "nl":
152155
legalFormRegistrationNumber := ""
153156
if value, ok := extensionMap["legal_form_registration_number"]; ok {
@@ -160,6 +163,7 @@ func expandContactExtension(extensionMap map[string]interface{}, extensionType s
160163
LegalForm: domain.ContactExtensionNLLegalForm(parseEnum(extensionMap, "legal_form", domain.ContactExtensionNLLegalFormLegalFormUnknown.String())),
161164
LegalFormRegistrationNumber: legalFormRegistrationNumber,
162165
}
166+
163167
case "eu":
164168
europeanCitizenship := ""
165169
if value, ok := extensionMap["european_citizenship"]; ok {
@@ -171,6 +175,7 @@ func expandContactExtension(extensionMap map[string]interface{}, extensionType s
171175
return &domain.ContactExtensionEU{
172176
EuropeanCitizenship: europeanCitizenship,
173177
}
178+
174179
default:
175180
return nil
176181
}
@@ -233,6 +238,7 @@ func ExpandNewContact(contactMap map[string]interface{}) *domain.NewContact {
233238
contact.ExtensionFr = extension.(*domain.ContactExtensionFR)
234239
}
235240
}
241+
236242
if extEu, ok := contactMap["extension_eu"].(map[string]interface{}); ok && len(extEu) > 0 {
237243
extension := expandContactExtension(extEu, "eu")
238244
if extension != nil {
@@ -265,6 +271,7 @@ func parseStruct[T any](data map[string]interface{}, key string) *T {
265271

266272
return &result
267273
}
274+
268275
return nil
269276
}
270277

@@ -274,13 +281,15 @@ func mapToStruct(data map[string]interface{}, target interface{}) {
274281
if v, ok := data["whois_opt_in"].(bool); ok {
275282
t.WhoisOptIn = v
276283
}
284+
277285
case *domain.ContactExtensionFRDunsInfo:
278286
if v, ok := data["duns_id"].(string); ok {
279287
t.DunsID = v
280288
}
281289
if v, ok := data["local_id"].(string); ok {
282290
t.LocalID = v
283291
}
292+
284293
case *domain.ContactExtensionFRAssociationInfo:
285294
if v, ok := data["publication_jo"].(string); ok {
286295
if parsedTime, err := time.Parse(time.RFC3339, v); err == nil {
@@ -290,10 +299,12 @@ func mapToStruct(data map[string]interface{}, target interface{}) {
290299
if v, ok := data["publication_jo_page"].(float64); ok {
291300
t.PublicationJoPage = uint32(v)
292301
}
302+
293303
case *domain.ContactExtensionFRTrademarkInfo:
294304
if v, ok := data["trademark_inpi"].(string); ok {
295305
t.TrademarkInpi = v
296306
}
307+
297308
case *domain.ContactExtensionFRCodeAuthAfnicInfo:
298309
if v, ok := data["code_auth_afnic"].(string); ok {
299310
t.CodeAuthAfnic = v
@@ -304,6 +315,7 @@ func mapToStruct(data map[string]interface{}, target interface{}) {
304315
func getStatusTasks(ctx context.Context, api *domain.RegistrarAPI, taskID string) (domain.TaskStatus, error) {
305316
var page int32 = 1
306317
var pageSize uint32 = 1000
318+
307319
for {
308320
listTasksResponse, err := api.ListTasks(&domain.RegistrarAPIListTasksRequest{
309321
Page: &page,
@@ -356,6 +368,7 @@ func ExtractDomainsFromTaskID(ctx context.Context, id string, registrarAPI *doma
356368
if len(parts) != 2 {
357369
return nil, fmt.Errorf("invalid ID format, expected 'projectID/domainName', got: %s", id)
358370
}
371+
359372
taskID := parts[1]
360373

361374
listTasksResponse, err := registrarAPI.ListTasks(&domain.RegistrarAPIListTasksRequest{}, scw.WithContext(ctx), scw.WithAllPages())
@@ -402,9 +415,11 @@ func flattenContact(contact *domain.Contact) []map[string]interface{} {
402415
if contact.ExtensionFr != nil {
403416
flattened["extension_fr"] = flattenContactExtensionFR(contact.ExtensionFr)
404417
}
418+
405419
if contact.ExtensionEu != nil {
406420
flattened["extension_eu"] = flattenContactExtensionEU(contact.ExtensionEu)
407421
}
422+
408423
if contact.ExtensionNl != nil {
409424
flattened["extension_nl"] = flattenContactExtensionNL(contact.ExtensionNl)
410425
}
@@ -516,52 +531,9 @@ func flattenContactExtensionNL(ext *domain.ContactExtensionNL) []map[string]inte
516531
}
517532
}
518533

519-
// func flattenTLD(tld *domain.Tld) []map[string]interface{} {
520-
// if tld == nil {
521-
// return []map[string]interface{}{}
522-
// }
523-
// tldMap := map[string]interface{}{
524-
// "name": tld.Name,
525-
// "dnssec_support": tld.DnssecSupport,
526-
// "duration_in_years_min": tld.DurationInYearsMin,
527-
// "duration_in_years_max": tld.DurationInYearsMax,
528-
// "idn_support": tld.IDnSupport,
529-
// }
530-
//
531-
// tldMap["offers"] = flattenTldOffers(tld.Offers)
532-
//
533-
// if tld.Specifications != nil {
534-
// tldMap["specifications"] = tld.Specifications
535-
// } else {
536-
// tldMap["specifications"] = map[string]interface{}{}
537-
// }
538-
//
539-
// return []map[string]interface{}{tldMap}
540-
// }
541-
542-
// func flattenTldOffers(offers map[string]*domain.TldOffer) []map[string]interface{} {
543-
// if offers == nil {
544-
// return nil
545-
// }
546-
//
547-
// flattenedOffers := []map[string]interface{}{}
548-
// for _, offer := range offers {
549-
// flattenedOffers = append(flattenedOffers, map[string]interface{}{
550-
// "action": offer.Action,
551-
// "operation_path": offer.OperationPath,
552-
// "price": map[string]interface{}{
553-
// "currency_code": offer.Price.CurrencyCode,
554-
// "units": strconv.Itoa(int(offer.Price.Units)),
555-
// "nanos": strconv.Itoa(int(offer.Price.Nanos)),
556-
// },
557-
// })
558-
// }
559-
//
560-
// return flattenedOffers
561-
// }
562-
563534
func waitForTaskCompletion(ctx context.Context, registrarAPI *domain.RegistrarAPI, taskID string, duration int) error {
564535
timeout := time.Duration(duration) * time.Second
536+
565537
return retry.RetryContext(ctx, timeout, func() *retry.RetryError {
566538
status, err := getStatusTasks(ctx, registrarAPI, taskID)
567539
if err != nil {
@@ -577,7 +549,7 @@ func waitForTaskCompletion(ctx context.Context, registrarAPI *domain.RegistrarAP
577549
}
578550

579551
if status == domain.TaskStatusError {
580-
return retry.NonRetryableError(fmt.Errorf("task failed for domain: %s", taskID)) // Échec
552+
return retry.NonRetryableError(fmt.Errorf("task failed for domain: %s", taskID))
581553
}
582554

583555
return retry.NonRetryableError(fmt.Errorf("unexpected task status: %v", status))
@@ -661,6 +633,50 @@ func FlattenDSRecord(dsRecords []*domain.DSRecord) []interface{} {
661633
return results
662634
}
663635

636+
// func flattenTLD(tld *domain.Tld) []map[string]interface{} {
637+
// if tld == nil {
638+
// return []map[string]interface{}{}
639+
// }
640+
// tldMap := map[string]interface{}{
641+
// "name": tld.Name,
642+
// "dnssec_support": tld.DnssecSupport,
643+
// "duration_in_years_min": tld.DurationInYearsMin,
644+
// "duration_in_years_max": tld.DurationInYearsMax,
645+
// "idn_support": tld.IDnSupport,
646+
// }
647+
//
648+
// tldMap["offers"] = flattenTldOffers(tld.Offers)
649+
//
650+
// if tld.Specifications != nil {
651+
// tldMap["specifications"] = tld.Specifications
652+
// } else {
653+
// tldMap["specifications"] = map[string]interface{}{}
654+
// }
655+
//
656+
// return []map[string]interface{}{tldMap}
657+
// }
658+
659+
// func flattenTldOffers(offers map[string]*domain.TldOffer) []map[string]interface{} {
660+
// if offers == nil {
661+
// return nil
662+
// }
663+
//
664+
// flattenedOffers := []map[string]interface{}{}
665+
// for _, offer := range offers {
666+
// flattenedOffers = append(flattenedOffers, map[string]interface{}{
667+
// "action": offer.Action,
668+
// "operation_path": offer.OperationPath,
669+
// "price": map[string]interface{}{
670+
// "currency_code": offer.Price.CurrencyCode,
671+
// "units": strconv.Itoa(int(offer.Price.Units)),
672+
// "nanos": strconv.Itoa(int(offer.Price.Nanos)),
673+
// },
674+
// })
675+
// }
676+
//
677+
// return flattenedOffers
678+
// }
679+
664680
// func flattenDNSZones(dnsZones []*domain.DNSZone) []map[string]interface{} {
665681
// if dnsZones == nil {
666682
// return nil

0 commit comments

Comments
 (0)