Skip to content

Commit

Permalink
refactor: change config types
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenschneider committed Sep 5, 2023
1 parent 286f2c5 commit f9a3f47
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion cmd/deps/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package deps

import (
"fmt"

"github.com/soerenschneider/conditional-reboot/internal"
"github.com/soerenschneider/conditional-reboot/internal/group"
)
Expand All @@ -10,7 +11,7 @@ func BuildGroups(groupUpdates chan *group.Group, conf *internal.ConditionalReboo
var groups []*group.Group

for _, groupConf := range conf.Groups {
group, err := BuildGroup(groupUpdates, groupConf)
group, err := BuildGroup(groupUpdates, &groupConf)

Check failure on line 14 in cmd/deps/app.go

View workflow job for this annotation

GitHub Actions / lint

G601: Implicit memory aliasing in for loop. (gosec)
if err != nil {
return nil, fmt.Errorf("could not build group '%s': %w", groupConf.Name, err)
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/deps/group.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package deps

import (
"strings"

"github.com/soerenschneider/conditional-reboot/internal"
"github.com/soerenschneider/conditional-reboot/internal/agent/state"
"github.com/soerenschneider/conditional-reboot/internal/group"
"github.com/soerenschneider/conditional-reboot/internal/group/state_evaluator"
"strings"
)

func BuildGroup(groupUpdates chan *group.Group, conf *internal.GroupConf) (*group.Group, error) {
Expand All @@ -30,7 +31,7 @@ func BuildGroup(groupUpdates chan *group.Group, conf *internal.GroupConf) (*grou
func BuildAgents(conf *internal.GroupConf) ([]state.Agent, error) {
var agents []state.Agent
for _, agentConf := range conf.Agents {
agent, err := BuildAgent(agentConf)
agent, err := BuildAgent(&agentConf)

Check failure on line 34 in cmd/deps/group.go

View workflow job for this annotation

GitHub Actions / lint

G601: Implicit memory aliasing in for loop. (gosec)
if err != nil {
return nil, err
}
Expand Down
13 changes: 7 additions & 6 deletions internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package internal

import (
"encoding/json"

"github.com/rs/zerolog/log"
"github.com/soerenschneider/conditional-reboot/internal/agent/state"
)
Expand All @@ -13,10 +14,10 @@ const (
)

type ConditionalRebootConfig struct {
Groups []*GroupConf `json:"groups" validate:"dive,required"`
JournalFile string `json:"journal_file" validate:"omitempty,filepath"`
MetricsListenAddr string `json:"metrics_listen_addr" validate:"excluded_with=MetricsDir"`
MetricsDir string `json:"metrics_dir" validate:"excluded_with=MetricsListenAddr,omitempty,dirpath"`
Groups []GroupConf `json:"groups" validate:"dive,required"`
JournalFile string `json:"journal_file" validate:"omitempty,filepath"`
MetricsListenAddr string `json:"metrics_listen_addr" validate:"excluded_with=MetricsDir"`
MetricsDir string `json:"metrics_dir" validate:"excluded_with=MetricsListenAddr,omitempty,dirpath"`
}

func (conf *ConditionalRebootConfig) Print() {
Expand All @@ -30,8 +31,8 @@ func (conf *ConditionalRebootConfig) Print() {
}

type GroupConf struct {
Agents []*AgentConf `json:"agents" validate:"dive"`
Name string `json:"name" validate:"required"`
Agents []AgentConf `json:"agents" validate:"dive"`
Name string `json:"name" validate:"required"`

StateEvaluatorName string `json:"state_evaluator_name"`
StateEvaluatorArgs map[string]string `json:"state_evaluator_args" validate:"required"`
Expand Down

0 comments on commit f9a3f47

Please sign in to comment.