providers

package
v0.0.12 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DaysSince

func DaysSince(t time.Time) int

DaysSince returns the number of days since the given time

func GenericResourceAttrs added in v0.0.3

func GenericResourceAttrs(resourceType, resourceID, owner, orgID string) map[string]interface{}

GenericResourceAttrs creates a basic resource attributes map

func HoursSince

func HoursSince(t time.Time) int

HoursSince returns the number of hours since the given time

func IPInRange

func IPInRange(ip string, cidrs []string) bool

IPInRange checks if an IP address is in any of the given CIDR ranges

func InTimeRange

func InTimeRange(now time.Time, start, end string) bool

InTimeRange checks if current time is between start and end times (24-hour format) start and end are in format "HH:MM" (e.g., "09:00", "17:00")

func IsWeekday

func IsWeekday(t time.Time) bool

IsWeekday returns true if the given time is a weekday

func ResourceWithOwnership added in v0.0.3

func ResourceWithOwnership(resourceType, resourceID, ownerID, orgID, teamID string, isPublic bool) map[string]interface{}

ResourceWithOwnership creates resource attributes with ownership info

Types

type AuthsomeMemberService added in v0.0.3

type AuthsomeMemberService interface {
	// GetUserMemberships returns all organizations a user is a member of
	GetUserMembershipsForUser(ctx context.Context, userID xid.ID) ([]AuthsomeMembership, error)
}

AuthsomeMemberService defines the interface for organization member operations

type AuthsomeMembership added in v0.0.3

type AuthsomeMembership interface {
	GetOrganizationID() xid.ID
	GetRole() string
	GetStatus() string
}

AuthsomeMembership represents a user's membership in an organization

type AuthsomeRBACService added in v0.0.3

type AuthsomeRBACService interface {
	// GetUserRoles gets the roles for a user in an organization
	GetUserRoles(ctx context.Context, userID, orgID xid.ID) ([]string, error)

	// GetUserPermissions gets the permissions for a user in an organization
	GetUserPermissions(ctx context.Context, userID, orgID xid.ID) ([]string, error)
}

AuthsomeRBACService defines the interface for RBAC operations

type AuthsomeResourceAttributeProvider added in v0.0.3

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

AuthsomeResourceAttributeProvider provides resource attributes using the registry

func NewAuthsomeResourceAttributeProvider added in v0.0.3

func NewAuthsomeResourceAttributeProvider(cfg AuthsomeResourceProviderConfig) *AuthsomeResourceAttributeProvider

NewAuthsomeResourceAttributeProvider creates a new AuthSome resource attribute provider

func (*AuthsomeResourceAttributeProvider) GetAttributes added in v0.0.3

func (p *AuthsomeResourceAttributeProvider) GetAttributes(ctx context.Context, key string) (map[string]interface{}, error)

GetAttributes fetches resource attributes key format: "resourceType:resourceID" (e.g., "document:abc123xyz")

func (*AuthsomeResourceAttributeProvider) GetBatchAttributes added in v0.0.3

func (p *AuthsomeResourceAttributeProvider) GetBatchAttributes(ctx context.Context, keys []string) (map[string]map[string]interface{}, error)

GetBatchAttributes fetches attributes for multiple resources

func (*AuthsomeResourceAttributeProvider) GetRegistry added in v0.0.3

GetRegistry returns the resource registry for external registration

func (*AuthsomeResourceAttributeProvider) Name added in v0.0.3

Name returns the provider name

type AuthsomeResourceProviderConfig added in v0.0.3

type AuthsomeResourceProviderConfig struct {
	Registry      *ResourceProviderRegistry
	DefaultLoader ResourceLoader
}

AuthsomeResourceProviderConfig configures the resource provider

type AuthsomeUser added in v0.0.3

type AuthsomeUser interface {
	GetID() xid.ID
	GetAppID() xid.ID
	GetEmail() string
	GetName() string
	GetEmailVerified() bool
	GetUsername() string
	GetImage() string
	GetCreatedAt() string
}

AuthsomeUser represents user data from the core user service

type AuthsomeUserAttributeProvider added in v0.0.3

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

AuthsomeUserAttributeProvider provides user attributes from AuthSome services

