forked from cloudfoundry/bosh-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
session_context.go
50 lines (38 loc) · 1.05 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
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.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
}