forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registry_provider.go
55 lines (47 loc) · 1.47 KB
/
registry_provider.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 infrastructure
import (
"strings"
boshplat "github.com/cloudfoundry/bosh-agent/platform"
bosherr "github.com/cloudfoundry/bosh-utils/errors"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
boshsys "github.com/cloudfoundry/bosh-utils/system"
)
type RegistryProvider interface {
GetRegistry() (Registry, error)
}
type registryProvider struct {
metadataService MetadataService
useServerName bool
platform boshplat.Platform
fs boshsys.FileSystem
logTag string
logger boshlog.Logger
}
func NewRegistryProvider(
metadataService MetadataService,
platform boshplat.Platform,
useServerName bool,
fs boshsys.FileSystem,
logger boshlog.Logger,
) RegistryProvider {
return ®istryProvider{
metadataService: metadataService,
platform: platform,
useServerName: useServerName,
fs: fs,
logTag: "registryProvider",
logger: logger,
}
}
func (p *registryProvider) GetRegistry() (Registry, error) {
registryEndpoint, err := p.metadataService.GetRegistryEndpoint()
if err != nil {
return nil, bosherr.WrapError(err, "Getting registry endpoint")
}
if strings.HasPrefix(registryEndpoint, "http") {
p.logger.Debug(p.logTag, "Using http registry at %s", registryEndpoint)
return NewHTTPRegistry(p.metadataService, p.platform, p.useServerName, p.logger), nil
}
p.logger.Debug(p.logTag, "Using file registry at %s", registryEndpoint)
return NewFileRegistry(registryEndpoint, p.fs), nil
}