func NewAuthsomeUserAttributeProvider added in v0.0.3

func NewAuthsomeUserAttributeProvider(cfg AuthsomeUserProviderConfig) *AuthsomeUserAttributeProvider

NewAuthsomeUserAttributeProvider creates a new AuthSome user attribute provider

func (*AuthsomeUserAttributeProvider) GetAttributes added in v0.0.3

func (p *AuthsomeUserAttributeProvider) GetAttributes(ctx context.Context, key string) (map[string]interface{}, error)

GetAttributes fetches user attributes by user ID The key format can be:

  • "userId" - just the user ID (uses default org for roles)
  • "userId:orgId" - user ID with specific organization context

func (*AuthsomeUserAttributeProvider) GetBatchAttributes added in v0.0.3

func (p *AuthsomeUserAttributeProvider) GetBatchAttributes(ctx context.Context, keys []string) (map[string]map[string]interface{}, error)

GetBatchAttributes fetches attributes for multiple users

func (*AuthsomeUserAttributeProvider) Name added in v0.0.3

Name returns the provider name

type AuthsomeUserProviderConfig added in v0.0.3

type AuthsomeUserProviderConfig struct {
	UserService   AuthsomeUserService
	MemberService AuthsomeMemberService
	RBACService   AuthsomeRBACService
	DefaultOrgID  *xid.ID
}

AuthsomeUserProviderConfig configures the provider

type AuthsomeUserService added in v0.0.3

type AuthsomeUserService interface {
	// FindByID finds a user by ID
	FindByID(ctx context.Context, id xid.ID) (AuthsomeUser, error)
}

AuthsomeUserService defines the interface for the AuthSome user service

type ContextAttributeProvider

type ContextAttributeProvider struct {
}

ContextAttributeProvider provides request context attributes

func NewContextAttributeProvider

func NewContextAttributeProvider() *ContextAttributeProvider

NewContextAttributeProvider creates a new context attribute provider

func (*ContextAttributeProvider) GetAttributes

func (p *ContextAttributeProvider) GetAttributes(ctx context.Context, key string) (map[string]interface{}, error)

GetAttributes returns the request context attributes key is ignored as context is typically set directly in the evaluation context

func (*ContextAttributeProvider) GetBatchAttributes

func (p *ContextAttributeProvider) GetBatchAttributes(ctx context.Context, keys []string) (map[string]map[string]interface{}, error)

GetBatchAttributes returns context attributes for multiple keys For context, batch operations don't make much sense, so we return individual contexts

func (*ContextAttributeProvider) Name

func (p *ContextAttributeProvider) Name() string

Name returns the provider name

type DeviceInfo

type DeviceInfo struct {
	Type      string `json:"type"`    // mobile, desktop, tablet
	OS        string `json:"os"`      // iOS, Android, Windows, macOS, Linux
	Browser   string `json:"browser"` // Chrome, Firefox, Safari, etc.
	IsMobile  bool   `json:"is_mobile"`
	IsDesktop bool   `json:"is_desktop"`
}

DeviceInfo contains device-specific information

type Geolocation

type Geolocation struct {
	Country   string  `json:"country"`
	Region    string  `json:"region"`
	City      string  `json:"city"`
	Latitude  float64 `json:"latitude"`
	Longitude float64 `json:"longitude"`
	Timezone  string  `json:"timezone"`
}

Geolocation contains geographic information about the request

type MemberServiceWrapper added in v0.0.3

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

MemberServiceWrapper wraps the actual member service

func NewMemberServiceWrapper added in v0.0.3

func NewMemberServiceWrapper(getMemberships func(ctx context.Context, userID xid.ID) ([]AuthsomeMembership, error)) *MemberServiceWrapper

NewMemberServiceWrapper creates a wrapper for member service

func (*MemberServiceWrapper) GetUserMembershipsForUser added in v0.0.3

func (w *MemberServiceWrapper) GetUserMembershipsForUser(ctx context.Context, userID xid.ID) ([]AuthsomeMembership, error)

type MembershipAdapter added in v0.0.3

type MembershipAdapter struct {
	OrganizationID xid.ID
	Role           string
	Status         string
}

MembershipAdapter adapts membership data to AuthsomeMembership interface

