Skip to content

Commit

Permalink
fix: Convert the Device Labels value from string to string slice
Browse files Browse the repository at this point in the history
Signed-off-by: FelixTing <felix@iotechsys.com>
  • Loading branch information
FelixTing committed May 28, 2024
1 parent 2bf2505 commit 0d5b88d
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// -*- Mode: Go; indent-tabs-mode: t -*-
//
// Copyright (C) 2020-2022 IOTech Ltd
// Copyright (C) 2020-2024 IOTech Ltd
// Copyright (C) 2023 Intel Corp.
//
// SPDX-License-Identifier: Apache-2.0

package config

import (
"strings"

bootstrapConfig "github.com/edgexfoundry/go-mod-bootstrap/v3/config"
)

Expand Down Expand Up @@ -38,6 +40,16 @@ func (c *ConfigurationStruct) UpdateFromRaw(rawConfig interface{}) bool {
if ok {
*c = *configuration
}
// Device labels are stored as a single string, so we need to convert it to a string slice.
// The decision to do the conversion in sdk is based on the fact that we can only modify the logic inside the
// decoding function of the Keeper client. Unless we opt to develop a new decoder for Consul ourselves.
// See:
// Keeper client https://github.com/edgexfoundry/go-mod-configuration/blob/2c3512b731558a2be3f8460c3f0fed9361b5dcd4/internal/pkg/keeper/client.go#L163
// Consul client https://github.com/edgexfoundry/go-mod-configuration/blob/2c3512b731558a2be3f8460c3f0fed9361b5dcd4/internal/pkg/consul/client.go#L206
if len(c.Device.Labels) == 1 && strings.HasPrefix(c.Device.Labels[0], "[") &&
strings.HasSuffix(c.Device.Labels[0], "]") {
c.Device.Labels = strings.Fields(strings.Trim(c.Device.Labels[0], "[]"))
}
return ok
}

Expand Down

0 comments on commit 0d5b88d

Please sign in to comment.