Files
dev-service/pkg/authz/service.go
itzaname fecfc520a8
Some checks failed
continuous-integration/drone/push Build is failing
Update package path
2025-06-22 12:43:19 -04:00

57 lines
1.3 KiB
Go

package authz
import (
"errors"
"git.itzana.me/StrafesNET/dev-service/pkg/datastore"
"git.itzana.me/strafesnet/go-grpc/auth"
)
// Service provides authorization and authentication services
type Service struct {
store datastore.Datastore
authClient auth.AuthServiceClient
domain string
}
// Option represents a functional option for configuring the Service
type Option func(*Service)
// WithDatastore sets the datastore for the Service
func WithDatastore(store datastore.Datastore) Option {
return func(s *Service) {
s.store = store
}
}
// WithAuthClient sets the auth client for the Service
func WithAuthClient(authClient auth.AuthServiceClient) Option {
return func(s *Service) {
s.authClient = authClient
}
}
// WithDomain sets the local domain for the service
func WithDomain(domain string) Option {
return func(s *Service) {
s.domain = domain
}
}
// NewService creates a new authz service using functional options
func NewService(opts ...Option) (*Service, error) {
s := &Service{}
for _, opt := range opts {
opt(s)
}
if s.store == nil {
return nil, errors.New("datastore is required")
}
if s.authClient == nil {
return nil, errors.New("authClient is required")
}
if s.domain == "" {
return nil, errors.New("domain is required")
}
return s, nil
}