emissary/internal/server/init.go

55 lines
1.2 KiB
Go
Raw Permalink Normal View History

2023-02-02 10:55:24 +01:00
package server
import (
"context"
"forge.cadoles.com/Cadoles/emissary/internal/setup"
"forge.cadoles.com/Cadoles/emissary/internal/spec"
2023-02-02 10:55:24 +01:00
"github.com/pkg/errors"
"gitlab.com/wpetit/goweb/logger"
2023-02-02 10:55:24 +01:00
)
func (s *Server) initRepositories(ctx context.Context) error {
agentRepo, err := setup.NewAgentRepository(ctx, s.conf.Database)
2023-02-02 10:55:24 +01:00
if err != nil {
return errors.WithStack(err)
}
tenantRepo, err := setup.NewTenantRepository(ctx, s.conf.Database)
if err != nil {
return errors.WithStack(err)
}
specDefRepo, err := setup.NewSpecDefinitionRepository(ctx, s.conf.Database)
if err != nil {
return errors.WithStack(err)
}
2023-02-02 10:55:24 +01:00
s.agentRepo = agentRepo
s.tenantRepo = tenantRepo
s.specDefRepo = specDefRepo
return nil
}
func (s *Server) initSpecDefinitions(ctx context.Context) error {
err := spec.Walk(func(name, version string, schema []byte) error {
logger.Debug(
ctx, "updating spec definition",
logger.F("name", name),
logger.F("version", version),
)
if _, err := s.specDefRepo.Upsert(ctx, name, version, schema); err != nil {
return errors.WithStack(err)
}
return nil
})
if err != nil {
return errors.WithStack(err)
}
2023-02-02 10:55:24 +01:00
return nil
}