Files
tasks/common/authorization/authorizer.go
zeekay 5a601d081b rebrand: go.temporal.io/server -> github.com/hanzoai/tasks
Full module path rebrand from Temporal to Hanzo Tasks:
- go.mod module: github.com/hanzoai/tasks
- All internal Go imports updated (1906 files)
- cmd/server renamed to cmd/tasksd
- Binary name: tasksd (was temporal-server)
- Docker images: hanzoai/tasks (was temporalio/server)
- README rewritten with Hanzo Tasks branding
- LLM.md created with integration notes
- Makefile, goreleaser, CI workflows updated
- go.temporal.io/sdk and go.temporal.io/api imports preserved (separate repos)

Fork of Temporal.io (MIT license).
2026-03-19 10:36:40 -07:00

76 lines
1.9 KiB
Go

//go:generate mockgen -package $GOPACKAGE -source $GOFILE -destination authorizer_mock.go
package authorization
import (
"context"
"fmt"
"strings"
"github.com/hanzoai/tasks/common/config"
)
const (
// DecisionDeny means auth decision is deny
DecisionDeny Decision = iota + 1
// DecisionAllow means auth decision is allow
DecisionAllow
)
// @@@SNIPSTART temporal-common-authorization-authorizer-calltarget
// CallTarget is contains information for Authorizer to make a decision.
// It can be extended to include resources like WorkflowType and TaskQueue
type CallTarget struct {
// APIName must be the full API function name.
// Example: "/temporal.api.workflowservice.v1.WorkflowService/StartWorkflowExecution".
APIName string
// If a Namespace is not being targeted this be set to an empty string.
Namespace string
// The nexus endpoint name being targeted (if any).
NexusEndpointName string
// Request contains a deserialized copy of the API request object
Request any
}
// @@@SNIPEND
type (
// Result is result from authority.
Result struct {
Decision Decision
// Reason may contain a message explaining the value of the Decision field.
Reason string
}
// Decision is enum type for auth decision
Decision int
)
// @@@SNIPSTART temporal-common-authorization-authorizer-interface
// Authorizer is an interface for implementing authorization logic
type Authorizer interface {
Authorize(ctx context.Context, caller *Claims, target *CallTarget) (Result, error)
}
// @@@SNIPEND
type hasNamespace interface {
GetNamespace() string
}
func GetAuthorizerFromConfig(config *config.Authorization) (Authorizer, error) {
switch strings.ToLower(config.Authorizer) {
case "":
return NewNoopAuthorizer(), nil
case "default":
return NewDefaultAuthorizer(), nil
}
return nil, fmt.Errorf("unknown authorizer: %s", config.Authorizer)
}
func IsNoopAuthorizer(authorizer Authorizer) bool {
_, ok := authorizer.(*noopAuthorizer)
return ok
}