types

package
v0.11.6 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2025 License: BSD-3-Clause-Clear Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	FailureStrategyFailFast = "fail-fast"
	FailureStrategyContinue = "continue"
)

Constants for failure strategy values

View Source
const (
	EntityTypeSubject     = "subject"
	EntityTypeEnvironment = "environment"
)

Constants for entity type values

View Source
const JWTClaimsContextKey contextKey = "jwt_claims"

JWTClaimsContextKey is the typed context key for JWT claims

Variables

This section is empty.

Functions

func NewConfigurationError

func NewConfigurationError(message string, context map[string]interface{}) error

Common error constructors

func NewHealthError

func NewHealthError(message string, context map[string]interface{}) error

func NewJWTError

func NewJWTError(message string, context map[string]interface{}) error

func NewMappingError

func NewMappingError(message string, context map[string]interface{}) error

func NewProviderError

func NewProviderError(message string, context map[string]interface{}) error

func NewStrategyError

func NewStrategyError(message string, context map[string]interface{}) error

Types

type EntityResult

type EntityResult struct {
	// OriginalID is the entity ID from the request
	OriginalID string

	// Claims contains the mapped claims (field-agnostic)
	Claims map[string]interface{}

	// Metadata contains processing metadata
	Metadata map[string]interface{}
}

EntityResult represents the final result after output mapping

type ErrorType

type ErrorType string

ErrorType represents different categories of errors

const (
	ErrorTypeConfiguration ErrorType = "configuration"
	ErrorTypeProvider      ErrorType = "provider"
	ErrorTypeStrategy      ErrorType = "strategy"
	ErrorTypeMapping       ErrorType = "mapping"
	ErrorTypeJWT           ErrorType = "jwt"
	ErrorTypeHealth        ErrorType = "health"
)

type HealthCheckConfig

type HealthCheckConfig struct {
	Enabled        bool                  `mapstructure:"enabled"`
	Interval       time.Duration         `mapstructure:"interval"`
	ProviderChecks []ProviderHealthCheck `mapstructure:"provider_checks"`
}

HealthCheckConfig defines health check settings

type InputMapping

type InputMapping struct {
	JWTClaim  string `mapstructure:"jwt_claim"`
	Parameter string `mapstructure:"parameter"`
	Required  bool   `mapstructure:"required"`
	Default   string `mapstructure:"default"`
}

InputMapping defines how to extract parameters from JWT for queries

type JWTClaimCondition

type JWTClaimCondition struct {
	Claim    string   `mapstructure:"claim"`
	Operator string   `mapstructure:"operator"` // "exists", "equals", "contains", "regex"
	Values   []string `mapstructure:"values"`
}

JWTClaimCondition defines a condition on a JWT claim

type JWTClaims

type JWTClaims map[string]interface{}

JWTClaims represents JWT claims for strategy matching

type LDAPSearchConfig

type LDAPSearchConfig struct {
	BaseDN     string   `mapstructure:"base_dn"`
	Filter     string   `mapstructure:"filter"`
	Scope      string   `mapstructure:"scope"`
	Attributes []string `mapstructure:"attributes"`
}

LDAPSearchConfig defines LDAP search parameters

type Mapper

type Mapper interface {
	// ExtractParameters extracts parameters from JWT claims using strategy's input mapping
	ExtractParameters(jwtClaims JWTClaims, inputMapping []InputMapping) (map[string]interface{}, error)

	// TransformResults transforms provider results using strategy's output mapping
	TransformResults(rawData map[string]interface{}, outputMapping []OutputMapping) (map[string]interface{}, error)

	// ValidateInputMapping validates that input mapping is compatible with this provider type
	ValidateInputMapping(inputMapping []InputMapping) error

	// ValidateOutputMapping validates that output mapping is compatible with this provider type
	ValidateOutputMapping(outputMapping []OutputMapping) error

	// GetSupportedTransformations returns provider-specific transformations
	GetSupportedTransformations() []string
}

Mapper defines the interface for mapping JWT claims to provider parameters and transforming provider results back to standardized claims

type MappingStrategy

type MappingStrategy struct {
	Name         string             `mapstructure:"name"`
	Provider     string             `mapstructure:"provider"`
	Conditions   StrategyConditions `mapstructure:"conditions"`
	InputMapping []InputMapping     `mapstructure:"input_mapping"`

	// Strategy behavior configuration
	EntityType string `mapstructure:"entity_type"` // "subject" or "environment"

	// Provider-specific configuration
	Query      string            `mapstructure:"query"`            // SQL query
	LDAPSearch *LDAPSearchConfig `mapstructure:"ldap_search"`      // LDAP search config
	RedisOps   *RedisOperations  `mapstructure:"redis_operations"` // Future: Redis operations

	// Field-agnostic output mapping
	OutputMapping []OutputMapping `mapstructure:"output_mapping"`
}

