forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_context.go
58 lines (44 loc) · 1.21 KB
/
session_context.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
48
49
50
51
52
53
54
55
56
57
58
package cmd
import (
boshsys "github.com/cloudfoundry/bosh-utils/system"
cmdconf "github.com/cloudfoundry/bosh-cli/cmd/config"
)
// SessionContextImpl prefers options over config values
type SessionContextImpl struct {
opts BoshOpts
config cmdconf.Config
fs boshsys.FileSystem
}
func NewSessionContextImpl(
opts BoshOpts,
config cmdconf.Config,
fs boshsys.FileSystem,
) *SessionContextImpl {
return &SessionContextImpl{opts: opts, config: config, fs: fs}
}
func (c SessionContextImpl) Environment() string {
return c.config.ResolveEnvironment(c.opts.EnvironmentOpt)
}
func (c SessionContextImpl) Credentials() cmdconf.Creds {
creds := c.config.Credentials(c.Environment())
if len(c.opts.UsernameOpt) > 0 {
creds.Username = c.opts.UsernameOpt
}
if len(c.opts.PasswordOpt) > 0 {
creds.Password = c.opts.PasswordOpt
}
if len(c.opts.UAAClientOpt) > 0 {
creds.Client = c.opts.UAAClientOpt
creds.ClientSecret = c.opts.UAAClientSecretOpt
}
return creds
}
func (c SessionContextImpl) CACert() string {
if len(c.opts.CACertOpt.Content) > 0 {
return c.opts.CACertOpt.Content
}
return c.config.CACert(c.Environment())
}
func (c SessionContextImpl) Deployment() string {
return c.opts.DeploymentOpt
}