forked from digitalocean/atc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth_flags.go
39 lines (32 loc) · 984 Bytes
/
auth_flags.go
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
28
29
30
31
32
33
34
35
36
37
38
39
package atc
import (
"errors"
multierror "github.com/hashicorp/go-multierror"
)
type AuthFlags struct {
NoAuth bool `long:"no-really-i-dont-want-any-auth" description:"Ignore warnings about not configuring auth"`
BasicAuth BasicAuthFlag `group:"Basic Authentication" namespace:"basic-auth"`
}
type BasicAuthFlag struct {
Username string `long:"username" description:"Username to use for basic auth."`
Password string `long:"password" description:"Password to use for basic auth."`
}
func (auth *BasicAuthFlag) IsConfigured() bool {
return auth.Username != "" || auth.Password != ""
}
func (auth *BasicAuthFlag) Validate() error {
var errs *multierror.Error
if auth.Username == "" {
errs = multierror.Append(
errs,
errors.New("must specify --basic-auth-username to use basic auth."),
)
}
if auth.Password == "" {
errs = multierror.Append(
errs,
errors.New("must specify --basic-auth-password to use basic auth."),
)
}
return errs.ErrorOrNil()
}