-
Notifications
You must be signed in to change notification settings - Fork 162
/
session_context.go
55 lines (42 loc) · 1.17 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
package cmd
import (
boshsys "github.com/cloudfoundry/bosh-utils/system"
cmdconf "github.com/cloudfoundry/bosh-cli/v7/cmd/config"
. "github.com/cloudfoundry/bosh-cli/v7/cmd/opts"
)
// 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) Config() cmdconf.Config {
return c.config
}
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.ClientOpt) > 0 {
creds.Client = c.opts.ClientOpt
creds.ClientSecret = c.opts.ClientSecretOpt
}
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
}