func (*MembershipAdapter) GetOrganizationID added in v0.0.3

func (m *MembershipAdapter) GetOrganizationID() xid.ID

func (*MembershipAdapter) GetRole added in v0.0.3

func (m *MembershipAdapter) GetRole() string

func (*MembershipAdapter) GetStatus added in v0.0.3

func (m *MembershipAdapter) GetStatus() string

type MockResourceService

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

MockResourceService provides a mock implementation for testing

func NewMockResourceService

func NewMockResourceService() *MockResourceService

NewMockResourceService creates a new mock resource service

func (*MockResourceService) AddResource

func (m *MockResourceService) AddResource(resource *Resource)

AddResource adds a resource to the mock service

func (*MockResourceService) GetResource

func (m *MockResourceService) GetResource(ctx context.Context, resourceType, resourceID string) (*Resource, error)

GetResource fetches a resource by type and ID

func (*MockResourceService) GetResources

func (m *MockResourceService) GetResources(ctx context.Context, requests []ResourceRequest) ([]*Resource, error)

GetResources fetches multiple resources

type MockUserService

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

MockUserService provides a mock implementation for testing

func NewMockUserService

func NewMockUserService() *MockUserService

NewMockUserService creates a new mock user service

func (*MockUserService) AddUser

func (m *MockUserService) AddUser(user *User)

AddUser adds a user to the mock service

func (*MockUserService) GetUser

func (m *MockUserService) GetUser(ctx context.Context, userID string) (*User, error)

GetUser fetches a user by ID

func (*MockUserService) GetUsers

func (m *MockUserService) GetUsers(ctx context.Context, userIDs []string) ([]*User, error)

GetUsers fetches multiple users by IDs

type OrganizationResourceLoader added in v0.0.3

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

OrganizationResourceLoader loads organization resources

func NewOrganizationResourceLoader added in v0.0.3

func NewOrganizationResourceLoader(getOrg func(ctx context.Context, orgID xid.ID) (map[string]interface{}, error)) *OrganizationResourceLoader

NewOrganizationResourceLoader creates an organization resource loader

func (*OrganizationResourceLoader) LoadResource added in v0.0.3

func (l *OrganizationResourceLoader) LoadResource(ctx context.Context, resourceID string) (map[string]interface{}, error)

func (*OrganizationResourceLoader) LoadResources added in v0.0.3

func (l *OrganizationResourceLoader) LoadResources(ctx context.Context, resourceIDs []string) (map[string]map[string]interface{}, error)

type RBACServiceWrapper added in v0.0.3

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

RBACServiceWrapper wraps the actual RBAC service

func NewRBACServiceWrapper added in v0.0.3

func NewRBACServiceWrapper(
	getUserRoles func(ctx context.Context, userID, orgID xid.ID) ([]string, error),
	getUserPermissions func(ctx context.Context, userID, orgID xid.ID) ([]string, error),
) *RBACServiceWrapper

NewRBACServiceWrapper creates a wrapper for RBAC service

func (*RBACServiceWrapper) GetUserPermissions added in v0.0.3

func (w *RBACServiceWrapper) GetUserPermissions(ctx context.Context, userID, orgID xid.ID) ([]string, error)

func (*RBACServiceWrapper) GetUserRoles added in v0.0.3

func (w *RBACServiceWrapper) GetUserRoles(ctx context.Context, userID, orgID xid.ID) ([]string, error)

type RequestContext

type RequestContext struct {
	IP          string                 `json:"ip"`
	UserAgent   string                 `json:"user_agent"`
	Method      string                 `json:"method"`
	Path        string                 `json:"path"`
	Timestamp   time.Time              `json:"timestamp"`
	Geolocation *Geolocation           `json:"geolocation,omitempty"`
	Device      *DeviceInfo            `json:"device,omitempty"`
	Headers     map[string]string      `json:"headers,omitempty"`
	Metadata    map[string]interface{} `json:"metadata,omitempty"`
}

RequestContext contains ephemeral request-specific data

type Resource

