auth

package
v0.10.2 Latest Latest
Warning

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

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PermissionIndexerReleasesRead        = "indexer.releases.read"
	PermissionIndexerReleasesOverride    = "indexer.releases.override"
	PermissionIndexerReleasesHide        = "indexer.releases.hide"
	PermissionIndexerReleasesPurge       = "indexer.releases.purge"
	PermissionIndexerRuntimeRead         = "indexer.runtime.read"
	PermissionIndexerRuntimeRun          = "indexer.runtime.run"
	PermissionIndexerRuntimePause        = "indexer.runtime.pause"
	PermissionIndexerRuntimeConfigure    = "indexer.runtime.configure"
	PermissionAdminSettingsRead          = "admin.settings.read"
	PermissionAdminSettingsWrite         = "admin.settings.write"
	PermissionAggregatorReleasesRead     = "aggregator.releases.read"
	PermissionAggregatorRuntimeRead      = "aggregator.runtime.read"
	PermissionAggregatorRuntimeConfigure = "aggregator.runtime.configure"
	PermissionGoNZBNetSearch             = "gonzbnet.search"
	PermissionGoNZBNetGet                = "gonzbnet.get"
	PermissionGoNZBNetResolveManifest    = "gonzbnet.resolve_manifest"
	PermissionGoNZBNetViewTrustScore     = "gonzbnet.view_trust_score"
	PermissionGoNZBNetViewSourceNode     = "gonzbnet.view_source_node"
	PermissionGoNZBNetViewCoverage       = "gonzbnet.view.coverage"
	PermissionGoNZBNetAdminRead          = "gonzbnet.admin.read"
	PermissionGoNZBNetAdminWrite         = "gonzbnet.admin.write"
	PermissionGoNZBNetAdminPeers         = "gonzbnet.admin.peers"
	PermissionGoNZBNetAdminPools         = "gonzbnet.admin.pools"
	PermissionGoNZBNetAdminModeration    = "gonzbnet.admin.moderation"
	PermissionGoNZBNetAdminKeys          = "gonzbnet.admin.keys"
	PermissionGoNZBNetAdminCoverage      = "gonzbnet.admin.coverage"
	PermissionGoNZBNetAdminScanner       = "gonzbnet.admin.scanner"
	PermissionGoNZBNetAdminValidator     = "gonzbnet.admin.validator"
	PermissionGoNZBNetAdminScheduler     = "gonzbnet.admin.scheduler"
	PermissionDownloadClientsSend        = "download_clients.send"
	PermissionUploaderSubmissionsRead    = "uploader.submissions.read"
	PermissionUploaderSubmissionsCreate  = "uploader.submissions.create"
	PermissionUploaderSubmissionsReview  = "uploader.submissions.review"
	PermissionUploaderPublicationsManage = "uploader.publications.manage"
	PermissionAuthUsersRead              = "auth.users.read"
	PermissionAuthUsersWrite             = "auth.users.write"
	PermissionAuthRolesRead              = "auth.roles.read"
	PermissionAuthRolesWrite             = "auth.roles.write"
	PermissionAuthTokensRead             = "auth.tokens.read"
	PermissionAuthTokensWrite            = "auth.tokens.write"
)

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("invalid credentials")
	ErrUnauthorized       = errors.New("unauthorized")
	ErrForbidden          = errors.New("forbidden")
	ErrSetupRequired      = errors.New("initial setup required")
	ErrSetupCompleted     = errors.New("initial setup already completed")
)

Functions

func ContextWithPrincipal added in v0.9.0

func ContextWithPrincipal(ctx context.Context, principal *Principal) context.Context

Types

type Principal

type Principal struct {
	UserID      string
	Username    string
	RoleIDs     []string
	Permissions map[string]struct{}
}

func PrincipalFromContext added in v0.9.0

func PrincipalFromContext(ctx context.Context) (*Principal, bool)

func (*Principal) Has

func (p *Principal) Has(permission string) bool

type Role

