Skip to content

Commit

Permalink
Basic Authentication - #399
Browse files Browse the repository at this point in the history
Code review points part #4.

Fix validation logic.

See <#399> for further information.
  • Loading branch information
Mohamed Bana authored and mbana committed Jun 15, 2022
1 parent d789f27 commit 193901b
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions pkg/options/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,31 @@ type AuthOptions struct {
AuthUpstream AuthUpstream `json:"auth-upstream,omitempty" yaml:"auth-upstream,omitempty"`
}

func (o AuthOptions) Validate() error {
return validation.ValidateStruct(&o,
validation.Field(&o.Scheme, validation.In("basic")),
validation.Field(&o.AuthUpstream),
)
}

type AuthUpstream struct {
Host AuthUpstreamHost `json:"host,omitempty" yaml:"host,omitempty"`
}

func (o AuthUpstream) Validate() error {
return validation.ValidateStruct(&o,
validation.Field(&o.Host),
)
}

type AuthUpstreamHost struct {
Hostname string `json:"hostname,omitempty" yaml:"hostname,omitempty"`
Port uint32 `json:"port,omitempty" yaml:"port,omitempty"`
}

func (o AuthOptions) Validate() error {
// Nothing to validate yet
// return nil
func (o AuthUpstreamHost) Validate() error {
return validation.ValidateStruct(&o,
validation.Field(&o.Scheme, validation.In("basic")),
validation.Field(&o.AuthUpstream.Host.Hostname, is.Host),
validation.Field(&o.AuthUpstream.Host.Port, is.Port),
validation.Field(&o.Hostname, is.Host),
// validation.Field(&o.Port, is.Port), // Do not attempt to validate, otherwise this error, `port: must be either a string or byte slice` occurs.
)
}

0 comments on commit 193901b

Please sign in to comment.