|
| 1 | +// |
| 2 | +// Copyright (C) 2024 IOTech Ltd |
| 3 | +// |
| 4 | +// SPDX-License-Identifier: Apache-2.0 |
| 5 | + |
| 6 | +package config |
| 7 | + |
| 8 | +import ( |
| 9 | + bootstrapConfig "github.com/edgexfoundry/go-mod-bootstrap/v3/config" |
| 10 | +) |
| 11 | + |
| 12 | +// ConfigurationStruct contains the configuration properties for the Support Cron Scheduler Service |
| 13 | +type ConfigurationStruct struct { |
| 14 | + Writable WritableInfo |
| 15 | + Database bootstrapConfig.Database |
| 16 | + Registry bootstrapConfig.RegistryInfo |
| 17 | + Service bootstrapConfig.ServiceInfo |
| 18 | + Clients bootstrapConfig.ClientsCollection |
| 19 | + MessageBus bootstrapConfig.MessageBusInfo |
| 20 | +} |
| 21 | + |
| 22 | +type WritableInfo struct { |
| 23 | + LogLevel string |
| 24 | + InsecureSecrets bootstrapConfig.InsecureSecrets |
| 25 | + Telemetry bootstrapConfig.TelemetryInfo |
| 26 | +} |
| 27 | + |
| 28 | +// UpdateFromRaw converts configuration received from the registry to a service-specific configuration struct which is |
| 29 | +// then used to overwrite the service's existing configuration struct. |
| 30 | +func (c *ConfigurationStruct) UpdateFromRaw(rawConfig any) bool { |
| 31 | + configuration, ok := rawConfig.(*ConfigurationStruct) |
| 32 | + if ok { |
| 33 | + *c = *configuration |
| 34 | + } |
| 35 | + return ok |
| 36 | +} |
| 37 | + |
| 38 | +// EmptyWritablePtr returns a pointer to a service-specific empty WritableInfo struct. It is used by the bootstrap to |
| 39 | +// provide the appropriate structure to registry.Client's WatchForChanges(). |
| 40 | +func (c *ConfigurationStruct) EmptyWritablePtr() any { |
| 41 | + return &WritableInfo{} |
| 42 | +} |
| 43 | + |
| 44 | +// GetWritablePtr returns pointer to the writable section |
| 45 | +func (c *ConfigurationStruct) GetWritablePtr() any { |
| 46 | + return &c.Writable |
| 47 | +} |
| 48 | + |
| 49 | +// UpdateWritableFromRaw converts configuration received from the registry to a service-specific WritableInfo struct |
| 50 | +// which is then used to overwrite the service's existing configuration's WritableInfo struct. |
| 51 | +func (c *ConfigurationStruct) UpdateWritableFromRaw(rawWritable any) bool { |
| 52 | + writable, ok := rawWritable.(*WritableInfo) |
| 53 | + if ok { |
| 54 | + c.Writable = *writable |
| 55 | + } |
| 56 | + return ok |
| 57 | +} |
| 58 | + |
| 59 | +// GetBootstrap returns the configuration elements required by the bootstrap. Currently, a copy of the configuration |
| 60 | +// data is returned. This is intended to be temporary -- since ConfigurationStruct drives the configuration.yaml's |
| 61 | +// structure -- until we can make backwards-breaking configuration.yaml changes (which would consolidate these fields |
| 62 | +// into an bootstrapConfig.BootstrapConfiguration struct contained within ConfigurationStruct). |
| 63 | +func (c *ConfigurationStruct) GetBootstrap() bootstrapConfig.BootstrapConfiguration { |
| 64 | + // temporary until we can make backwards-breaking configuration.yaml change |
| 65 | + return bootstrapConfig.BootstrapConfiguration{ |
| 66 | + Clients: &c.Clients, |
| 67 | + Database: &c.Database, |
| 68 | + MessageBus: &c.MessageBus, |
| 69 | + Registry: &c.Registry, |
| 70 | + Service: &c.Service, |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +// GetLogLevel returns the current ConfigurationStruct's log level. |
| 75 | +func (c *ConfigurationStruct) GetLogLevel() string { |
| 76 | + return c.Writable.LogLevel |
| 77 | +} |
| 78 | + |
| 79 | +// GetRegistryInfo returns the RegistryInfo from the ConfigurationStruct. |
| 80 | +func (c *ConfigurationStruct) GetRegistryInfo() bootstrapConfig.RegistryInfo { |
| 81 | + return c.Registry |
| 82 | +} |
| 83 | + |
| 84 | +// GetDatabaseInfo returns a database information map. |
| 85 | +func (c *ConfigurationStruct) GetDatabaseInfo() bootstrapConfig.Database { |
| 86 | + return c.Database |
| 87 | +} |
| 88 | + |
| 89 | +// GetInsecureSecrets returns the service's InsecureSecrets. |
| 90 | +func (c *ConfigurationStruct) GetInsecureSecrets() bootstrapConfig.InsecureSecrets { |
| 91 | + return c.Writable.InsecureSecrets |
| 92 | +} |
| 93 | + |
| 94 | +// GetTelemetryInfo returns the service's Telemetry settings. |
| 95 | +func (c *ConfigurationStruct) GetTelemetryInfo() *bootstrapConfig.TelemetryInfo { |
| 96 | + return &c.Writable.Telemetry |
| 97 | +} |
0 commit comments