|
4 | 4 | "context"
|
5 | 5 | "errors"
|
6 | 6 | "fmt"
|
| 7 | + "strconv" |
7 | 8 | "strings"
|
8 | 9 | "time"
|
9 | 10 |
|
@@ -295,7 +296,7 @@ func mapToStruct(data map[string]interface{}, target interface{}) {
|
295 | 296 | }
|
296 | 297 | }
|
297 | 298 |
|
298 |
| -func extractDomainFromID(id string) (string, error) { |
| 299 | +func ExtractDomainFromID(id string) (string, error) { |
299 | 300 | parts := strings.Split(id, "/")
|
300 | 301 | if len(parts) != 2 {
|
301 | 302 | return "", fmt.Errorf("invalid ID format, expected 'projectID/domainName', got: %s", id)
|
@@ -442,43 +443,44 @@ func flattenContactExtensionNL(ext *domain.ContactExtensionNL) []map[string]inte
|
442 | 443 | }
|
443 | 444 | }
|
444 | 445 |
|
445 |
| -func flattenTLD(tld *domain.Tld) map[string]interface{} { |
| 446 | +func flattenTLD(tld *domain.Tld) []map[string]interface{} { |
446 | 447 | if tld == nil {
|
447 | 448 | return nil
|
448 | 449 | }
|
449 | 450 |
|
450 |
| - return map[string]interface{}{ |
451 |
| - "name": tld.Name, |
452 |
| - "dnssec_support": tld.DnssecSupport, |
453 |
| - "duration_in_years_min": tld.DurationInYearsMin, |
454 |
| - "duration_in_years_max": tld.DurationInYearsMax, |
455 |
| - "idn_support": tld.IDnSupport, |
456 |
| - "offers": flattenTldOffers(tld.Offers), |
457 |
| - "specifications": tld.Specifications, |
| 451 | + return []map[string]interface{}{ |
| 452 | + { |
| 453 | + "name": tld.Name, |
| 454 | + "dnssec_support": tld.DnssecSupport, |
| 455 | + "duration_in_years_min": tld.DurationInYearsMin, |
| 456 | + "duration_in_years_max": tld.DurationInYearsMax, |
| 457 | + "idn_support": tld.IDnSupport, |
| 458 | + "offers": flattenTldOffers(tld.Offers), |
| 459 | + "specifications": tld.Specifications, |
| 460 | + }, |
458 | 461 | }
|
459 | 462 | }
|
460 | 463 |
|
461 |
| -func flattenTldOffers(offers map[string]*domain.TldOffer) map[string]interface{} { |
| 464 | +func flattenTldOffers(offers map[string]*domain.TldOffer) []map[string]interface{} { |
462 | 465 | if offers == nil {
|
463 | 466 | return nil
|
464 | 467 | }
|
465 | 468 |
|
466 |
| - flattenedOffers := make(map[string]interface{}) |
467 |
| - for key, offer := range offers { |
468 |
| - flattenedOffers[key] = map[string]interface{}{ |
| 469 | + flattenedOffers := []map[string]interface{}{} |
| 470 | + for _, offer := range offers { |
| 471 | + flattenedOffers = append(flattenedOffers, map[string]interface{}{ |
469 | 472 | "action": offer.Action,
|
470 | 473 | "operation_path": offer.OperationPath,
|
471 | 474 | "price": map[string]interface{}{
|
472 | 475 | "currency_code": offer.Price.CurrencyCode,
|
473 |
| - "units": offer.Price.Units, |
474 |
| - "nanos": offer.Price.Nanos, |
| 476 | + "units": strconv.Itoa(int(offer.Price.Units)), |
| 477 | + "nanos": strconv.Itoa(int(offer.Price.Nanos)), |
475 | 478 | },
|
476 |
| - } |
| 479 | + }) |
477 | 480 | }
|
478 | 481 |
|
479 | 482 | return flattenedOffers
|
480 | 483 | }
|
481 |
| - |
482 | 484 | func flattenExternalDomainRegistrationStatus(status *domain.DomainRegistrationStatusExternalDomain) map[string]interface{} {
|
483 | 485 | if status == nil {
|
484 | 486 | return nil
|
@@ -588,3 +590,77 @@ func waitForTaskCompletion(ctx context.Context, registrarAPI *domain.RegistrarAP
|
588 | 590 | return retry.NonRetryableError(fmt.Errorf("unexpected task status: %v", status))
|
589 | 591 | })
|
590 | 592 | }
|
| 593 | + |
| 594 | +func ExpandDSRecord(dsRecordList []interface{}) *domain.DSRecord { |
| 595 | + if len(dsRecordList) == 0 || dsRecordList[0] == nil { |
| 596 | + return nil |
| 597 | + } |
| 598 | + |
| 599 | + dsRecordMap := dsRecordList[0].(map[string]interface{}) |
| 600 | + dsRecord := &domain.DSRecord{ |
| 601 | + KeyID: uint32(dsRecordMap["key_id"].(int)), |
| 602 | + Algorithm: domain.DSRecordAlgorithm(dsRecordMap["algorithm"].(string)), |
| 603 | + } |
| 604 | + |
| 605 | + if digestList, ok := dsRecordMap["digest"].([]interface{}); ok && len(digestList) > 0 { |
| 606 | + digestMap := digestList[0].(map[string]interface{}) |
| 607 | + dsRecord.Digest = &domain.DSRecordDigest{ |
| 608 | + Type: domain.DSRecordDigestType(digestMap["type"].(string)), |
| 609 | + Digest: digestMap["digest"].(string), |
| 610 | + } |
| 611 | + |
| 612 | + if publicKeyList, ok := digestMap["public_key"].([]interface{}); ok && len(publicKeyList) > 0 { |
| 613 | + publicKeyMap := publicKeyList[0].(map[string]interface{}) |
| 614 | + dsRecord.Digest.PublicKey = &domain.DSRecordPublicKey{ |
| 615 | + Key: publicKeyMap["key"].(string), |
| 616 | + } |
| 617 | + } |
| 618 | + } |
| 619 | + |
| 620 | + if publicKeyList, ok := dsRecordMap["public_key"].([]interface{}); ok && len(publicKeyList) > 0 { |
| 621 | + publicKeyMap := publicKeyList[0].(map[string]interface{}) |
| 622 | + dsRecord.PublicKey = &domain.DSRecordPublicKey{ |
| 623 | + Key: publicKeyMap["key"].(string), |
| 624 | + } |
| 625 | + } |
| 626 | + |
| 627 | + return dsRecord |
| 628 | +} |
| 629 | + |
| 630 | +func FlattenDSRecord(dsRecord *domain.DSRecord) []map[string]interface{} { |
| 631 | + if dsRecord == nil { |
| 632 | + return nil |
| 633 | + } |
| 634 | + |
| 635 | + result := map[string]interface{}{ |
| 636 | + "key_id": dsRecord.KeyID, |
| 637 | + "algorithm": string(dsRecord.Algorithm), |
| 638 | + } |
| 639 | + |
| 640 | + if dsRecord.Digest != nil { |
| 641 | + digest := map[string]interface{}{ |
| 642 | + "type": string(dsRecord.Digest.Type), |
| 643 | + "digest": dsRecord.Digest.Digest, |
| 644 | + } |
| 645 | + |
| 646 | + if dsRecord.Digest.PublicKey != nil { |
| 647 | + digest["public_key"] = []map[string]interface{}{ |
| 648 | + { |
| 649 | + "key": dsRecord.Digest.PublicKey.Key, |
| 650 | + }, |
| 651 | + } |
| 652 | + } |
| 653 | + |
| 654 | + result["digest"] = []map[string]interface{}{digest} |
| 655 | + } |
| 656 | + |
| 657 | + if dsRecord.PublicKey != nil { |
| 658 | + result["public_key"] = []map[string]interface{}{ |
| 659 | + { |
| 660 | + "key": dsRecord.PublicKey.Key, |
| 661 | + }, |
| 662 | + } |
| 663 | + } |
| 664 | + |
| 665 | + return []map[string]interface{}{result} |
| 666 | +} |
0 commit comments