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