mirror of
https://github.com/juanfont/headscale.git
synced 2026-09-14 12:32:02 +09:00
all: adopt strings, errors, and os helpers
This commit is contained in:
@@ -22,19 +22,12 @@ import (
|
||||
)
|
||||
|
||||
func loadDERPMapFromPath(path string) (*tailcfg.DERPMap, error) {
|
||||
derpFile, err := os.Open(path)
|
||||
b, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer derpFile.Close()
|
||||
|
||||
var derpMap tailcfg.DERPMap
|
||||
|
||||
b, err := io.ReadAll(derpFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = yaml.Unmarshal(b, &derpMap)
|
||||
|
||||
return &derpMap, err
|
||||
|
||||
+2
-2
@@ -420,7 +420,7 @@ func (api headscaleV1APIServer) SetApprovedRoutes(
|
||||
}
|
||||
|
||||
func validateTag(tag string) error {
|
||||
if strings.Index(tag, "tag:") != 0 {
|
||||
if !strings.HasPrefix(tag, "tag:") {
|
||||
return errors.New("tag must start with the string 'tag:'")
|
||||
}
|
||||
if strings.ToLower(tag) != tag {
|
||||
@@ -935,7 +935,7 @@ func (api headscaleV1APIServer) AuthReject(
|
||||
}
|
||||
|
||||
authReq.FinishAuth(types.AuthVerdict{
|
||||
Err: fmt.Errorf("auth request rejected"),
|
||||
Err: errors.New("auth request rejected"),
|
||||
})
|
||||
|
||||
return &v1.AuthRejectResponse{}, nil
|
||||
|
||||
@@ -5,7 +5,6 @@ import (
|
||||
"fmt"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -597,14 +596,7 @@ func groupSourcesByUser(
|
||||
// filterRuleKey generates a unique key for merging based on [tailcfg.FilterRule.SrcIPs]
|
||||
// and [tailcfg.FilterRule.IPProto].
|
||||
func filterRuleKey(rule tailcfg.FilterRule) string {
|
||||
srcKey := strings.Join(rule.SrcIPs, ",")
|
||||
|
||||
protoStrs := make([]string, len(rule.IPProto))
|
||||
for i, p := range rule.IPProto {
|
||||
protoStrs[i] = strconv.Itoa(p)
|
||||
}
|
||||
|
||||
return srcKey + "|" + strings.Join(protoStrs, ",")
|
||||
return fmt.Sprintf("%s|%v", strings.Join(rule.SrcIPs, ","), rule.IPProto)
|
||||
}
|
||||
|
||||
// mergeFilterRules merges rules with identical [tailcfg.FilterRule.SrcIPs] and
|
||||
|
||||
Reference in New Issue
Block a user