-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Expand file tree
/
Copy pathclean.go
More file actions
92 lines (79 loc) · 2.23 KB
/
Copy pathclean.go
File metadata and controls
92 lines (79 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright IBM Corp. 2014, 2026
// SPDX-License-Identifier: MPL-2.0
package route53
import (
"strings"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/hashicorp/terraform-provider-aws/internal/dns"
)
// cleanDelegationSetID is used to remove the leading "/delegationset/" from a
// delegation set ID
func cleanDelegationSetID(id string) string {
return strings.TrimPrefix(id, "/delegationset/")
}
// cleanZoneID is used to remove the leading "/hostedzone/" from a hosted zone ID
func cleanZoneID(id string) string {
return strings.TrimPrefix(id, "/hostedzone/")
}
// normalizeAliasDomainName is a wrapper around the shared dns package normalization
// function which handles interface types for Plugin SDK V2 based resources
//
// The only difference between this helper and normalizeDomainName is that the single
// dot (".") domain name is not passed through as-is.
func normalizeAliasDomainName(v any) string {
var s string
switch v := v.(type) {
case *string:
s = aws.ToString(v)
case string:
s = v
default:
return ""
}
return dns.Normalize(strings.TrimSuffix(s, "."))
}
// normalizeDomainName is a wrapper around the shared dns package normalization
// function which handles interface values from Plugin SDK V2 based resources
func normalizeDomainName(v any) string {
var s string
switch v := v.(type) {
case *string:
s = aws.ToString(v)
case string:
s = v
default:
return ""
}
return dns.Normalize(s)
}
// fqdn appends a single dot (".") to the input string if necessary
func fqdn(name string) string {
if n := len(name); n == 0 || name[n-1] == '.' {
return name
} else {
return name + "."
}
}
// denormalizeDomainName removes escaping for the "*" character in the leftmost label of a domain name,
// and removes the trailing dot if present.
// The single dot (".") domain name is passed through as-is.
func denormalizeDomainName(v any) string {
switch v := v.(type) {
case *string:
return denormalizeDomainNameImpl(aws.ToString(v))
case string:
return denormalizeDomainNameImpl(v)
default:
return ""
}
}
func denormalizeDomainNameImpl(s string) string {
if s == "" || s == "." {
return s
}
s = strings.TrimSuffix(s, ".")
if after, ok := strings.CutPrefix(s, `\052.`); ok {
s = `*.` + after
}
return s
}