handler

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout is the maximum time to process a request
	DefaultTimeout = 10 * time.Second

	// MaxTokenLength is the maximum allowed length for a JWT token
	MaxTokenLength = 16384 // 16KB

	// MaxRoleLength is the maximum allowed length for role ARN
	MaxRoleLength = 2048 // 2KB
)

Constants for handler configuration

View Source
const (
	RequestIDContextKey contextKey = "requestId"
	StartTimeContextKey contextKey = "startTime"
	SourceIPContextKey  contextKey = "sourceIp"
	UserAgentContextKey contextKey = "userAgent"
)

Variables

View Source
var (
	ErrEmptyToken          = errors.New("token is empty")
	ErrTokenTooLarge       = errors.New("token exceeds maximum allowed size")
	ErrEmptyRole           = errors.New("role is empty")
	ErrRoleTooLarge        = errors.New("role exceeds maximum allowed size")
	ErrInvalidJSON         = errors.New("invalid JSON in request body")
	ErrSessionPolicyAccess = errors.New("failed to access session policy")
	ErrRoleNotPermitted    = errors.New("role not allowed for repository or doesn't meet constraints")
	ErrAssumeRoleFailed    = errors.New("failed to assume the requested role")
)

Custom error types for more precise error reporting

View Source
var (
	// Basic validation that the role looks like an ARN
	// Check if the role ARN has a valid AWS partition prefix
	ValidPrefixes = []string{
		"arn:aws:iam::",
		"arn:aws-us-gov:iam::",
		"arn:aws-cn:iam::",
	}

	// ResponseHeaders common headers to include in all API responses
	ResponseHeaders = map[string]string{
		"Content-Type": "application/json",
	}
)

Functions

func ValidateRequestData

func ValidateRequestData(token, role string) error

ValidateRequestData validates common request data fields

Types

type AwsApiGateway

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

AwsApiGateway handles AWS API Gateway proxy integration requests

func NewAwsApiGateway

func NewAwsApiGateway(cfg *config.Config, consumer aws.AwsConsumerInterface, validator validator.TokenValidatorInterface) *AwsApiGateway

NewAwsApiGateway creates a new API Gateway handler

func NewAwsApiGatewayFromBootstrap

func NewAwsApiGatewayFromBootstrap(bootstrap *Bootstrap) *AwsApiGateway

NewAwsApiGatewayFromBootstrap creates a new API Gateway handler using bootstrap

func (*AwsApiGateway) Handler

Handler is the Lambda function interface for API Gateway

type AwsApplicationLoadBalancer

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

AwsApplicationLoadBalancer handles AWS Application Load Balancer requests

func NewAwsApplicationLoadBalancer

func NewAwsApplicationLoadBalancer(cfg *config.Config, consumer aws.AwsConsumerInterface, validator validator.TokenValidatorInterface) *AwsApplicationLoadBalancer

NewAwsApplicationLoadBalancer creates a new Application Load Balancer handler

func NewAwsApplicationLoadBalancerFromBootstrap

func NewAwsApplicationLoadBalancerFromBootstrap(bootstrap *Bootstrap) *AwsApplicationLoadBalancer

NewAwsApplicationLoadBalancerFromBootstrap creates a new ALB handler using bootstrap

func (*AwsApplicationLoadBalancer) Handler

Handler is the Lambda function interface for Application Load Balancer

type AwsLambdaUrl

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

AwsLambdaUrl handles AWS Lambda URL requests

func NewAwsLambdaUrl

func NewAwsLambdaUrl(cfg *config.Config, consumer aws.AwsConsumerInterface, validator validator.TokenValidatorInterface) *AwsLambdaUrl

NewAwsLambdaUrl creates a new Lambda URL handler

func NewAwsLambdaUrlFromBootstrap

func NewAwsLambdaUrlFromBootstrap(bootstrap *Bootstrap) *AwsLambdaUrl

NewAwsLambdaUrlFromBootstrap creates a new Lambda URL handler using bootstrap

func (*AwsLambdaUrl) Handler

Handler is the Lambda function interface for Lambda URLs

type Bootstrap

type Bootstrap struct {
	Config    *config.Config
	Consumer  aws.AwsConsumerInterface
	Validator validator.TokenValidatorInterface
	Cache     cache.Cache
	S3Logger  *s3logger.S3Logger
	Logger    *slog.Logger
	LogBuffer *bytes.Buffer
}

Bootstrap contains all the initialized components needed by handlers

func NewBootstrap

func NewBootstrap() (*Bootstrap, error)

NewBootstrap initializes all common components needed by Lambda handlers

func (*Bootstrap) Cleanup

func (b *Bootstrap) Cleanup()

Cleanup handles cleanup operations for the bootstrap components

type RequestData

type RequestData struct {
	Token string `json:"token"` // The JWT token to be validated
	Role  string `json:"role"`  // The role to be assumed
}

RequestData is the request format expected by the Lambda

func ParseRequestBody

func ParseRequestBody(body string) (*RequestData, error)

ParseRequestBody parses and validates JSON request body into RequestData

type RequestProcessor

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

RequestProcessor contains the core business logic for processing authentication requests

func NewRequestProcessor

func NewRequestProcessor(cfg *config.Config, consumer aws.AwsConsumerInterface, validator validator.TokenValidatorInterface) *RequestProcessor

NewRequestProcessor creates a new instance of request processor

func (*RequestProcessor) ProcessRequest

func (r *RequestProcessor) ProcessRequest(ctx context.Context, requestData *RequestData, requestID string, log *slog.Logger) (*types.Credentials, error)

ProcessRequest contains the main business logic for processing requests

type Response

type Response struct {
	Success      bool   `json:"success"`
	StatusCode   int    `json:"statusCode,omitempty"`
	RequestID    string `json:"requestId"`
	ProcessingMS int64  `json:"processingMs,omitempty"`

	// For successful responses
	Message string `json:"message,omitempty"`
	Data    any    `json:"data,omitempty"`

	// For error responses
	ErrorCode    string `json:"errorCode,omitempty"`
	ErrorDetails string `json:"errorDetails,omitempty"`
}

Response represents a standardized API response

Jump to

Keyboard shortcuts

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