Skip to content

Commit

Permalink
Sync gravity settings in manual e2e test, improve debug prints
Browse files Browse the repository at this point in the history
  • Loading branch information
lovelaze committed Aug 17, 2024
1 parent 1f8813d commit 3d808bc
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
9 changes: 9 additions & 0 deletions e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ func (suite *testSuite) Test_ManualSync() {
suite.T().Setenv("SYNC_CONFIG_MISC", "true")
suite.T().Setenv("SYNC_CONFIG_DEBUG", "true")

suite.T().Setenv("SYNC_GRAVITY_DHCP_LEASES", "true")
suite.T().Setenv("SYNC_GRAVITY_GROUP", "true")
suite.T().Setenv("SYNC_GRAVITY_AD_LIST", "true")
suite.T().Setenv("SYNC_GRAVITY_AD_LIST_BY_GROUP", "true")
suite.T().Setenv("SYNC_GRAVITY_DOMAIN_LIST", "true")
suite.T().Setenv("SYNC_GRAVITY_DOMAIN_LIST_BY_GROUP", "true")
suite.T().Setenv("SYNC_GRAVITY_CLIENT", "true")
suite.T().Setenv("SYNC_GRAVITY_CLIENT_BY_GROUP", "true")

s, err := service.Init()
require.NoError(suite.T(), err)
err = s.Run()
Expand Down
24 changes: 24 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,27 @@ func LoadEnvFile(filename string) error {
log.Debug().Msgf("Loading env file: %s", filename)
return godotenv.Load(filename)
}

func (c *Config) String() string {
replicas := make([]string, len(c.Replicas))
for _, replica := range c.Replicas {
replicas = append(replicas, replica.Url.String())
}

cron := ""
if c.Cron != nil {
cron = *c.Cron
}

syncSettings := ""
if c.SyncSettings != nil {
if mc := c.SyncSettings.Config; mc != nil {
syncSettings += fmt.Sprintf("config=%+v", *mc)
}
if gc := c.SyncSettings.Gravity; gc != nil {
syncSettings += fmt.Sprintf(", gravity=%+v", *gc)
}
}

return fmt.Sprintf("primary=%s, replicas=%s, fullSync=%t, cron=%s, syncSettings=%s", c.Primary.Url, replicas, c.FullSync, cron, syncSettings)
}
10 changes: 5 additions & 5 deletions internal/pihole/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var (
func NewClient(piHole model.PiHole) Client {
logger := log.With().Str("client", piHole.Url.String()).Logger()
return &client{
PiHole: piHole,
piHole: piHole,
logger: &logger,
}
}
Expand All @@ -41,7 +41,7 @@ type Client interface {
}

type client struct {
PiHole model.PiHole
piHole model.PiHole
auth auth
logger *zerolog.Logger
}
Expand Down Expand Up @@ -73,7 +73,7 @@ func (client *client) Authenticate() error {
client.logger.Debug().Msg("Authenticate")
authResponse := model.AuthResponse{}

reqBytes, err := json.Marshal(model.AuthRequest{Password: client.PiHole.Password})
reqBytes, err := json.Marshal(model.AuthRequest{Password: client.piHole.Password})
if err != nil {
return err
}
Expand Down Expand Up @@ -314,11 +314,11 @@ func (client *client) PatchConfig(patchRequest *model.PatchConfigRequest) error
}

func (client *client) String() string {
return client.PiHole.Url.String()
return client.piHole.Url.String()
}

func (client *client) ApiPath(target string) string {
return client.PiHole.Url.JoinPath("api", target).String()
return client.piHole.Url.JoinPath("api", target).String()
}

func successfulHttpStatus(statusCode int) error {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func Init() (*Service, error) {

func (service *Service) Run() error {
log.Info().Msgf("Starting nebula-sync v%s", version.Version)
log.Debug().Msgf("Settings cron=%v, fullsync=%v, syncsettings=%v", service.conf.Cron, service.conf.FullSync, service.conf.SyncSettings)
log.Debug().Str("config", service.conf.String()).Msgf("Settings")

if service.conf.Cron == nil {
return service.doSync(service.target)
Expand Down

0 comments on commit 3d808bc

Please sign in to comment.