type Role struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Builtin     bool      `json:"builtin"`
	Permissions []string  `json:"permissions"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

func DefaultRoles

func DefaultRoles() []Role

type Service

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

func NewService

func NewService(store Store) *Service

func (*Service) AuthenticatePassword

func (s *Service) AuthenticatePassword(ctx context.Context, username, password string) (*Session, *Principal, error)

func (*Service) AuthenticateSession

func (s *Service) AuthenticateSession(ctx context.Context, sessionID string) (*Principal, error)

func (*Service) AuthenticateToken

func (s *Service) AuthenticateToken(ctx context.Context, rawToken string) (*Principal, error)

func (*Service) Bootstrap

func (s *Service) Bootstrap(ctx context.Context) error

func (*Service) CreateToken

func (s *Service) CreateToken(ctx context.Context, userID, name string) (*Token, string, error)

func (*Service) DeleteRole

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

func (*Service) DeleteUser

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

func (*Service) GetUser

func (s *Service) GetUser(ctx context.Context, userID string) (*StoredUser, error)

func (*Service) ListRoles

func (s *Service) ListRoles(ctx context.Context) ([]Role, error)

func (*Service) ListTokens

func (s *Service) ListTokens(ctx context.Context) ([]Token, error)

func (*Service) ListTokensByUser

func (s *Service) ListTokensByUser(ctx context.Context, userID string) ([]Token, error)

func (*Service) ListUsers

func (s *Service) ListUsers(ctx context.Context) ([]StoredUser, error)

func (*Service) LogoutSession

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

func (*Service) RevokeToken

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

func (*Service) RevokeTokenForUser

func (s *Service) RevokeTokenForUser(ctx context.Context, userID, tokenID string) error

func (*Service) SetupInitialUser

func (s *Service) SetupInitialUser(ctx context.Context, username, password string) (*Session, *Principal, error)

func (*Service) SetupRequired

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

func (*Service) UpsertRole

func (s *Service) UpsertRole(ctx context.Context, role Role) (*Role, error)

func (*Service) UpsertUser

func (s *Service) UpsertUser(ctx context.Context, user StoredUser, password string, roleIDs []string) (*StoredUser, error)

type Session

type Session struct {
	ID         string
	UserID     string
	ExpiresAt  time.Time
	CreatedAt  time.Time
	LastSeenAt time.Time
}

type Store

type Store interface {
	EnsureAuthDefaults(ctx context.Context, roles []Role) error
	CountAuthUsers(ctx context.Context) (int, error)
	CreateInitialAuthUser(ctx context.Context, user StoredUser, roleIDs []string) error
	GetAuthUserByUsername(ctx context.Context, username string) (*StoredUser, error)
	GetAuthUserByID(ctx context.Context, userID string) (*StoredUser, error)
	ListAuthUsers(ctx context.Context) ([]StoredUser, error)
	UpsertAuthUser(ctx context.Context, user StoredUser) error
	DeleteAuthUser(ctx context.Context, userID string) error
	ListAuthRoles(ctx context.Context) ([]Role, error)
	UpsertAuthRole(ctx context.Context, role Role) error
	DeleteAuthRole(ctx context.Context, roleID string) error
	ReplaceAuthUserRoles(ctx context.Context, userID string, roleIDs []string) error
	ListAuthUserRoleIDs(ctx context.Context, userID string) ([]string, error)
	CreateAuthSession(ctx context.Context, session Session) error
	GetAuthSession(ctx context.Context, sessionID string) (*Session, error)
	TouchAuthSession(ctx context.Context, sessionID string, seenAt time.Time) error
	DeleteAuthSession(ctx context.Context, sessionID string) error
	CreateAuthToken(ctx context.Context, token StoredToken) error
	ListAuthTokens(ctx context.Context) ([]Token, error)
	ListAuthTokensByUserID(ctx context.Context, userID string) ([]Token, error)
	GetAuthTokenByHash(ctx context.Context, tokenHash string) (*StoredToken, error)
	GetAuthTokenByID(ctx context.Context, tokenID string) (*StoredToken, error)
	TouchAuthToken(ctx context.Context, tokenID string, seenAt time.Time) error
	RevokeAuthToken(ctx context.Context, tokenID string) error
}

type StoredToken

type StoredToken struct {
	Token
	TokenHash string
}

type StoredUser

type StoredUser struct {
	User
	PasswordHash string
}

type Token

type Token struct {
	ID         string     `json:"id"`
	UserID     string     `json:"user_id"`
	Name       string     `json:"name"`
	Prefix     string     `json:"prefix"`
	CreatedAt  time.Time  `json:"created_at"`
	LastUsedAt *time.Time `json:"last_used_at,omitempty"`
	RevokedAt  *time.Time `json:"revoked_at,omitempty"`
}

type User

type User struct {
	ID          string    `json:"id"`
	Username    string    `json:"username"`
	Enabled     bool      `json:"enabled"`
	RoleIDs     []string  `json:"role_ids,omitempty"`
	Permissions []string  `json:"permissions,omitempty"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

Jump to

Keyboard shortcuts

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