-
Notifications
You must be signed in to change notification settings - Fork 162
/
log_in.go
47 lines (39 loc) · 862 Bytes
/
log_in.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
40
41
42
43
44
45
46
47
package cmd
import (
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshdir "github.com/cloudfoundry/bosh-cli/director"
)
//go:generate counterfeiter . LoginStrategy
type LoginStrategy interface {
Try() error
}
type LogInCmd struct {
basicStrategy LoginStrategy
uaaStrategy LoginStrategy
director boshdir.Director
}
func NewLogInCmd(
basicStrategy LoginStrategy,
uaaStrategy LoginStrategy,
director boshdir.Director,
) LogInCmd {
return LogInCmd{
basicStrategy: basicStrategy,
uaaStrategy: uaaStrategy,
director: director,
}
}
func (c LogInCmd) Run() error {
info, err := c.director.Info()
if err != nil {
return err
}
switch info.Auth.Type {
case "uaa":
return c.uaaStrategy.Try()
case "basic":
return c.basicStrategy.Try()
default:
return bosherr.Errorf("Unknown auth type '%s'", info.Auth.Type)
}
}