middleware

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package middleware provides middleware for the Ocular API. It includes authentication, authorization, and other middleware

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AuthorizeIdentity

func AuthorizeIdentity(authorizers ...identities.Authorizer) gin.HandlerFunc

AuthorizeIdentity is a middleware that checks if the user is authorized to access the resource. It will check if the identities.Identity from the request is authorized by calling each identity.Authorizer provided. If any of the authorizers return true, the user is authorized.

func BearerAuthenticator

func BearerAuthenticator() gin.HandlerFunc

BearerAuthenticator is a gin middleware that authenticates the user using a bearer token. It checks the "Authorization" header for a bearer token and verifies it. If the token is valid, it sets the "identity" key in the context with the user information. If the token is invalid, it returns a 401 Unauthorized response.

func CertificateAuthenticator

func CertificateAuthenticator() gin.HandlerFunc

CertificateAuthenticator is a gin middleware that authenticates the user using a client certificate. It checks the TLS connection for client certificates and verifies them.

func ContextAssigner

func ContextAssigner(manager cluster.ContextManager) gin.HandlerFunc

ContextAssigner is a gin middleware that assigns the cluster context to the request context. It checks the "X-ClusterContext-Name" header for the context name. If the header is not set, it will use the default context if enabled. The context assigned is the one that is used for authorization and for interacting with the cluster.

func GetClusterContext

func GetClusterContext(c context.Context) (cluster.Context, bool)

GetClusterContext retrieves the cluster context from the request context.

func GetIdentity

func GetIdentity(c *gin.Context) (identities.Identity, bool)

GetIdentity retrieves the identity from the context.

func MustClusterContext

func MustClusterContext(c *gin.Context) cluster.Context

MustClusterContext retrieves the cluster context from the request context. It panics if the context is not found or is not of type cluster.Context.

func SetClusterContext

func SetClusterContext(c *gin.Context, ctx cluster.Context)

SetClusterContext sets the cluster context in the request context.

Types

This section is empty.

Jump to

Keyboard shortcuts

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