service

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package service provides authorization services for the auth module. It includes functionality for checking if a user is authorized to perform specific operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// AdminRoleName is the name of the admin role
	AdminRoleName string

	// ReadOnlyRoleName is the name of the read-only role
	ReadOnlyRoleName string

	// ReadOperationPrefixes are prefixes for read-only operations
	ReadOperationPrefixes []string
}

Config holds the configuration for the authorization service.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default configuration for the authorization service.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service implements authorization functionality.

func NewService

func NewService(config Config, logger *zap.Logger) *Service

NewService creates a new authorization service.

func (*Service) GetUserID

func (s *Service) GetUserID(ctx context.Context) (string, error)

GetUserID retrieves the user ID from the context.

func (*Service) GetUserRoles

func (s *Service) GetUserRoles(ctx context.Context) ([]string, error)

GetUserRoles retrieves the user roles from the context.

func (*Service) HasRole

func (s *Service) HasRole(ctx context.Context, role string) (bool, error)

HasRole checks if the user has a specific role.

func (*Service) IsAdmin

func (s *Service) IsAdmin(ctx context.Context) (bool, error)

IsAdmin checks if the user has admin role.

func (*Service) IsAuthorized

func (s *Service) IsAuthorized(ctx context.Context, operation string) (bool, error)

IsAuthorized checks if the user is authorized to perform the operation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL