auth

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Aug 8, 2024 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// UserIDFlag is the User ID flag we set in the context
	UserIDFlag contextFlags = "user_id"
)

Variables

This section is empty.

Functions

func AdminRequiredMiddleware added in v0.1.4

func AdminRequiredMiddleware(next http.Handler) http.Handler

func Expires added in v0.1.5

func Expires(ctx context.Context) *time.Time

func FullName

func FullName(ctx context.Context) string

FullName returns the full name from context

func GetAdminContext

func GetAdminContext(ctx context.Context) context.Context

GetAdminContext will return an admin context. This can be used internally when fetching users.

func InstanceEntity

func InstanceEntity(ctx context.Context) string

func InstanceHasJITConfig added in v0.1.4

func InstanceHasJITConfig(ctx context.Context) bool

func InstanceID

func InstanceID(ctx context.Context) string

func InstanceName

func InstanceName(ctx context.Context) string

func InstanceParams added in v0.1.4

func InstanceParams(ctx context.Context) (params.Instance, error)

func InstancePoolID

func InstancePoolID(ctx context.Context) string

func InstancePoolType

func InstancePoolType(ctx context.Context) string

func InstanceRunnerStatus

func InstanceRunnerStatus(ctx context.Context) params.RunnerStatus

func InstanceTokenFetched

func InstanceTokenFetched(ctx context.Context) bool

func IsAdmin

func IsAdmin(ctx context.Context) bool

IsAdmin returns a boolean indicating whether or not the context belongs to a logged in user and if that context has the admin flag set

func IsEnabled

func IsEnabled(ctx context.Context) bool

IsEnabled returns the a boolean indicating if the enabled flag is set and is true or false

func PasswordGeneration added in v0.1.5

func PasswordGeneration(ctx context.Context) uint

func PopulateContext

func PopulateContext(ctx context.Context, user params.User, authExpires *time.Time) context.Context

PopulateContext sets the appropriate fields in the context, based on the user object

func PopulateInstanceContext

func PopulateInstanceContext(ctx context.Context, instance params.Instance) context.Context

func SetAdmin

func SetAdmin(ctx context.Context, isAdmin bool) context.Context

SetAdmin sets the isAdmin flag on the context

func SetExpires added in v0.1.5

func SetExpires(ctx context.Context, expires *time.Time) context.Context

func SetFullName

func SetFullName(ctx context.Context, fullName string) context.Context

SetFullName sets the user full name in the context

func SetInstanceEntity

func SetInstanceEntity(ctx context.Context, val string) context.Context

func SetInstanceHasJITConfig added in v0.1.4

func SetInstanceHasJITConfig(ctx context.Context, cfg map[string]string) context.Context

func SetInstanceID

func SetInstanceID(ctx context.Context, id string) context.Context

func SetInstanceName

func SetInstanceName(ctx context.Context, val string) context.Context

func SetInstanceParams added in v0.1.4

func SetInstanceParams(ctx context.Context, instance params.Instance) context.Context

func SetInstancePoolID

func SetInstancePoolID(ctx context.Context, val string) context.Context

func SetInstancePoolType

func SetInstancePoolType(ctx context.Context, val string) context.Context

func SetInstanceRunnerStatus

func SetInstanceRunnerStatus(ctx context.Context, val params.RunnerStatus) context.Context

func SetInstanceTokenFetched

func SetInstanceTokenFetched(ctx context.Context, fetched bool) context.Context

func SetIsEnabled

func SetIsEnabled(ctx context.Context, enabled bool) context.Context

SetIsEnabled sets a flag indicating if account is enabled

func SetPasswordGeneration added in v0.1.5

func SetPasswordGeneration(ctx context.Context, val uint) context.Context

func SetUserID

func SetUserID(ctx context.Context, userID string) context.Context

SetUserID sets the userID in the context

func UserID

func UserID(ctx context.Context) string

UserID returns the userID from the context

Types

type Authenticator

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

func NewAuthenticator

func NewAuthenticator(cfg config.JWTAuth, store common.Store) *Authenticator

func (*Authenticator) AuthenticateUser

func (a *Authenticator) AuthenticateUser(ctx context.Context, info params.PasswordLoginParams) (context.Context, error)

func (*Authenticator) GetJWTMetricsToken

func (a *Authenticator) GetJWTMetricsToken(ctx context.Context) (string, error)

GetJWTMetricsToken returns a JWT token that can be used to read metrics. This token is not tied to a user, no user is stored in the db.

func (*Authenticator) GetJWTToken

func (a *Authenticator) GetJWTToken(ctx context.Context) (string, error)

func (*Authenticator) InitController

func (a *Authenticator) InitController(ctx context.Context, param params.NewUserParams) (params.User, error)

func (*Authenticator) IsInitialized

func (a *Authenticator) IsInitialized() bool

type InstanceJWTClaims

type InstanceJWTClaims struct {
	ID     string `json:"id"`
	Name   string `json:"name"`
	PoolID string `json:"provider_id"`
	// Scope is either repository or organization
	Scope params.GithubEntityType `json:"scope"`
	// Entity is the repo or org name
	Entity        string `json:"entity"`
	CreateAttempt int    `json:"create_attempt"`
	jwt.RegisteredClaims
}

InstanceJWTClaims holds JWT claims

type InstanceTokenGetter added in v0.1.5

type InstanceTokenGetter interface {
	NewInstanceJWTToken(instance params.Instance, entity string, poolType params.GithubEntityType, ttlMinutes uint) (string, error)
}

func NewInstanceTokenGetter added in v0.1.5

func NewInstanceTokenGetter(jwtSecret string) (InstanceTokenGetter, error)

type JWTClaims

type JWTClaims struct {
	UserID      string `json:"user"`
	TokenID     string `json:"token_id"`
	FullName    string `json:"full_name"`
	IsAdmin     bool   `json:"is_admin"`
	ReadMetrics bool   `json:"read_metrics"`
	Generation  uint   `json:"generation"`
	jwt.RegisteredClaims
}

JWTClaims holds JWT claims

type MetricsMiddleware

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

func NewMetricsMiddleware

func NewMetricsMiddleware(cfg config.JWTAuth) (*MetricsMiddleware, error)

func (*MetricsMiddleware) Middleware

func (m *MetricsMiddleware) Middleware(next http.Handler) http.Handler

type Middleware

type Middleware interface {
	Middleware(next http.Handler) http.Handler
}

Middleware defines an authentication middleware

func NewInitRequiredMiddleware

func NewInitRequiredMiddleware(store common.Store) (Middleware, error)

NewjwtMiddleware returns a populated jwtMiddleware

func NewInstanceMiddleware

func NewInstanceMiddleware(store dbCommon.Store, cfg config.JWTAuth) (Middleware, error)

NewjwtMiddleware returns a populated jwtMiddleware

func NewUrlsRequiredMiddleware added in v0.1.5

func NewUrlsRequiredMiddleware(store common.Store) (Middleware, error)

func NewjwtMiddleware

func NewjwtMiddleware(store dbCommon.Store, cfg config.JWTAuth) (Middleware, error)

NewjwtMiddleware returns a populated jwtMiddleware

Jump to

Keyboard shortcuts

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