Skip to content

Commit

Permalink
cleanup(all) Merge lint from main (#3358)
Browse files Browse the repository at this point in the history
Co-authored-by: Asif Nawaz <[email protected]>
  • Loading branch information
tlimoncelli and AsifNawaz-cnic authored Jan 13, 2025
1 parent c9ca2f6 commit b1b2a2a
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 7 deletions.
2 changes: 1 addition & 1 deletion integrationTest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ func makeRec(name, target, typ string) *models.RecordConfig {
func manyA(namePattern, target string, n int) []*models.RecordConfig {
recs := []*models.RecordConfig{}
for i := range n {
//recs = append(recs, makeRec(fmt.Sprintf(namePattern, i), target, "A"))
recs = append(recs, a(fmt.Sprintf(namePattern, i), target))
//recs = append(recs, makeRec(fmt.Sprintf(namePattern, i), target, "A"))
}
return recs
}
Expand Down
32 changes: 32 additions & 0 deletions models/cloudflare_from.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,38 @@ import (
// MakeSingleRedirectFromRawRec updates a RecordConfig to be a
// SINGLEREDIRECT using the data from a RawRecord.
func MakeSingleRedirectFromRawRec(rc *RecordConfig, code uint16, name, when, then string) error {
//// MakePageRule updates a RecordConfig to be a PAGE_RULE using PAGE_RULE data.
//func MakePageRule(rc *models.RecordConfig, priority int, code uint16, when, then string) error {
// if rc == nil {
// return errors.New("RecordConfig cannot be nil")
// }
// if when == "" || then == "" {
// return errors.New("when and then parameters cannot be empty")
// }
//
// display := mkPageRuleBlob(priority, code, when, then)
//
// rc.Type = "PAGE_RULE"
// rc.TTL = 1
// rc.CloudflareRedirect = &models.CloudflareSingleRedirectConfig{
// Code: code,
// //
// PRWhen: when,
// PRThen: then,
// PRPriority: priority,
// PRDisplay: display,
// }
// return rc.SetTarget(display)
//}
//
//// mkPageRuleBlob creates the 1,301,when,then string used in displays.
//func mkPageRuleBlob(priority int, code uint16, when, then string) string {
// return fmt.Sprintf("%d,%03d,%s,%s", priority, code, when, then)
//}
//
//// makeSingleRedirectFromRawRec updates a RecordConfig to be a
//// SINGLEREDIRECT using the data from a RawRecord.
//func makeSingleRedirectFromRawRec(rc *models.RecordConfig, code uint16, name, when, then string) error {
target := targetFromRaw(name, code, when, then)

rc.Type = "CF_SINGLE_REDIRECT"
Expand Down
1 change: 0 additions & 1 deletion models/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ func (rc *RecordConfig) SetLabel3(short, subdomain, origin string) error {
// fqdn may have a trailing "." but it is not required.
// origin may not have a trailing dot.
func (rc *RecordConfig) SetLabelFromFQDN(fqdn, origin string) {

// Assertions that make sure the function is being used correctly:
if strings.HasSuffix(origin, ".") {
panic(fmt.Errorf("origin (%s) is not supposed to end with a dot", origin))
Expand Down
47 changes: 47 additions & 0 deletions pkg/rtypecontrol/pave.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package rtypecontrol

import (
"fmt"
"strconv"
)

// PaveArgs converts each arg to its desired type, or returns an error if conversion fails or if the number of arguments is wrong.
// argTypes is a string where each rune specifies the desired type of the arg in the same position:
// 'i': uinet16 (will convert strings, truncate floats, etc)
// 's': Valid only if string.
func PaveArgs(args []any, argTypes string) error {
if len(args) != len(argTypes) {
return fmt.Errorf("wrong number of arguments. Expected %v, got %v", len(argTypes), len(args))
}

for i, at := range argTypes {
arg := args[i]
switch at {
case 'i': // uint16
if s, ok := arg.(string); ok { // Is this a string-encoded int?
ni, err := strconv.Atoi(s)
if err != nil {
return fmt.Errorf("value %q is not a number (uint16 wanted)", arg)
}
args[i] = uint16(ni)
} else if _, ok := arg.(float64); ok {
args[i] = uint16(arg.(float64))
} else if _, ok := arg.(uint16); ok {
args[i] = arg.(uint16)
} else if _, ok := arg.(int); ok {
args[i] = uint16(arg.(int))
} else {
return fmt.Errorf("value %q is type %T, expected uint16", arg, arg)
}

case 's':
if _, ok := arg.(string); ok {
args[i] = arg.(string)
} else {
args[i] = fmt.Sprintf("%v", arg)
}
}
}

return nil
}
4 changes: 2 additions & 2 deletions pkg/txtutil/txtcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ func txtDecode(s string) (string, error) {
/*
BNF:
txttarget := `""`` | item | item ` ` item*
txttarget := `""`` | item | item ` item*
item := quoteditem | unquoteditem
quoteditem := quote innertxt quote
quote := `"`
:= `"`
innertxt := (escaped | printable )*
escaped := `\\` | `\"`
printable := (printable ASCII chars)
Expand Down
2 changes: 1 addition & 1 deletion pkg/txtutil/txtutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func splitChunks(buf string, lim int) []string {
chunks = append(chunks, chunk)
}
if len(buf) > 0 {
chunks = append(chunks, buf[:])
chunks = append(chunks, buf)
}
return chunks
}
4 changes: 3 additions & 1 deletion providers/cloudns/cloudnsProvider.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,9 @@ func toRc(domain string, r *domainRecord) (*models.RecordConfig, error) {
case "TXT":
err = rc.SetTargetTXT(r.Target)
case "CNAME", "DNAME", "MX", "NS", "SRV", "ALIAS", "PTR":
err = rc.SetTarget(dnsutil.AddOrigin(r.Target+".", domain))
if err := rc.SetTarget(dnsutil.AddOrigin(r.Target+".", domain)); err != nil {
return nil, err
}
case "CAA":
caaFlag, _ := strconv.ParseUint(r.CaaFlag, 10, 8)
rc.CaaFlag = uint8(caaFlag)
Expand Down
9 changes: 8 additions & 1 deletion providers/hexonet/records.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"errors"
"fmt"
"math"
"strconv"
"strings"

Expand Down Expand Up @@ -206,7 +207,13 @@ func (n *HXClient) getRecords(domain string) ([]*HXRecord, error) {
record.Fqdn = spl[0] + "." + record.Fqdn
}
if record.Type == "MX" || record.Type == "SRV" {
prio, _ := strconv.ParseUint(spl[4], 10, 32)
prio, err := strconv.ParseUint(spl[4], 10, 32)
if err != nil {
return nil, fmt.Errorf("failed to parse priority: %w", err)
}
if prio > math.MaxUint16 {
return nil, fmt.Errorf("priority value exceeds uint16 maximum: %s", spl[4])
}
record.Priority = uint32(prio)
record.Answer = strings.Join(spl[5:], " ")
} else {
Expand Down

0 comments on commit b1b2a2a

Please sign in to comment.