middleware

package
v0.0.0-...-1573b19 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2025 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	IdentityRequestKey = &contextKey{"authnapi.Identity"}
	GetIdentity        = GetFromContext[authnapi.Identity](IdentityRequestKey)
)
View Source
var (
	PaginationRequestKey = &contextKey{"paginationRequest"}
	GetPaginationRequest = GetFromContext[PaginationRequest](PaginationRequestKey)
)
View Source
var (
	ErrWrongContext = errors.Unauthorized(reason, "Wrong context for middleware")
)
View Source
var SchemaCache sync.Map

Functions

func Authentication

func Authentication(authenticator authnapi.Authenticator) func(middleware.Handler) middleware.Handler

func ExtractMapField

func ExtractMapField(data map[string]interface{}, key string, opts ...ExtractOption) (map[string]interface{}, error)

Extracts a Map Field from another map

func ExtractStringField

func ExtractStringField(data map[string]interface{}, key string, opts ...ExtractOption) (string, error)

Extracts a String Field from a map

func GetFromContext

func GetFromContext[V any, I any](i I) func(context.Context) (*V, error)

func GetSchemaFromCache

func GetSchemaFromCache(cacheKey string) (string, error)

Retrieves schema from cache

func LoadCommonResourceDataSchema

func LoadCommonResourceDataSchema(resourceType string, baseSchemaDir string) (string, error)

Load Common Resource Data Schema

func LoadConfigFile

func LoadConfigFile(resourceDir string, resourceType string) (struct {
	ResourceType      string   `yaml:"resource_type"`
	ResourceReporters []string `yaml:"resource_reporters"`
}, error)

func LoadFromCache

func LoadFromCache(resourceType string) ([]string, error)

func LoadFromFilesystem

func LoadFromFilesystem(resourceType string) ([]string, error)

LoadValidReporters Takes the resource_type from the provided config.yaml and compares it to the defined reporter_types

func LoadResourceSchema

func LoadResourceSchema(resourceType string, reporterType string, dir string) (string, bool, error)

LoadResourceSchema finds the resources schema based on the directory structure of data/resources

func LoadSchemaCacheFromJSON

func LoadSchemaCacheFromJSON(filePath string) error

LoadSchemaCacheFromJSON loads schema cache from a JSON file

func LoadValidReporters

func LoadValidReporters(resourceType string) ([]string, error)

LoadValidReporters retrieves valid reporters for a given resource type. It either loads from the cache (JSON-based) or the filesystem (YAML-based).

func MarshalProtoToJSON

func MarshalProtoToJSON(msg proto.Message) ([]byte, error)

func NormalizeResourceType

func NormalizeResourceType(resourceType string) string

func Pagination

func Pagination(next http.Handler) http.Handler

Pagination is HTTP middleware that extracts pagination parameters from query string and makes them available in the request context.

func PreloadAllSchemas

func PreloadAllSchemas(resourceDir string) error

func PreloadAllSchemasFromFilesystem

func PreloadAllSchemasFromFilesystem(resourceDir string) error

func RemoveNulls

func RemoveNulls(m map[string]interface{}) map[string]interface{}

RemoveNulls recursively creates a new map with keys removed where the value is null. This function is safe for concurrent use as it does not modify the input map.

func UnmarshalJSONToMap

func UnmarshalJSONToMap(data []byte) (map[string]interface{}, error)

func ValidateCommonRepresentation

func ValidateCommonRepresentation(resourceType string, commonRepresentation map[string]interface{}) error

ValidateCommonRepresentation Validates the "common" field in ResourceRepresentations using a predefined schema.

func ValidateJSONSchema

func ValidateJSONSchema(schemaStr string, jsonData interface{}) error

func ValidateReportResourceJSON

func ValidateReportResourceJSON(msg proto.Message) error

func ValidateReporterRepresentation

func ValidateReporterRepresentation(resourceType string, reporterType string, reporterRepresentation map[string]interface{}) error

Validates the reporter-specific representation against its schema based on resourceType and reporterType.

func ValidateResourceReporterCombination

func ValidateResourceReporterCombination(resourceType, reporterType string) error

func Validation

func Validation(validator protovalidate.Validator) middleware.Middleware

Types

type ExtractOption

type ExtractOption func(*extractConfig)

ExtractOption configures extraction behavior

func ValidateFieldExists

func ValidateFieldExists() ExtractOption

ValidateFieldExists makes the extraction fail if the field doesn't exist

type PagedResponse

type PagedResponse[R any] struct {
	PagedResponseMetadata
	Items []R `json:"items"`
}

PagedResponse represents a paginated response containing items and metadata.

type PagedResponseMetadata

type PagedResponseMetadata struct {
	Page  int   `json:"page"`
	Size  int   `json:"size"`
	Total int64 `json:"total"`
}

PagedResponseMetadata contains metadata for paginated responses including page number, size, and total count.

type PaginationRequest

type PaginationRequest struct {
	Page    int
	MaxSize int
	Filter  func(*gorm.DB) *gorm.DB
}

PaginationRequest contains the parameters needed for paginating database queries.

Jump to

Keyboard shortcuts

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