mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-19 23:11:25 +02:00
refactor(docker): update TLS config validation to require both CertFile and KeyFile exists or both empty
This commit is contained in:
@@ -27,8 +27,8 @@ type DockerProviderConfigDetailed struct {
|
|||||||
|
|
||||||
type DockerTLSConfig struct {
|
type DockerTLSConfig struct {
|
||||||
CAFile string `json:"ca_file,omitempty" validate:"required"`
|
CAFile string `json:"ca_file,omitempty" validate:"required"`
|
||||||
CertFile string `json:"cert_file,omitempty" validate:"required"`
|
CertFile string `json:"cert_file,omitempty" validate:"required_with=KeyFile"`
|
||||||
KeyFile string `json:"key_file,omitempty" validate:"required"`
|
KeyFile string `json:"key_file,omitempty" validate:"required_with=CertFile"`
|
||||||
} // @name DockerTLSConfig
|
} // @name DockerTLSConfig
|
||||||
|
|
||||||
func (cfg *DockerProviderConfig) MarshalJSON() ([]byte, error) {
|
func (cfg *DockerProviderConfig) MarshalJSON() ([]byte, error) {
|
||||||
|
|||||||
@@ -98,13 +98,29 @@ func TestDockerProviderConfigValidation(t *testing.T) {
|
|||||||
cert_file: /etc/ssl/cert.crt
|
cert_file: /etc/ssl/cert.crt
|
||||||
key_file: /etc/ssl/key.crt
|
key_file: /etc/ssl/key.crt
|
||||||
`, wantErr: false},
|
`, wantErr: false},
|
||||||
{name: "invalid tls (missing cert file and key file)", yamlStr: `
|
{name: "valid tls (only ca file)", yamlStr: `
|
||||||
test:
|
test:
|
||||||
scheme: tls
|
scheme: tls
|
||||||
host: localhost
|
host: localhost
|
||||||
port: 2375
|
port: 2375
|
||||||
tls:
|
tls:
|
||||||
ca_file: /etc/ssl/ca.crt
|
ca_file: /etc/ssl/ca.crt
|
||||||
|
`, wantErr: false},
|
||||||
|
{name: "invalid tls (missing cert file)", yamlStr: `
|
||||||
|
test:
|
||||||
|
scheme: tls
|
||||||
|
host: localhost
|
||||||
|
port: 2375
|
||||||
|
tls:
|
||||||
|
key_file: /etc/ssl/key.crt
|
||||||
|
`, wantErr: true},
|
||||||
|
{name: "invalid tls (missing key file)", yamlStr: `
|
||||||
|
test:
|
||||||
|
scheme: tls
|
||||||
|
host: localhost
|
||||||
|
port: 2375
|
||||||
|
tls:
|
||||||
|
cert_file: /etc/ssl/cert.crt
|
||||||
`, wantErr: true},
|
`, wantErr: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user