aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/aws/smithy-go/transport/http/host.go
diff options
context:
space:
mode:
authorvitalyisaev <vitalyisaev@ydb.tech>2023-12-12 21:55:07 +0300
committervitalyisaev <vitalyisaev@ydb.tech>2023-12-12 22:25:10 +0300
commit4967f99474a4040ba150eb04995de06342252718 (patch)
treec9c118836513a8fab6e9fcfb25be5d404338bca7 /vendor/github.com/aws/smithy-go/transport/http/host.go
parent2ce9cccb9b0bdd4cd7a3491dc5cbf8687cda51de (diff)
downloadydb-4967f99474a4040ba150eb04995de06342252718.tar.gz
YQ Connector: prepare code base for S3 integration
1. Кодовая база Коннектора переписана с помощью Go дженериков так, чтобы добавление нового источника данных (в частности S3 + csv) максимально переиспользовало имеющийся код (чтобы сохранялась логика нарезания на блоки данных, учёт трафика и пр.) 2. API Connector расширено для работы с S3, но ещё пока не протестировано.
Diffstat (limited to 'vendor/github.com/aws/smithy-go/transport/http/host.go')
-rw-r--r--vendor/github.com/aws/smithy-go/transport/http/host.go89
1 files changed, 89 insertions, 0 deletions
diff --git a/vendor/github.com/aws/smithy-go/transport/http/host.go b/vendor/github.com/aws/smithy-go/transport/http/host.go
new file mode 100644
index 0000000000..6b290fec03
--- /dev/null
+++ b/vendor/github.com/aws/smithy-go/transport/http/host.go
@@ -0,0 +1,89 @@
+package http
+
+import (
+ "fmt"
+ "net"
+ "strconv"
+ "strings"
+)
+
+// ValidateEndpointHost validates that the host string passed in is a valid RFC
+// 3986 host. Returns error if the host is not valid.
+func ValidateEndpointHost(host string) error {
+ var errors strings.Builder
+ var hostname string
+ var port string
+ var err error
+
+ if strings.Contains(host, ":") {
+ hostname, port, err = net.SplitHostPort(host)
+ if err != nil {
+ errors.WriteString(fmt.Sprintf("\n endpoint %v, failed to parse, got ", host))
+ errors.WriteString(err.Error())
+ }
+
+ if !ValidPortNumber(port) {
+ errors.WriteString(fmt.Sprintf("port number should be in range [0-65535], got %v", port))
+ }
+ } else {
+ hostname = host
+ }
+
+ labels := strings.Split(hostname, ".")
+ for i, label := range labels {
+ if i == len(labels)-1 && len(label) == 0 {
+ // Allow trailing dot for FQDN hosts.
+ continue
+ }
+
+ if !ValidHostLabel(label) {
+ errors.WriteString("\nendpoint host domain labels must match \"[a-zA-Z0-9-]{1,63}\", but found: ")
+ errors.WriteString(label)
+ }
+ }
+
+ if len(hostname) == 0 && len(port) != 0 {
+ errors.WriteString("\nendpoint host with port must not be empty")
+ }
+
+ if len(hostname) > 255 {
+ errors.WriteString(fmt.Sprintf("\nendpoint host must be less than 255 characters, but was %d", len(hostname)))
+ }
+
+ if len(errors.String()) > 0 {
+ return fmt.Errorf("invalid endpoint host%s", errors.String())
+ }
+ return nil
+}
+
+// ValidPortNumber returns whether the port is valid RFC 3986 port.
+func ValidPortNumber(port string) bool {
+ i, err := strconv.Atoi(port)
+ if err != nil {
+ return false
+ }
+
+ if i < 0 || i > 65535 {
+ return false
+ }
+ return true
+}
+
+// ValidHostLabel returns whether the label is a valid RFC 3986 host abel.
+func ValidHostLabel(label string) bool {
+ if l := len(label); l == 0 || l > 63 {
+ return false
+ }
+ for _, r := range label {
+ switch {
+ case r >= '0' && r <= '9':
+ case r >= 'A' && r <= 'Z':
+ case r >= 'a' && r <= 'z':
+ case r == '-':
+ default:
+ return false
+ }
+ }
+
+ return true
+}