@@ -351,24 +351,20 @@ func (s *Service) RawGetRecursive(path string) (string, error) {
351351func (s * Service ) GetDetectorForHost (hostname string ) (string , error ) {
352352 s .logMethod ()
353353
354- if cSrc , ok := s .src .(* cfgbackend.ConsulSource ); ok {
355- keys , err := cSrc .GetKeysByPrefix (filepath .Join ("o2/hardware" , "detectors" ))
356- if err != nil {
357- return "" , err
358- }
359- for _ , key := range keys {
360- // key example: o2/hardware/detectors/TST/flps/some-hostname/
361- splitKey := strings .Split (key , "/" )
362- if len (splitKey ) == 7 {
363- if splitKey [5 ] == hostname {
364- return splitKey [3 ], nil
365- }
354+ keys , err := s .src .GetKeysByPrefix (filepath .Join ("o2/hardware" , "detectors" ))
355+ if err != nil {
356+ return "" , err
357+ }
358+ for _ , key := range keys {
359+ // key example: o2/hardware/detectors/TST/flps/some-hostname/
360+ splitKey := strings .Split (key , "/" )
361+ if len (splitKey ) == 7 {
362+ if splitKey [5 ] == hostname {
363+ return splitKey [3 ], nil
366364 }
367365 }
368- return "" , fmt .Errorf ("detector not found for host %s" , hostname )
369- } else {
370- return "" , errors .New ("runtime KV not supported with file backend" )
371366 }
367+ return "" , fmt .Errorf ("detector not found for host %s" , hostname )
372368}
373369
374370func (s * Service ) GetDetectorsForHosts (hosts []string ) ([]string , error ) {
@@ -396,25 +392,21 @@ func (s *Service) GetDetectorsForHosts(hosts []string) ([]string, error) {
396392func (s * Service ) GetCRUCardsForHost (hostname string ) ([]string , error ) {
397393 s .logMethod ()
398394
399- if cSrc , ok := s .src .(* cfgbackend.ConsulSource ); ok {
400- var cards map [string ]Card
401- var serials []string
402- cfgCards , err := cSrc .Get (filepath .Join ("o2/hardware" , "flps" , hostname , "cards" ))
403- if err != nil {
404- return nil , err
405- }
406- json .Unmarshal ([]byte (cfgCards ), & cards )
407- unique := make (map [string ]bool )
408- for _ , card := range cards {
409- if _ , value := unique [card .Serial ]; ! value {
410- unique [card .Serial ] = true
411- serials = append (serials , card .Serial )
412- }
395+ var cards map [string ]Card
396+ var serials []string
397+ cfgCards , err := s .src .Get (filepath .Join ("o2/hardware" , "flps" , hostname , "cards" ))
398+ if err != nil {
399+ return nil , err
400+ }
401+ json .Unmarshal ([]byte (cfgCards ), & cards )
402+ unique := make (map [string ]bool )
403+ for _ , card := range cards {
404+ if _ , value := unique [card .Serial ]; ! value {
405+ unique [card .Serial ] = true
406+ serials = append (serials , card .Serial )
413407 }
414- return serials , nil
415- } else {
416- return nil , errors .New ("runtime KV not supported with file backend" )
417408 }
409+ return serials , nil
418410}
419411
420412func (s * Service ) GetEndpointsForCRUCard (hostname , cardSerial string ) ([]string , error ) {
@@ -427,26 +419,22 @@ func (s *Service) GetEndpointsForCRUCard(hostname, cardSerial string) ([]string,
427419 WithField ("cardSerial" , cardSerial ).
428420 Debug ("getting endpoints" )
429421
430- if cSrc , ok := s .src .(* cfgbackend.ConsulSource ); ok {
431- var cards map [string ]Card
432- var endpoints []string
433- cfgCards , err := cSrc .Get (filepath .Join ("o2/hardware" , "flps" , hostname , "cards" ))
434- if err != nil {
435- return nil , err
436- }
437- err = json .Unmarshal ([]byte (cfgCards ), & cards )
438- if err != nil {
439- return nil , err
440- }
441- for _ , card := range cards {
442- if card .Serial == cardSerial {
443- endpoints = append (endpoints , card .Endpoint )
444- }
422+ var cards map [string ]Card
423+ var endpoints []string
424+ cfgCards , err := s .src .Get (filepath .Join ("o2/hardware" , "flps" , hostname , "cards" ))
425+ if err != nil {
426+ return nil , err
427+ }
428+ err = json .Unmarshal ([]byte (cfgCards ), & cards )
429+ if err != nil {
430+ return nil , err
431+ }
432+ for _ , card := range cards {
433+ if card .Serial == cardSerial {
434+ endpoints = append (endpoints , card .Endpoint )
445435 }
446- return endpoints , nil
447- } else {
448- return nil , errors .New ("runtime KV not supported with file backend" )
449436 }
437+ return endpoints , nil
450438}
451439
452440func (s * Service ) GetRuntimeEntry (component string , key string ) (string , error ) {
0 commit comments