middleware

package
v0.1.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentTypeJSON

func ContentTypeJSON(next http.Handler) http.Handler

ContentTypeJSON sets the content type for requests to application/json

Types

type AccessType

type AccessType string

AccessType represents the various access types for a project

const (
	ReadAccess  AccessType = "read"
	WriteAccess AccessType = "write"
)

The various access types

type Auth

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

Auth implements the authorization functions

func NewAuth

func NewAuth(
	store sessions.Store,
	cookieName string,
	repo *repository.Repository,
) *Auth

NewAuth returns a new Auth instance

func (*Auth) BasicAuthenticate

func (auth *Auth) BasicAuthenticate(next http.Handler) http.Handler

BasicAuthenticate just checks that a user is logged in

func (*Auth) DoesUserHaveProjectAccess

func (auth *Auth) DoesUserHaveProjectAccess(
	next http.Handler,
	projLoc IDLocation,
	accessType AccessType,
) http.Handler

DoesUserHaveProjectAccess looks for a project_id parameter and checks that the user has access via the specified accessType

func (*Auth) DoesUserHaveServiceAccountAccess

func (auth *Auth) DoesUserHaveServiceAccountAccess(
	next http.Handler,
	projLoc IDLocation,
	saLoc IDLocation,
) http.Handler

DoesUserHaveServiceAccountAccess looks for a project_id parameter and a service_account_id parameter, and verifies that the service account belongs to the project

func (*Auth) DoesUserIDMatch

func (auth *Auth) DoesUserIDMatch(next http.Handler, loc IDLocation) http.Handler

DoesUserIDMatch checks the id URL parameter and verifies that it matches the one stored in the session

type IDLocation

type IDLocation uint

IDLocation represents the location of the ID to use for authentication

const (
	// URLParam location looks for a parameter in the URL endpoint
	URLParam IDLocation = iota
	// BodyParam location looks for a parameter in the body
	BodyParam
	// QueryParam location looks for a parameter in the query string
	QueryParam
)

Jump to

Keyboard shortcuts

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