mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-11 22:30:47 +01:00
refactor(docker): accept unix and ssh scheme for providers
This commit is contained in:
@@ -20,7 +20,7 @@ type DockerProviderConfig struct {
|
||||
} // @name DockerProviderConfig
|
||||
|
||||
type DockerProviderConfigDetailed struct {
|
||||
Scheme string `json:"scheme,omitempty" validate:"required,oneof=http https tcp tls"`
|
||||
Scheme string `json:"scheme,omitempty" validate:"required,oneof=http https tcp tls unix ssh"`
|
||||
Host string `json:"host,omitempty" validate:"required,hostname|ip"`
|
||||
Port int `json:"port,omitempty" validate:"required,min=1,max=65535"`
|
||||
TLS *DockerTLSConfig `json:"tls" validate:"omitempty"`
|
||||
@@ -49,11 +49,13 @@ func (cfg *DockerProviderConfig) Parse(value string) error {
|
||||
|
||||
switch u.Scheme {
|
||||
case "http", "https", "tcp", "tls":
|
||||
cfg.URL = u.String()
|
||||
case "unix", "ssh":
|
||||
cfg.URL = value
|
||||
default:
|
||||
return fmt.Errorf("invalid scheme: %s", u.Scheme)
|
||||
}
|
||||
|
||||
cfg.URL = u.String()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,12 @@ func TestDockerProviderConfigValidation(t *testing.T) {
|
||||
yamlStr string
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "valid url", yamlStr: "test: http://localhost:2375", wantErr: false},
|
||||
{name: "valid url (http)", yamlStr: "test: http://localhost:2375", wantErr: false},
|
||||
{name: "valid url (https)", yamlStr: "test: https://localhost:2375", wantErr: false},
|
||||
{name: "valid url (tcp)", yamlStr: "test: tcp://localhost:2375", wantErr: false},
|
||||
{name: "valid url (tls)", yamlStr: "test: tls://localhost:2375", wantErr: false},
|
||||
{name: "valid url (unix)", yamlStr: "test: unix:///var/run/docker.sock", wantErr: false},
|
||||
{name: "valid url (ssh)", yamlStr: "test: ssh://localhost:2375", wantErr: false},
|
||||
{name: "invalid url", yamlStr: "test: ftp://localhost/2375", wantErr: true},
|
||||
{name: "valid scheme", yamlStr: `
|
||||
test:
|
||||
|
||||
Reference in New Issue
Block a user