type Resource struct {
	ID           string                 `json:"id"`
	Type         string                 `json:"type"`
	Name         string                 `json:"name"`
	Owner        string                 `json:"owner"`
	OrgID        string                 `json:"org_id"`
	TeamID       string                 `json:"team_id"`
	ProjectID    string                 `json:"project_id"`
	Visibility   string                 `json:"visibility"` // public, private, team, org
	Status       string                 `json:"status"`     // active, archived, deleted
	Tags         []string               `json:"tags"`
	Metadata     map[string]interface{} `json:"metadata"`
	CreatedAt    string                 `json:"created_at"`
	UpdatedAt    string                 `json:"updated_at"`
	CreatedBy    string                 `json:"created_by"`
	Confidential string                 `json:"confidential"` // public, internal, confidential, secret
}

Resource represents resource data for attribute resolution

type ResourceAttributeProvider

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

ResourceAttributeProvider fetches resource attributes from resource services

func NewResourceAttributeProvider

func NewResourceAttributeProvider(resourceService ResourceService) *ResourceAttributeProvider

NewResourceAttributeProvider creates a new resource attribute provider

func (*ResourceAttributeProvider) GetAttributes

func (p *ResourceAttributeProvider) GetAttributes(ctx context.Context, key string) (map[string]interface{}, error)

GetAttributes fetches resource attributes key is expected to be in format "type:id" (e.g., "document:123")

func (*ResourceAttributeProvider) GetBatchAttributes

func (p *ResourceAttributeProvider) GetBatchAttributes(ctx context.Context, keys []string) (map[string]map[string]interface{}, error)

GetBatchAttributes fetches attributes for multiple resources

func (*ResourceAttributeProvider) Name

Name returns the provider name

type ResourceLoader added in v0.0.3

type ResourceLoader interface {
	// LoadResource loads a resource by ID and returns its attributes
	LoadResource(ctx context.Context, resourceID string) (map[string]interface{}, error)

	// LoadResources loads multiple resources by IDs
	LoadResources(ctx context.Context, resourceIDs []string) (map[string]map[string]interface{}, error)
}

ResourceLoader defines the interface for loading a specific resource type

type ResourceLoaderFunc added in v0.0.3

type ResourceLoaderFunc func(ctx context.Context, resourceID string) (map[string]interface{}, error)

ResourceLoaderFunc is a function type that implements ResourceLoader

func (ResourceLoaderFunc) LoadResource added in v0.0.3

func (f ResourceLoaderFunc) LoadResource(ctx context.Context, resourceID string) (map[string]interface{}, error)

func (ResourceLoaderFunc) LoadResources added in v0.0.3

func (f ResourceLoaderFunc) LoadResources(ctx context.Context, resourceIDs []string) (map[string]map[string]interface{}, error)

type ResourceProviderRegistry added in v0.0.3

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

ResourceProviderRegistry manages resource loaders for different resource types

func NewResourceProviderRegistry added in v0.0.3

func NewResourceProviderRegistry() *ResourceProviderRegistry

NewResourceProviderRegistry creates a new resource provider registry

func (*ResourceProviderRegistry) Get added in v0.0.3

func (r *ResourceProviderRegistry) Get(resourceType string) (ResourceLoader, bool)

Get returns the resource loader for a specific type

func (*ResourceProviderRegistry) List added in v0.0.3

func (r *ResourceProviderRegistry) List() []string

List returns all registered resource types

func (*ResourceProviderRegistry) Register added in v0.0.3

func (r *ResourceProviderRegistry) Register(resourceType string, loader ResourceLoader)

Register registers a resource loader for a specific resource type

func (*ResourceProviderRegistry) RegisterFunc added in v0.0.3

func (r *ResourceProviderRegistry) RegisterFunc(resourceType string, fn ResourceLoaderFunc)

RegisterFunc registers a function as a resource loader

type ResourceRequest

type ResourceRequest struct {
	Type string
	ID   string
}

ResourceRequest represents a request for a specific resource

type ResourceService

type ResourceService interface {
	// GetResource fetches a resource by type and ID
	GetResource(ctx context.Context, resourceType, resourceID string) (*Resource, error)

	// GetResources fetches multiple resources
	GetResources(ctx context.Context, requests []ResourceRequest) ([]*Resource, error)
}

ResourceService defines the interface for fetching resource data This should be implemented by your application's resource services

type User

