forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agent_client_factory.go
46 lines (37 loc) · 1.19 KB
/
agent_client_factory.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
package http
//go:generate mockgen -source=agent_client_factory.go -package=mocks -destination=mocks/mocks.go
import (
"time"
"github.com/cloudfoundry/bosh-agent/agentclient"
"github.com/cloudfoundry/bosh-utils/crypto"
"github.com/cloudfoundry/bosh-utils/httpclient"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
type AgentClientFactory interface {
NewAgentClient(directorID, mbusURL, caCert string) (agentclient.AgentClient, error)
}
type agentClientFactory struct {
getTaskDelay time.Duration
logger boshlog.Logger
}
func NewAgentClientFactory(
getTaskDelay time.Duration,
logger boshlog.Logger,
) AgentClientFactory {
return &agentClientFactory{
getTaskDelay: getTaskDelay,
logger: logger,
}
}
func (f *agentClientFactory) NewAgentClient(directorID, mbusURL, caCert string) (agentclient.AgentClient, error) {
client := httpclient.DefaultClient
if caCert != "" {
caCertPool, err := crypto.CertPoolFromPEM([]byte(caCert))
if err != nil {
return nil, err
}
client = httpclient.CreateDefaultClient(caCertPool)
}
httpClient := httpclient.NewHTTPClient(client, f.logger)
return NewAgentClient(mbusURL, directorID, f.getTaskDelay, 10, httpClient, f.logger), nil
}