Skip to content

Commit

Permalink
fix: sprintf floats & cname const
Browse files Browse the repository at this point in the history
  • Loading branch information
Kav91 committed Jan 28, 2020
1 parent 49a1ca7 commit 4b77e22
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions internal/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ func runConfigLookup(dockerClient *client.Client, containers *[]types.Container,
if findContainerTarget(discoveryConfig, container, foundTargetContainerIds) {

switch discoveryConfig["tt"].(string) {
case "cname", load.TypeContainer:
case load.TypeCname, load.TypeContainer:
load.Logrus.Debug(fmt.Sprintf("discovery: %v cfg lookup matched %v %v - %v", container.ID, container.Names, cd.Target, cd.FileName))
case load.Img, load.Image:
load.Logrus.Debug(fmt.Sprintf("discovery: %v cfg lookup matched %v %v - %v", container.ID, container.Image, cd.Target, cd.FileName))
Expand Down Expand Up @@ -612,7 +612,7 @@ func findContainerTarget(discoveryConfig map[string]interface{}, container types
switch discoveryConfig["tt"].(type) {
case string:
switch discoveryConfig["tt"].(string) {
case "cname", load.TypeContainer:
case load.TypeCname, load.TypeContainer:
for _, containerName := range container.Names {
checkContainerName := strings.TrimPrefix(containerName, "/") // docker adds a / in front
if checkContainerName != "" && formatter.KvFinder(discoveryConfig["tm"].(string), checkContainerName, discoveryConfig["t"].(string)) {
Expand Down
2 changes: 1 addition & 1 deletion internal/discovery/fargate.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func determineDynamicFargateConfigs(configs *[]load.Config, TaskMetadata load.Ta

func checkContainerMatch(container load.Container, containerDiscovery load.ContainerDiscovery) bool {
switch containerDiscovery.Type {
case "cname", load.TypeContainer:
case load.TypeCname, load.TypeContainer:
if formatter.KvFinder(containerDiscovery.Mode, container.Name, containerDiscovery.Target) {
return true
}
Expand Down
1 change: 1 addition & 0 deletions internal/load/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const (
Img = "img"
Image = "image"
TypeContainer = "container"
TypeCname = "cname"
TypeJSON = "json"
TypeXML = "xml"
TypeColumns = "columns"
Expand Down
15 changes: 12 additions & 3 deletions internal/processor/lookups.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ import (
"github.com/sirupsen/logrus"
)

func cleanValue(v *interface{}) string {
switch val := (*v).(type) {
case float32, float64:
return fmt.Sprintf("%f", val)
default:
return fmt.Sprintf("%v", val)
}
}

// StoreLookups if key is found (using regex), store the values in the lookupStore as the defined lookupStoreKey for later use
func StoreLookups(storeLookups map[string]string, key *string, lookupStore *map[string]map[string]struct{}, v *interface{}) {
for lookupStoreKey, lookupFindKey := range storeLookups {
Expand All @@ -32,10 +41,10 @@ func StoreLookups(storeLookups map[string]string, key *string, lookupStore *map[
}).Debug("splitting array")

for _, dataKey := range data {
(*lookupStore)[lookupStoreKey][fmt.Sprintf("%v", dataKey)] = struct{}{}
(*lookupStore)[lookupStoreKey][cleanValue(&dataKey)] = struct{}{}
}
default:
(*lookupStore)[lookupStoreKey][fmt.Sprintf("%v", *v)] = struct{}{}
(*lookupStore)[lookupStoreKey][cleanValue(v)] = struct{}{}
}
}
}
Expand All @@ -48,7 +57,7 @@ func VariableLookups(variableLookups map[string]string, key *string, variableSto
if (*variableStore) == nil {
(*variableStore) = map[string]string{}
}
(*variableStore)[variableStoreKey] = fmt.Sprintf("%v", *v)
(*variableStore)[variableStoreKey] = cleanValue(v)
}
}
}

0 comments on commit 4b77e22

Please sign in to comment.