File: endpoint.go

package info (click to toggle)
docker-buildx 0.13.1%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,356 kB
  • sloc: sh: 299; makefile: 87
file content (27 lines) | stat: -rw-r--r-- 539 bytes parent folder | download
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
package remote

import (
	"net/url"

	"github.com/pkg/errors"
)

var schemes = map[string]struct{}{
	"tcp":              {},
	"unix":             {},
	"ssh":              {},
	"docker-container": {},
	"kube-pod":         {},
	"npipe":            {},
}

func IsValidEndpoint(ep string) error {
	endpoint, err := url.Parse(ep)
	if err != nil {
		return errors.Wrapf(err, "failed to parse endpoint %s", ep)
	}
	if _, ok := schemes[endpoint.Scheme]; !ok {
		return errors.Errorf("unrecognized url scheme %s", endpoint.Scheme)
	}
	return nil
}