Skip to content

Commit

Permalink
refactor(dns): Add formating
Browse files Browse the repository at this point in the history
  • Loading branch information
mlec1 committed Sep 24, 2024
1 parent 83036a6 commit 0fece24
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 32 deletions.
25 changes: 12 additions & 13 deletions cmd/dns_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func StringToDNSDomainRecordRequestType(recordType string) (v3.CreateDNSDomainRe
return "", errors.New("invalid DNS record type")
}


func addDomainRecord(domainIdent, name, rType, content string, ttl int64, priority *int64) error {
domain, err := domainFromIdent(domainIdent)
if err != nil {
Expand All @@ -58,15 +57,15 @@ func addDomainRecord(domainIdent, name, rType, content string, ttl int64, priori
err = decorateAsyncOperations(fmt.Sprintf("Adding DNS record %q to %q...", rType, domain.UnicodeName), func() error {

recordType, err := StringToDNSDomainRecordRequestType(rType)
if err != nil {
return fmt.Errorf("exoscale: error while get DNS record type: %w", err)
}
if err != nil {
return fmt.Errorf("exoscale: error while get DNS record type: %w", err)
}

dnsDomainRecordRequest := v3.CreateDNSDomainRecordRequest{
Content: content,
Name: name,
Ttl: ttl,
Type: recordType,
Name: name,
Ttl: ttl,
Type: recordType,
}

if priority != nil {
Expand All @@ -76,13 +75,13 @@ func addDomainRecord(domainIdent, name, rType, content string, ttl int64, priori
op, err := globalstate.EgoscaleV3Client.CreateDNSDomainRecord(ctx, domain.ID, dnsDomainRecordRequest)

if err != nil {
return fmt.Errorf("exoscale: error while creating DNS record: %w", err)
}
return fmt.Errorf("exoscale: error while creating DNS record: %w", err)
}

_, err = globalstate.EgoscaleV3Client.Wait(ctx, op, v3.OperationStateSuccess)
if err != nil {
return fmt.Errorf("exoscale: error while waiting for DNS record creation: %w", err)
}
_, err = globalstate.EgoscaleV3Client.Wait(ctx, op, v3.OperationStateSuccess)
if err != nil {
return fmt.Errorf("exoscale: error while waiting for DNS record creation: %w", err)
}

return nil
})
Expand Down
12 changes: 6 additions & 6 deletions cmd/dns_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ func deleteDomain(ident string, force bool) error {
decorateAsyncOperations(fmt.Sprintf("Deleting DNS domain %q...", domain.UnicodeName), func() error {
op, err := globalstate.EgoscaleV3Client.DeleteDNSDomain(ctx, domain.ID)
if err != nil {
return fmt.Errorf("exoscale: error while deleting DNS domain: %w", err)
}
return fmt.Errorf("exoscale: error while deleting DNS domain: %w", err)
}

_, err = globalstate.EgoscaleV3Client.Wait(ctx, op, v3.OperationStateSuccess)
if err != nil {
return fmt.Errorf("exoscale: error while waiting DNS domain deletion: %w", err)
}
_, err = globalstate.EgoscaleV3Client.Wait(ctx, op, v3.OperationStateSuccess)
if err != nil {
return fmt.Errorf("exoscale: error while waiting DNS domain deletion: %w", err)
}

return nil
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/dns_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func listDomains(filters []string) (output.Outputter, error) {

// Convert v3.UUID to string using String() method, then get a pointer to it
// Don't know if it is best practice
idStr := d.ID.String() // Convert UUID to string
idStr := d.ID.String() // Convert UUID to string

o := dnsListItemOutput{
ID: StrPtrFormatOutput(&idStr),
Expand Down
12 changes: 6 additions & 6 deletions cmd/dns_records_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,13 @@ func updateDomainRecord(
decorateAsyncOperations(fmt.Sprintf("Updating DNS record %q...", record.ID), func() error {
op, err := globalstate.EgoscaleV3Client.UpdateDNSDomainRecord(ctx, domain.ID, record.ID, recordUpdateRequest)
if err != nil {
return fmt.Errorf("exoscale: error while updating DNS record: %w", err)
}
return fmt.Errorf("exoscale: error while updating DNS record: %w", err)
}

_, err = globalstate.EgoscaleV3Client.Wait(ctx, op, v3.OperationStateSuccess)
if err != nil {
return fmt.Errorf("exoscale: error while waiting for DNS record update: %w", err)
}
_, err = globalstate.EgoscaleV3Client.Wait(ctx, op, v3.OperationStateSuccess)
if err != nil {
return fmt.Errorf("exoscale: error while waiting for DNS record update: %w", err)
}

return nil
})
Expand Down
12 changes: 6 additions & 6 deletions cmd/dns_remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func removeDomainRecord(domainIdent, recordIdent string, force bool) error {
decorateAsyncOperations(fmt.Sprintf("Deleting DNS record %q...", domain.UnicodeName), func() error {
op, err := globalstate.EgoscaleV3Client.DeleteDNSDomainRecord(ctx, domain.ID, record.ID)
if err != nil {
return fmt.Errorf("exoscale: error while deleting DNS record: %w", err)
}
return fmt.Errorf("exoscale: error while deleting DNS record: %w", err)
}

_, err = globalstate.EgoscaleV3Client.Wait(ctx, op, v3.OperationStateSuccess)
if err != nil {
return fmt.Errorf("exoscale: error while waiting DNS record deletion: %w", err)
}
_, err = globalstate.EgoscaleV3Client.Wait(ctx, op, v3.OperationStateSuccess)
if err != nil {
return fmt.Errorf("exoscale: error while waiting DNS record deletion: %w", err)
}

return nil
})
Expand Down

0 comments on commit 0fece24

Please sign in to comment.