mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-12 13:46:51 +00:00
clean up
This commit is contained in:
parent
25e48b03f9
commit
0e46357690
4 changed files with 25 additions and 33 deletions
|
|
@ -6,6 +6,7 @@ type Service struct {
|
|||
secret string
|
||||
admin string
|
||||
adminSecret string
|
||||
apiKey string
|
||||
}
|
||||
|
||||
type ProviderIndex struct {
|
||||
|
|
@ -13,17 +14,22 @@ type ProviderIndex struct {
|
|||
Providers []string
|
||||
}
|
||||
|
||||
func NewService(secret, admin, adminSecret string) (*Service, error) {
|
||||
if secret == "" || admin == "" || adminSecret == "" {
|
||||
func NewService(secret, admin, adminSecret, apiKey string) (*Service, error) {
|
||||
if secret == "" || admin == "" || adminSecret == "" || apiKey == "" {
|
||||
return nil, errors.New("error building Auth service. Verify your env variables")
|
||||
}
|
||||
return &Service{
|
||||
secret,
|
||||
admin,
|
||||
adminSecret,
|
||||
apiKey,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (as *Service) Authenticate(email, password string) bool {
|
||||
return email == as.admin && password == as.adminSecret
|
||||
}
|
||||
|
||||
func (as *Service) ValidateApiKey(key string) bool {
|
||||
return key == as.apiKey
|
||||
}
|
||||
|
|
|
|||
|
|
@ -52,7 +52,6 @@ func NewService(ctx context.Context, credJson string, opts ...Option) (*Service,
|
|||
return &Service{Service: srv}, nil
|
||||
}
|
||||
|
||||
// TODO: implement create event, list events in a period, delete event
|
||||
func (s *Service) Create(from, to time.Time) (*calendar.Event, error) {
|
||||
l := s.CalendarList.List()
|
||||
r, e := l.Do()
|
||||
|
|
|
|||
|
|
@ -25,16 +25,13 @@ import (
|
|||
)
|
||||
|
||||
type Server struct {
|
||||
Router *echo.Echo
|
||||
bs *booking.Service
|
||||
as *auth.Service
|
||||
ps *pdf.PdfService
|
||||
cs *calendar.Service
|
||||
hc *config.Host
|
||||
addr string
|
||||
secretKey string
|
||||
apiKey string
|
||||
Health *HealthHandler
|
||||
Router *echo.Echo
|
||||
bs *booking.Service
|
||||
as *auth.Service
|
||||
ps *pdf.PdfService
|
||||
cs *calendar.Service
|
||||
hc *config.Host
|
||||
addr string
|
||||
}
|
||||
|
||||
type options struct {
|
||||
|
|
@ -42,7 +39,6 @@ type options struct {
|
|||
fs *embed.FS
|
||||
debug *bool
|
||||
secretKey *string
|
||||
apiKey *string
|
||||
origins []string
|
||||
}
|
||||
|
||||
|
|
@ -86,13 +82,6 @@ func WithOrigins(origins []string) Option {
|
|||
}
|
||||
}
|
||||
|
||||
func WithApiKey(apiKey string) Option {
|
||||
return func(o *options) error {
|
||||
o.apiKey = &apiKey
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func New(bs *booking.Service, as *auth.Service, ps *pdf.PdfService, cs *calendar.Service, hc *config.Host, opts ...Option) (*Server, error) {
|
||||
option := new(options)
|
||||
for _, opt := range opts {
|
||||
|
|
@ -103,15 +92,13 @@ func New(bs *booking.Service, as *auth.Service, ps *pdf.PdfService, cs *calendar
|
|||
}
|
||||
|
||||
s := &Server{
|
||||
Router: NewRouter(*option.fs, *option.debug, *option.secretKey, option.origins),
|
||||
bs: bs,
|
||||
as: as,
|
||||
ps: ps,
|
||||
cs: cs,
|
||||
hc: hc,
|
||||
addr: fmt.Sprintf("0.0.0.0:%d", *option.port),
|
||||
secretKey: *option.secretKey,
|
||||
apiKey: *option.apiKey,
|
||||
Router: NewRouter(*option.fs, *option.debug, *option.secretKey, option.origins),
|
||||
bs: bs,
|
||||
as: as,
|
||||
ps: ps,
|
||||
cs: cs,
|
||||
hc: hc,
|
||||
addr: fmt.Sprintf("0.0.0.0:%d", *option.port),
|
||||
}
|
||||
|
||||
s.MountHandlers()
|
||||
|
|
|
|||
6
main.go
6
main.go
|
|
@ -78,6 +78,7 @@ func run(c context.Context, getEnv func(string) string) error {
|
|||
getEnv("SESSION_SECRET"),
|
||||
getEnv("ADMIN"),
|
||||
getEnv("ADMIN_SECRET"),
|
||||
getEnv("API_KEY"),
|
||||
)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error starting auth service %s", err)
|
||||
|
|
@ -105,16 +106,15 @@ func run(c context.Context, getEnv func(string) string) error {
|
|||
origins := strings.Split(ogs, ",")
|
||||
|
||||
srv, err := server.New(
|
||||
booking.NewService(db),
|
||||
booking.NewService(db), // TODO: should validate the booking service building
|
||||
as,
|
||||
ps,
|
||||
cs,
|
||||
config.NewHost(),
|
||||
config.NewHost(), // TODO: move to the database at some point
|
||||
server.WithPort(port),
|
||||
server.WithFileSystem(static),
|
||||
server.WithDebug(strings.ToLower(getEnv("DEBUG")) == "true"),
|
||||
server.WithSecretKey(getEnv("SECRET_KEY")),
|
||||
server.WithApiKey(getEnv("API_KEY")),
|
||||
server.WithOrigins(origins),
|
||||
)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Reference in a new issue