type User struct {
	ID            string                 `json:"id"`
	Email         string                 `json:"email"`
	Name          string                 `json:"name"`
	Roles         []string               `json:"roles"`
	Groups        []string               `json:"groups"`
	OrgID         string                 `json:"org_id"`
	Department    string                 `json:"department"`
	Permissions   []string               `json:"permissions"`
	Metadata      map[string]interface{} `json:"metadata"`
	CreatedAt     string                 `json:"created_at"`
	EmailVerified bool                   `json:"email_verified"`
	Active        bool                   `json:"active"`
}

User represents user data for attribute resolution

type UserAdapter added in v0.0.3

type UserAdapter struct {
	ID            xid.ID
	AppID         xid.ID
	Email         string
	Name          string
	EmailVerified bool
	Username      string
	Image         string
	CreatedAt     string
}

UserAdapter adapts the core user.User to AuthsomeUser interface

func (*UserAdapter) GetAppID added in v0.0.3

func (u *UserAdapter) GetAppID() xid.ID

func (*UserAdapter) GetCreatedAt added in v0.0.3

func (u *UserAdapter) GetCreatedAt() string

func (*UserAdapter) GetEmail added in v0.0.3

func (u *UserAdapter) GetEmail() string

func (*UserAdapter) GetEmailVerified added in v0.0.3

func (u *UserAdapter) GetEmailVerified() bool

func (*UserAdapter) GetID added in v0.0.3

func (u *UserAdapter) GetID() xid.ID

func (*UserAdapter) GetImage added in v0.0.3

func (u *UserAdapter) GetImage() string

func (*UserAdapter) GetName added in v0.0.3

func (u *UserAdapter) GetName() string

func (*UserAdapter) GetUsername added in v0.0.3

func (u *UserAdapter) GetUsername() string

type UserAttributeProvider

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

UserAttributeProvider fetches user attributes from the user service

func NewUserAttributeProvider

func NewUserAttributeProvider(userService UserService) *UserAttributeProvider

NewUserAttributeProvider creates a new user attribute provider

func (*UserAttributeProvider) GetAttributes

func (p *UserAttributeProvider) GetAttributes(ctx context.Context, key string) (map[string]interface{}, error)

GetAttributes fetches user attributes by user ID

func (*UserAttributeProvider) GetBatchAttributes

func (p *UserAttributeProvider) GetBatchAttributes(ctx context.Context, keys []string) (map[string]map[string]interface{}, error)

GetBatchAttributes fetches attributes for multiple users

func (*UserAttributeProvider) Name

func (p *UserAttributeProvider) Name() string

Name returns the provider name

type UserResourceLoader added in v0.0.3

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

UserResourceLoader loads user resources (for user-as-resource scenarios)

func NewUserResourceLoader added in v0.0.3

func NewUserResourceLoader(getUser func(ctx context.Context, userID xid.ID) (map[string]interface{}, error)) *UserResourceLoader

NewUserResourceLoader creates a user resource loader

func (*UserResourceLoader) LoadResource added in v0.0.3

func (l *UserResourceLoader) LoadResource(ctx context.Context, resourceID string) (map[string]interface{}, error)

func (*UserResourceLoader) LoadResources added in v0.0.3

func (l *UserResourceLoader) LoadResources(ctx context.Context, resourceIDs []string) (map[string]map[string]interface{}, error)

type UserService

type UserService interface {
	// GetUser fetches a user by ID
	GetUser(ctx context.Context, userID string) (*User, error)

	// GetUsers fetches multiple users by IDs
	GetUsers(ctx context.Context, userIDs []string) ([]*User, error)
}

UserService defines the interface for fetching user data This should be implemented by AuthSome's user service

type UserServiceWrapper added in v0.0.3

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

UserServiceWrapper wraps the actual core user service

func NewUserServiceWrapper added in v0.0.3

func NewUserServiceWrapper(findByID func(ctx context.Context, id xid.ID) (AuthsomeUser, error)) *UserServiceWrapper

NewUserServiceWrapper creates a wrapper for user service

func (*UserServiceWrapper) FindByID added in v0.0.3

func (w *UserServiceWrapper) FindByID(ctx context.Context, id xid.ID) (AuthsomeUser, error)

Jump to

Keyboard shortcuts

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