diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 7b9d27f..bddbaa7 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -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() diff --git a/internal/config/config.go b/internal/config/config.go index 033c94c..047d36b 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -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) +} diff --git a/internal/pihole/client.go b/internal/pihole/client.go index ff4017a..30af246 100644 --- a/internal/pihole/client.go +++ b/internal/pihole/client.go @@ -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, } } @@ -41,7 +41,7 @@ type Client interface { } type client struct { - PiHole model.PiHole + piHole model.PiHole auth auth logger *zerolog.Logger } @@ -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 } @@ -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 { diff --git a/internal/service/service.go b/internal/service/service.go index 6ea53ae..fb8fe76 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -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)