/
service.go
53 lines (41 loc) · 1.07 KB
/
service.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
package client
import (
boshsys "github.com/cloudfoundry/bosh-utils/system"
"github.com/dpb587/ssoca/client"
"github.com/dpb587/ssoca/httpclient"
"github.com/dpb587/ssoca/client/service"
svc "github.com/dpb587/ssoca/service/file"
svchttpclient "github.com/dpb587/ssoca/service/file/httpclient"
)
type Service struct {
svc.ServiceType
name string
runtime client.Runtime
fs boshsys.FileSystem
cmdRunner boshsys.CmdRunner
}
var _ service.Service = Service{}
func NewService(name string, runtime client.Runtime, fs boshsys.FileSystem, cmdRunner boshsys.CmdRunner) *Service {
return &Service{
name: name,
runtime: runtime,
fs: fs,
cmdRunner: cmdRunner,
}
}
func (s Service) Name() string {
return s.name
}
func (s Service) GetClient(skipAuthRetry bool) (svchttpclient.Client, error) {
var client httpclient.Client
var err error
if skipAuthRetry {
client, err = s.runtime.GetClient()
} else {
client, err = s.runtime.GetAuthInterceptClient()
}
if err != nil {
return nil, err
}
return svchttpclient.New(client, s.name)
}