forked from edgexfoundry/device-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
89 lines (79 loc) · 3.5 KB
/
config.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// -*- Mode: Go; indent-tabs-mode: t -*-
//
// Copyright (C) 2020 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0
package common
import (
bootstrapConfig "github.com/edgexfoundry/go-mod-bootstrap/config"
)
// ConfigurationStruct contains the configuration properties for the device service.
type ConfigurationStruct struct {
// WritableInfo contains configuration settings that can be changed in the Registry .
Writable WritableInfo
// Clients is a map of services used by a DS.
Clients map[string]bootstrapConfig.ClientInfo
// Registry contains registry-specific settings.
Registry bootstrapConfig.RegistryInfo
// Service contains DeviceService-specific settings.
Service ServiceInfo
// Device contains device-specific configuration settings.
Device DeviceInfo
// DeviceList is the list of pre-define Devices
DeviceList []DeviceConfig `consul:"-"`
// Driver is a string map contains customized configuration for the protocol driver implemented based on Device SDK
Driver map[string]string
// SecretStore contain information for connecting to the secure SecretStore (Vault) to retrieve or store secrets
SecretStore bootstrapConfig.SecretStoreInfo
}
// UpdateFromRaw converts configuration received from the registry to a service-specific configuration struct which is
// then used to overwrite the service's existing configuration struct.
func (c *ConfigurationStruct) UpdateFromRaw(rawConfig interface{}) bool {
configuration, ok := rawConfig.(*ConfigurationStruct)
if ok {
// Check that information was successfully read from Registry
if configuration.Service.Port == 0 {
return false
}
*c = *configuration
}
return ok
}
// EmptyWritablePtr returns a pointer to a service-specific empty WritableInfo struct. It is used by the bootstrap to
// provide the appropriate structure to registry.Client's WatchForChanges().
func (c *ConfigurationStruct) EmptyWritablePtr() interface{} {
return &WritableInfo{}
}
// UpdateWritableFromRaw converts configuration received from the registry to a service-specific WritableInfo struct
// which is then used to overwrite the service's existing configuration's WritableInfo struct.
func (c *ConfigurationStruct) UpdateWritableFromRaw(rawWritable interface{}) bool {
writable, ok := rawWritable.(*WritableInfo)
if ok {
c.Writable = *writable
}
return ok
}
// GetBootstrap returns the configuration elements required by the bootstrap. Currently, a copy of the configuration
// data is returned. This is intended to be temporary -- since ConfigurationStruct drives the configuration.toml's
// structure -- until we can make backwards-breaking configuration.toml changes (which would consolidate these fields
// into an bootstrapConfig.BootstrapConfiguration struct contained within ConfigurationStruct).
func (c *ConfigurationStruct) GetBootstrap() bootstrapConfig.BootstrapConfiguration {
return bootstrapConfig.BootstrapConfiguration{
Clients: c.Clients,
Service: c.Service.GetBootstrapServiceInfo(),
Registry: c.Registry,
SecretStore: c.SecretStore,
}
}
// GetLogLevel returns the current ConfigurationStruct's log level.
func (c *ConfigurationStruct) GetLogLevel() string {
return c.Writable.LogLevel
}
// GetRegistryInfo gets the config.RegistryInfo field from the ConfigurationStruct.
func (c *ConfigurationStruct) GetRegistryInfo() bootstrapConfig.RegistryInfo {
return c.Registry
}
// GetInsecureSecrets returns the service's InsecureSecrets.
func (c *ConfigurationStruct) GetInsecureSecrets() bootstrapConfig.InsecureSecrets {
return c.Writable.InsecureSecrets
}