forked from cloudfoundry/bosh-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
/
complex_settings_source.go
53 lines (42 loc) · 1.34 KB
/
complex_settings_source.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 infrastructure
import (
boshsettings "github.com/cloudfoundry/bosh-agent/settings"
boshlog "github.com/cloudfoundry/bosh-utils/logger"
)
type ComplexSettingsSource struct {
metadataService MetadataService
registryProvider RegistryProvider
logTag string
logger boshlog.Logger
}
func NewComplexSettingsSource(
metadataService MetadataService,
registryProvider RegistryProvider,
logger boshlog.Logger,
) ComplexSettingsSource {
return ComplexSettingsSource{
metadataService: metadataService,
registryProvider: registryProvider,
logTag: "ComplexSettingsSource",
logger: logger,
}
}
func (s ComplexSettingsSource) PublicSSHKeyForUsername(string) (string, error) {
return s.metadataService.GetPublicKey()
}
func (s ComplexSettingsSource) Settings() (boshsettings.Settings, error) {
settings, err := s.GetMetadataService().GetSettings()
if err == nil && settings.AgentID != "" {
s.logger.Debug(s.logTag, "Got settings from metadata service, not contacting registry.")
return settings, nil
}
s.logger.Debug(s.logTag, "Unable to get settings from metadata service, falling back to registry.")
registry, err := s.registryProvider.GetRegistry()
if err != nil {
return boshsettings.Settings{}, err
}
return registry.GetSettings()
}
func (s ComplexSettingsSource) GetMetadataService() MetadataService {
return s.metadataService
}