@@ -47,6 +47,7 @@ import (
4747)
4848
4949var log = logger .New (logrus .StandardLogger (), "confsys" )
50+
5051const inventoryKeyPrefix = "o2/hardware/"
5152
5253type Service struct {
@@ -136,7 +137,9 @@ func (s *Service) ListDetectors(getAll bool) (detectors []string, err error) {
136137 for _ , key := range keys {
137138 detTrimmed := strings .TrimPrefix (key , keyPrefix )
138139 detname := strings .Split (detTrimmed , "/" )
139- if ! getAll && detname [0 ] == "TRG" { continue }
140+ if ! getAll && detname [0 ] == "TRG" {
141+ continue
142+ }
140143 if _ , ok := detectorSet [detname [0 ]]; ! ok { // the detector name we found in the path isn't already accounted for
141144 detectorSet [detname [0 ]] = true
142145 detectors = append (detectors , detname [0 ])
@@ -389,12 +392,12 @@ func (s *Service) GetCRUCardsForHost(hostname string) (string, error) {
389392 return "" , err
390393 }
391394 json .Unmarshal ([]byte (cfgCards ), & cards )
392- unique := make (map [string ]bool )
393- for _ , card := range cards {
395+ unique := make (map [string ]bool )
396+ for _ , card := range cards {
394397 if _ , value := unique [card .Serial ]; ! value {
395- unique [card .Serial ] = true
396- serials = append (serials , card .Serial )
397- }
398+ unique [card .Serial ] = true
399+ serials = append (serials , card .Serial )
400+ }
398401 }
399402 bytes , err := json .Marshal (serials )
400403 if err != nil {
@@ -415,7 +418,7 @@ func (s *Service) GetEndpointsForCRUCard(hostname, cardSerial string) (string, e
415418 return "" , err
416419 }
417420 json .Unmarshal ([]byte (cfgCards ), & cards )
418- for _ , card := range cards {
421+ for _ , card := range cards {
419422 if card .Serial == cardSerial {
420423 endpoints = endpoints + card .Endpoint + " "
421424 }
@@ -444,20 +447,25 @@ func (s *Service) SetRuntimeEntry(component string, key string, value string) er
444447
445448func (s * Service ) ListRuntimeEntries (component string ) ([]string , error ) {
446449 if cSrc , ok := s .src .(* cfgbackend.ConsulSource ); ok {
447- keys , err := cSrc .GetKeysByPrefix (filepath .Join (getConsulRuntimePrefix (), component ))
450+ path := filepath .Join (getConsulRuntimePrefix (), component )
451+ keys , err := cSrc .GetKeysByPrefix (path )
448452 if err != nil {
449453 return nil , err
450454 }
451455
452456 payload := make ([]string , 0 )
453457 for _ , k := range keys {
454- split := strings .Split (k , componentcfg .SEPARATOR )
458+ keySuffix := strings .TrimPrefix (k , path + "/" )
459+ if keySuffix == "" {
460+ continue
461+ }
462+ split := strings .Split (keySuffix , componentcfg .SEPARATOR )
455463 var last string
456- if len (split ) == 4 { // correct depth for first level
457- last = split [3 ]
458- payload = append (payload , last )
459- } else {
464+ last = split [len (split )- 1 ]
465+ if last == "" {
460466 continue
467+ } else {
468+ payload = append (payload , keySuffix )
461469 }
462470 }
463471 return payload , nil
0 commit comments