MappingStrategy defines how to resolve entities for specific JWT contexts

type MultiStrategyConfig

type MultiStrategyConfig struct {
	// Providers defines the available data providers
	Providers map[string]ProviderConfig `mapstructure:"providers"`

	// MappingStrategies defines the strategies for entity resolution
	MappingStrategies []MappingStrategy `mapstructure:"mapping_strategies"`

	// FailureStrategy controls how the service handles strategy failures globally
	FailureStrategy string `mapstructure:"failure_strategy"` // "fail-fast" (default) or "continue"

	// HealthCheck configuration
	HealthCheck HealthCheckConfig `mapstructure:"health_check"`
}

MultiStrategyConfig is the main configuration for the multi-strategy ERS

type MultiStrategyError

type MultiStrategyError struct {
	Type     ErrorType              `json:"type"`
	Message  string                 `json:"message"`
	Context  map[string]interface{} `json:"context,omitempty"`
	Original error                  `json:"original,omitempty"`
}

MultiStrategyError represents an error in the multi-strategy ERS

func NewMultiStrategyError

func NewMultiStrategyError(errorType ErrorType, message string, context map[string]interface{}) *MultiStrategyError

NewMultiStrategyError creates a new multi-strategy error

func WrapMultiStrategyError

func WrapMultiStrategyError(errorType ErrorType, message string, original error, context map[string]interface{}) *MultiStrategyError

WrapMultiStrategyError wraps an existing error with multi-strategy context

func (*MultiStrategyError) Error

func (e *MultiStrategyError) Error() string

Error implements the error interface

func (*MultiStrategyError) Unwrap

func (e *MultiStrategyError) Unwrap() error

Unwrap returns the original error for error wrapping

type OutputMapping

type OutputMapping struct {
	// Source field names (provider-specific)
	SourceColumn    string `mapstructure:"source_column"`    // SQL column name
	SourceAttribute string `mapstructure:"source_attribute"` // LDAP attribute name
	SourceClaim     string `mapstructure:"source_claim"`     // JWT claim name
	SourceKey       string `mapstructure:"source_key"`       // Redis key name

	// Target claim name (field-agnostic)
	ClaimName string `mapstructure:"claim_name"`

	// Optional transformation
	Transformation string `mapstructure:"transformation"` // "array", "csv_to_array", "ldap_dn_to_cn_array", etc.
}

OutputMapping defines how to map provider results to claims (field-agnostic)

type Provider

type Provider interface {
	// Name returns the provider instance name
	Name() string

	// Type returns the provider type (sql, ldap, claims, etc.)
	Type() string

	// ResolveEntity executes the strategy against this provider
	ResolveEntity(ctx context.Context, strategy MappingStrategy, params map[string]interface{}) (*RawResult, error)

	// HealthCheck verifies the provider is healthy
	HealthCheck(ctx context.Context) error

	// GetMapper returns the provider's mapper implementation
	GetMapper() Mapper

	// Close cleans up provider resources
	Close() error
}

Provider interface that all backend providers must implement

type ProviderConfig

type ProviderConfig struct {
	Type       string                 `mapstructure:"type"` // "sql", "ldap", "claims"
	Connection map[string]interface{} `mapstructure:"connection"`
}

ProviderConfig defines a data provider configuration

type ProviderHealthCheck

type ProviderHealthCheck struct {
	Provider string `mapstructure:"provider"`
	Query    string `mapstructure:"query"`     // SQL health check query
	BindTest bool   `mapstructure:"bind_test"` // LDAP bind test
	Ping     bool   `mapstructure:"ping"`      // Redis ping
}

ProviderHealthCheck defines health check for a specific provider

type RawResult

type RawResult struct {
	// Data contains the raw field data from the provider
	Data map[string]interface{}

	// Metadata contains provider-specific metadata
	Metadata map[string]interface{}
}

RawResult represents the raw result from a provider before output mapping

type RedisOperations

type RedisOperations struct {
	Get string `mapstructure:"get"`
	TTL string `mapstructure:"ttl"`
}

RedisOperations defines Redis operations (future enhancement)

type StrategyConditions

type StrategyConditions struct {
	JWTClaims []JWTClaimCondition `mapstructure:"jwt_claims"`
}

StrategyConditions define when this strategy should be used

Jump to

Keyboard shortcuts

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