Skip to content

Commit 6e06215

Browse files
committed
feat(domain): add chore of new resource order domain
1 parent 4fb7dcb commit 6e06215

File tree

3 files changed

+414
-80
lines changed

3 files changed

+414
-80
lines changed

internal/services/domain/helpers.go

+94-18
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"strconv"
78
"strings"
89
"time"
910

@@ -295,7 +296,7 @@ func mapToStruct(data map[string]interface{}, target interface{}) {
295296
}
296297
}
297298

298-
func extractDomainFromID(id string) (string, error) {
299+
func ExtractDomainFromID(id string) (string, error) {
299300
parts := strings.Split(id, "/")
300301
if len(parts) != 2 {
301302
return "", fmt.Errorf("invalid ID format, expected 'projectID/domainName', got: %s", id)
@@ -442,43 +443,44 @@ func flattenContactExtensionNL(ext *domain.ContactExtensionNL) []map[string]inte
442443
}
443444
}
444445

445-
func flattenTLD(tld *domain.Tld) map[string]interface{} {
446+
func flattenTLD(tld *domain.Tld) []map[string]interface{} {
446447
if tld == nil {
447448
return nil
448449
}
449450

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+
},
458461
}
459462
}
460463

461-
func flattenTldOffers(offers map[string]*domain.TldOffer) map[string]interface{} {
464+
func flattenTldOffers(offers map[string]*domain.TldOffer) []map[string]interface{} {
462465
if offers == nil {
463466
return nil
464467
}
465468

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{}{
469472
"action": offer.Action,
470473
"operation_path": offer.OperationPath,
471474
"price": map[string]interface{}{
472475
"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)),
475478
},
476-
}
479+
})
477480
}
478481

479482
return flattenedOffers
480483
}
481-
482484
func flattenExternalDomainRegistrationStatus(status *domain.DomainRegistrationStatusExternalDomain) map[string]interface{} {
483485
if status == nil {
484486
return nil
@@ -588,3 +590,77 @@ func waitForTaskCompletion(ctx context.Context, registrarAPI *domain.RegistrarAP
588590
return retry.NonRetryableError(fmt.Errorf("unexpected task status: %v", status))
589591
})
590592
}
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

Comments
 (0)