mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2026-02-21 07:49:48 -06:00
* feat: allow extending the api server * chore: remove internal packages to pkg * chore: update db_gen.go * fix: expose auth * fix: move logger to pkg * fix: don't generate gitignore for prisma client * fix: allow extensions to register their own api spec * feat: expose pool on server config * fix: nil pointer exception on empty opts * fix: run.go file
88 lines
1.9 KiB
Go
88 lines
1.9 KiB
Go
package admin
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hatchet-dev/hatchet/internal/msgqueue"
|
|
"github.com/hatchet-dev/hatchet/internal/services/admin/contracts"
|
|
"github.com/hatchet-dev/hatchet/pkg/repository"
|
|
"github.com/hatchet-dev/hatchet/pkg/validator"
|
|
)
|
|
|
|
type AdminService interface {
|
|
contracts.WorkflowServiceServer
|
|
}
|
|
|
|
type AdminServiceImpl struct {
|
|
contracts.UnimplementedWorkflowServiceServer
|
|
|
|
entitlements repository.EntitlementsRepository
|
|
repo repository.EngineRepository
|
|
mq msgqueue.MessageQueue
|
|
v validator.Validator
|
|
}
|
|
|
|
type AdminServiceOpt func(*AdminServiceOpts)
|
|
|
|
type AdminServiceOpts struct {
|
|
entitlements repository.EntitlementsRepository
|
|
repo repository.EngineRepository
|
|
mq msgqueue.MessageQueue
|
|
v validator.Validator
|
|
}
|
|
|
|
func defaultAdminServiceOpts() *AdminServiceOpts {
|
|
v := validator.NewDefaultValidator()
|
|
|
|
return &AdminServiceOpts{
|
|
v: v,
|
|
}
|
|
}
|
|
|
|
func WithRepository(r repository.EngineRepository) AdminServiceOpt {
|
|
return func(opts *AdminServiceOpts) {
|
|
opts.repo = r
|
|
}
|
|
}
|
|
|
|
func WithEntitlementsRepository(r repository.EntitlementsRepository) AdminServiceOpt {
|
|
return func(opts *AdminServiceOpts) {
|
|
opts.entitlements = r
|
|
}
|
|
}
|
|
|
|
func WithMessageQueue(mq msgqueue.MessageQueue) AdminServiceOpt {
|
|
return func(opts *AdminServiceOpts) {
|
|
opts.mq = mq
|
|
}
|
|
}
|
|
|
|
func WithValidator(v validator.Validator) AdminServiceOpt {
|
|
return func(opts *AdminServiceOpts) {
|
|
opts.v = v
|
|
}
|
|
}
|
|
|
|
func NewAdminService(fs ...AdminServiceOpt) (AdminService, error) {
|
|
opts := defaultAdminServiceOpts()
|
|
|
|
for _, f := range fs {
|
|
f(opts)
|
|
}
|
|
|
|
if opts.repo == nil {
|
|
return nil, fmt.Errorf("repository is required. use WithRepository")
|
|
}
|
|
|
|
if opts.mq == nil {
|
|
return nil, fmt.Errorf("task queue is required. use WithMessageQueue")
|
|
}
|
|
|
|
return &AdminServiceImpl{
|
|
repo: opts.repo,
|
|
entitlements: opts.entitlements,
|
|
mq: opts.mq,
|
|
v: opts.v,
|
|
}, nil
|
|
}
|