feat(ax): expose normalization helpers for agent usage
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
5d002f8192
commit
f6afe97b35
2 changed files with 32 additions and 0 deletions
16
service.go
16
service.go
|
|
@ -1040,6 +1040,14 @@ func normalizeIP(ip string) string {
|
|||
return parsed.String()
|
||||
}
|
||||
|
||||
// NormalizeIP normalizes a raw IP string into its canonical textual form.
|
||||
//
|
||||
// normalized := dns.NormalizeIP("010.000.000.001")
|
||||
// // normalized == "10.0.0.1"
|
||||
func NormalizeIP(ip string) string {
|
||||
return normalizeIP(ip)
|
||||
}
|
||||
|
||||
func computeTreeRoot(records map[string]NameRecords) string {
|
||||
names := make([]string, 0, len(records))
|
||||
for name := range records {
|
||||
|
|
@ -1183,6 +1191,14 @@ func normalizeName(name string) string {
|
|||
return trimmed
|
||||
}
|
||||
|
||||
// NormalizeName normalizes a raw DNS name for cache lookups and action handling.
|
||||
//
|
||||
// normalized := dns.NormalizeName("Gateway.Charon.lthn.")
|
||||
// // normalized == "gateway.charon.lthn"
|
||||
func NormalizeName(name string) string {
|
||||
return normalizeName(name)
|
||||
}
|
||||
|
||||
// String returns a compact debug representation of the service.
|
||||
//
|
||||
// fmt.Println(service)
|
||||
|
|
|
|||
|
|
@ -3016,6 +3016,22 @@ func TestStringActionValueRejectsWhitespaceOnlyArgument(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNormalizeNameAndNormalizeIPArePublicWrappers(t *testing.T) {
|
||||
normalizedName := NormalizeName(" Gateway.Charon.lthn. ")
|
||||
if normalizedName != "gateway.charon.lthn" {
|
||||
t.Fatalf("expected normalized DNS name, got %q", normalizedName)
|
||||
}
|
||||
|
||||
normalizedIP := NormalizeIP(" 2001:0DB8::0001 ")
|
||||
if normalizedIP != "2001:db8::1" {
|
||||
t.Fatalf("expected normalized IP, got %q", normalizedIP)
|
||||
}
|
||||
|
||||
if NormalizeIP("invalid") != "" {
|
||||
t.Fatal("expected invalid IP to normalize to empty string")
|
||||
}
|
||||
}
|
||||
|
||||
func TestIntActionValueRejectsNonIntegerFloat(t *testing.T) {
|
||||
_, err := intActionValue(map[string]any{
|
||||
actionArgPort: 53.9,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue