-
Notifications
You must be signed in to change notification settings - Fork 174
Expand file tree
/
Copy pathbasic.go
More file actions
32 lines (26 loc) · 860 Bytes
/
basic.go
File metadata and controls
32 lines (26 loc) · 860 Bytes
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
package auth
import (
"github.com/stackrox/rox/pkg/errox"
"github.com/stackrox/rox/pkg/grpc/client/authn/basic"
"github.com/stackrox/rox/roxctl/common/flags"
"google.golang.org/grpc/credentials"
)
type basicMethod struct{}
var (
_ Method = (*basicMethod)(nil)
)
// BasicAuth provides an auth.Method for basic authentication.
// It will use the inputs from the --password flag or the ROX_ADMIN_PASSWORD environment variable.
func BasicAuth() Method {
return &basicMethod{}
}
func (b basicMethod) Type() string {
return "basic auth"
}
func (b basicMethod) GetCredentials(_ string) (credentials.PerRPCCredentials, error) {
password := flags.Password()
if password == "" {
return nil, errox.InvalidArgs.New("no password specified either via flag or environment variable")
}
return basic.PerRPCCredentials(basic.DefaultUsername, password), nil
}