authz

package
v0.0.0-...-f8970bf Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAuthenticated = errors.New("not authenticated")

Functions

func ContextWithActor

func ContextWithActor(ctx context.Context, user AuthenticatedUser, roles []*role.Role) context.Context

ContextWithActor Return a context with an actor attached to it.

func RequireGlobalAdmin

func RequireGlobalAdmin(ctx context.Context) error

func RequireGlobalAuthorization

func RequireGlobalAuthorization(actor *Actor, requiredAuthzName role.Authorization) error

RequireGlobalAuthorization Require an actor to have a specific authorization through a globally assigned role.

func RequireTeamAuthorization

func RequireTeamAuthorization(actor *Actor, requiredAuthzName role.Authorization, targetTeamSlug slug.Slug) error

RequireTeamAuthorization Require an actor to have a specific authorization through a globally assigned or a correctly targeted role.

func RequireTeamAuthorizationCtx

func RequireTeamAuthorizationCtx(ctx context.Context, requiredAuthzName role.Authorization, targetTeamSlug slug.Slug) error

RequireTeamAuthorizationCtx fetches the actor from the context and checks if it has the required authorization.

Types

type Actor

type Actor struct {
	User  AuthenticatedUser
	Roles []*role.Role
}

func ActorFromContext

func ActorFromContext(ctx context.Context) *Actor

ActorFromContext Get the actor stored in the context. Requires that a middleware has stored an actor in the first place.

func (*Actor) Authenticated

func (u *Actor) Authenticated() bool

type AuthenticatedUser

type AuthenticatedUser interface {
	GetID() uuid.UUID
	Identity() string
	IsServiceAccount() bool
}

type ContextKey

type ContextKey string

type ErrMissingAuthorization

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

func (ErrMissingAuthorization) Error

func (e ErrMissingAuthorization) Error() string

func (ErrMissingAuthorization) GraphError

func (e ErrMissingAuthorization) GraphError() string

type MockAuthenticatedUser

type MockAuthenticatedUser struct {
	mock.Mock
}

MockAuthenticatedUser is an autogenerated mock type for the AuthenticatedUser type

func NewMockAuthenticatedUser

func NewMockAuthenticatedUser(t interface {
	mock.TestingT
	Cleanup(func())
},
) *MockAuthenticatedUser

NewMockAuthenticatedUser creates a new instance of MockAuthenticatedUser. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.

func (*MockAuthenticatedUser) EXPECT

func (*MockAuthenticatedUser) GetID

func (_m *MockAuthenticatedUser) GetID() uuid.UUID

GetID provides a mock function with given fields:

func (*MockAuthenticatedUser) Identity

func (_m *MockAuthenticatedUser) Identity() string

Identity provides a mock function with given fields:

func (*MockAuthenticatedUser) IsServiceAccount

func (_m *MockAuthenticatedUser) IsServiceAccount() bool

IsServiceAccount provides a mock function with given fields:

type MockAuthenticatedUser_Expecter

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

func (*MockAuthenticatedUser_Expecter) GetID

GetID is a helper method to define mock.On call

func (*MockAuthenticatedUser_Expecter) Identity

Identity is a helper method to define mock.On call

func (*MockAuthenticatedUser_Expecter) IsServiceAccount

IsServiceAccount is a helper method to define mock.On call

type MockAuthenticatedUser_GetID_Call

type MockAuthenticatedUser_GetID_Call struct {
	*mock.Call
}

MockAuthenticatedUser_GetID_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'GetID'

func (*MockAuthenticatedUser_GetID_Call) Return

func (*MockAuthenticatedUser_GetID_Call) Run

func (*MockAuthenticatedUser_GetID_Call) RunAndReturn

type MockAuthenticatedUser_Identity_Call

type MockAuthenticatedUser_Identity_Call struct {
	*mock.Call
}

MockAuthenticatedUser_Identity_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Identity'

func (*MockAuthenticatedUser_Identity_Call) Return

func (*MockAuthenticatedUser_Identity_Call) Run

func (*MockAuthenticatedUser_Identity_Call) RunAndReturn

type MockAuthenticatedUser_IsServiceAccount_Call

type MockAuthenticatedUser_IsServiceAccount_Call struct {
	*mock.Call
}

MockAuthenticatedUser_IsServiceAccount_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'IsServiceAccount'

func (*MockAuthenticatedUser_IsServiceAccount_Call) Return

func (*MockAuthenticatedUser_IsServiceAccount_Call) Run

func (*MockAuthenticatedUser_IsServiceAccount_Call) RunAndReturn

Jump to

Keyboard shortcuts

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