dell / dell/iDRAC-Telemetry-Reference-Tools
Change simpledisc to yaml based config
- Dominant language
- Go
- Stars
- 44
- Forks
- 32
- PR merge metrics
- No merged PRs in 30d
Description
I think it makes sense to move to a yaml based config file and remove the password from a plain text file.
In a kubernetes deployment I'm storing the config.yaml in a configmap and mounting that to the container.
`kubectl create configmap telemetry-config -n telemetry --from-file=../../docker-compose/config.yaml`
simpledisc.go
```go
// Licensed to You under the Apache License, Version 2.0.
package main
import (
"log"
"os"
"strconv"
"time"
"github.com/dell/iDRAC-Telemetry-Reference-Tools/internal/disc"
"github.com/dell/iDRAC-Telemetry-Reference-Tools/internal/messagebus/stomp"
"gopkg.in/yaml.v3"
)
var configStrings = map[string]string{
"mbhost": "activemq",
"mbport": "61613",
}
var services []disc.Service
func getEnvSettings() {
mbHost := os.Getenv("MESSAGEBUS_HOST")
if len(mbHost) > 0 {
configStrings["mbhost"] = mbHost
}
mbPort := os.Getenv("MESSAGEBUS_PORT")
if len(mbPort) > 0 {
configStrings["mbport"] = mbPort
}
}
func main() {
var ServiceConfig disc.ServiceConfig
yamlData, err := os.ReadFile("config/config.yaml")
if err != nil {
log.Fatal("Fail to read file: %v", err)
}
yaml.Unmarshal(yamlData, &ServiceConfig)
log.Println("Loaded Server Config")
//Gather configuration from environment variables
getEnvSettings()
log.Printf("Services: %+v", ServiceConfig)
discoveryService := new(disc.DiscoveryService)
for {
stompPort, _ := strconv.Atoi(configStrings["mbport"])
mb, err := stomp.NewStompMessageBus(configStrings["mbhost"], stompPort)
if err != nil {
log.Printf("Could not connect to message bus: %s", err)
time.Sleep(5 * time.Second)
} else {
discoveryService.Bus = mb
defer mb.Close()
break
}
}
commands := make(chan *disc.Command)
log.Print("Discovery Service is initialized")
for _, element := range ServiceConfig.Services {
go func(elem disc.Service) {
err := discoveryService.SendService(elem)
if err != nil {
log.Printf("Failed sending service %v %v", elem, err)
}
}(element)
}
go discoveryService.ReceiveCommand(commands)
for {
command := <-commands
log.Printf("in simpledisc Received command: %s", command.Command)
switch command.Command {
case disc.RESEND:
for _, element := range ServiceConfig.Services {
go func(elem disc.Service) {
err := discoveryService.SendService(elem)
if err != nil {
log.Printf("Failed resending service %v %v", elem, err)
}
}(element)
}
case disc.TERMINATE:
os.Exit(0)
}
}
}
```
config.yaml
```yaml
services:
- ip: idrac-R650-9Z38ZZZ.example.com
serviceType: iDRAC
- ip: idrac-R750-859NZZZ.example.com
serviceType: iDRAC
```
docker-compose.yaml
```yaml
simpledisc:
<<: *refdaemon
container_name: simpledisc
image: simpledisc:latest
build:
<<: *base-build
args:
<<: *base-args
CMD: simpledisc
volumes:
- ./config.yaml:/app/config/config.yaml
```
Contributor guide
Research direction
Start with simpledisc.go and the config.yaml mount in docker-compose.yaml. Trace which settings simpledisc currently reads from its configuration and environment, then verify the deployment can provide the required values through the mounted YAML file without retaining the password in plain text. Done means the service starts and connects correctly with the new configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- backend, devops
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100