From ff659b648c99ee78b2d635bd69f36e3fa83205c9 Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Tue, 5 Dec 2023 17:09:22 +0100 Subject: [PATCH] reloader --- deployment/deploy-yml.tmpl | 2 ++ src/udi/handlers/sve/sve.go | 29 ++++++++++++++++++----------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/deployment/deploy-yml.tmpl b/deployment/deploy-yml.tmpl index 3160d11..3775cd6 100644 --- a/deployment/deploy-yml.tmpl +++ b/deployment/deploy-yml.tmpl @@ -18,6 +18,8 @@ metadata: namespace: udi labels: app: udi + annotations: + secret.reloader.stakater.com/reload: "udi-conf,udi-db-cred" spec: replicas: 1 selector: diff --git a/src/udi/handlers/sve/sve.go b/src/udi/handlers/sve/sve.go index 8024d3f..fe64147 100644 --- a/src/udi/handlers/sve/sve.go +++ b/src/udi/handlers/sve/sve.go @@ -24,6 +24,7 @@ type SingleValueExtractorHandler struct { const TOPIC_SEL = "topic" const PAYLOAD_SEL = "payload" +const PAYLOAD_FULL_SEL = "payload-full" const CONSTANT_SEL = "constant" type localConfig struct { @@ -76,18 +77,20 @@ func NewSveHandler(config config.HandlerConfigT) handler.Handler { // empty device is valid localConfig.device = config.Attributes["device"] - if config.Attributes["valueFrom"] != TOPIC_SEL && config.Attributes["valueFrom"] != PAYLOAD_SEL { + if config.Attributes["valueFrom"] != TOPIC_SEL && config.Attributes["valueFrom"] != PAYLOAD_SEL && config.Attributes["valueFrom"] != PAYLOAD_FULL_SEL { log.Printf("Error: invalid value %s for valueFrom", config.Attributes["valueFrom"]) return t } localConfig.valueFrom = config.Attributes["valueFrom"] - valuePart, err2 := strconv.Atoi(config.Attributes["valuePart"]) - if err2 != nil { - log.Printf("Error: unable to convert valuePart to number: %s", err2) - return t + if config.Attributes["valueFrom"] != PAYLOAD_FULL_SEL { + valuePart, err2 := strconv.Atoi(config.Attributes["valuePart"]) + if err2 != nil { + log.Printf("Error: unable to convert valuePart to number: %s", err2) + return t + } + localConfig.valuePart = valuePart } - localConfig.valuePart = valuePart if config.Attributes["unitFrom"] != TOPIC_SEL && config.Attributes["unitFrom"] != PAYLOAD_SEL && config.Attributes["unitFrom"] != CONSTANT_SEL { log.Printf("Error: invalid value %s for unitFrom", config.Attributes["unitFrom"]) @@ -95,12 +98,14 @@ func NewSveHandler(config config.HandlerConfigT) handler.Handler { } localConfig.unitFrom = config.Attributes["unitFrom"] - unitPart, err3 := strconv.Atoi(config.Attributes["unitPart"]) - if err3 != nil { - log.Printf("Error: unable to convert unitPart to number: %s", err3) - return t + if config.Attributes["unitFrom"] != CONSTANT_SEL { + unitPart, err3 := strconv.Atoi(config.Attributes["unitPart"]) + if err3 != nil { + log.Printf("Error: unable to convert unitPart to number: %s", err3) + return t + } + localConfig.unitPart = unitPart } - localConfig.unitPart = unitPart // empty unit is valid localConfig.unit = config.Attributes["unit"] @@ -183,6 +188,8 @@ func (self *SingleValueExtractorHandler) Handle(message handler.MessageT) { return } variable.Value = payloadMatches[self.config.valuePart] + case PAYLOAD_FULL_SEL: + variable.Value = message.Payload } switch self.config.unitFrom {