Resolve import cycles and migrate to chorus.services module path

This comprehensive refactoring addresses critical architectural issues:

IMPORT CYCLE RESOLUTION:
• pkg/crypto ↔ pkg/slurp/roles: Created pkg/security/access_levels.go
• pkg/ucxl → pkg/dht: Created pkg/storage/interfaces.go
• pkg/slurp/leader → pkg/election → pkg/slurp/storage: Moved types to pkg/election/interfaces.go

MODULE PATH MIGRATION:
• Changed from github.com/anthonyrawlins/bzzz to chorus.services/bzzz
• Updated all import statements across 115+ files
• Maintains compatibility while removing personal GitHub account dependency

TYPE SYSTEM IMPROVEMENTS:
• Resolved duplicate type declarations in crypto package
• Added missing type definitions (RoleStatus, TimeRestrictions, KeyStatus, KeyRotationResult)
• Proper interface segregation to prevent future cycles

ARCHITECTURAL BENEFITS:
• Build now progresses past structural issues to normal dependency resolution
• Cleaner separation of concerns between packages
• Eliminates circular dependencies that prevented compilation
• Establishes foundation for scalable codebase growth

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
anthonyrawlins
2025-08-17 10:04:25 +10:00
parent e9252ccddc
commit d96c931a29
115 changed files with 1010 additions and 534 deletions

View File

@@ -4,9 +4,9 @@ import (
"context"
"time"
"github.com/anthonyrawlins/bzzz/pkg/crypto"
"github.com/anthonyrawlins/bzzz/pkg/ucxl"
slurpContext "github.com/anthonyrawlins/bzzz/pkg/slurp/context"
"chorus.services/bzzz/pkg/security"
"chorus.services/bzzz/pkg/ucxl"
slurpContext "chorus.services/bzzz/pkg/slurp/context"
)
// RoleManager handles definition and management of roles and permissions
@@ -63,7 +63,7 @@ type AccessController interface {
CheckContextAccess(ctx context.Context, userID string, address ucxl.Address, accessType AccessType) (bool, error)
// CheckAccessLevel checks if a user meets the required access level
CheckAccessLevel(ctx context.Context, userID string, requiredLevel crypto.AccessLevel) (bool, error)
CheckAccessLevel(ctx context.Context, userID string, requiredLevel security.AccessLevel) (bool, error)
// BatchCheckPermissions checks multiple permissions efficiently
BatchCheckPermissions(ctx context.Context, userID string, permissions []Permission) (map[Permission]bool, error)
@@ -72,7 +72,7 @@ type AccessController interface {
EvaluateContextPermissions(ctx context.Context, userID string, node *slurpContext.ContextNode) (*ContextPermissions, error)
// GetUserAccessLevel gets the maximum access level for a user
GetUserAccessLevel(ctx context.Context, userID string) (crypto.AccessLevel, error)
GetUserAccessLevel(ctx context.Context, userID string) (security.AccessLevel, error)
// CreateAccessToken creates a time-limited access token
CreateAccessToken(ctx context.Context, userID string, permissions []Permission, ttl time.Duration) (*AccessToken, error)

View File

@@ -3,11 +3,179 @@ package roles
import (
"time"
"github.com/anthonyrawlins/bzzz/pkg/crypto"
"github.com/anthonyrawlins/bzzz/pkg/ucxl"
slurpContext "github.com/anthonyrawlins/bzzz/pkg/slurp/context"
"chorus.services/bzzz/pkg/security"
"chorus.services/bzzz/pkg/ucxl"
slurpContext "chorus.services/bzzz/pkg/slurp/context"
)
// Stub types for interfaces (to be implemented later)
type RoleFilter struct {
RoleIDs []string `json:"role_ids,omitempty"`
Permissions []string `json:"permissions,omitempty"`
}
type RoleHierarchy struct {
Roles map[string][]string `json:"roles"`
}
type RoleValidation struct {
Valid bool `json:"valid"`
Errors []string `json:"errors"`
}
type RoleStatistics struct {
TotalRoles int `json:"total_roles"`
ActiveRoles int `json:"active_roles"`
}
type AccessStatistics struct {
TotalRequests int `json:"total_requests"`
GrantedRequests int `json:"granted_requests"`
}
type FilteringStatistics struct {
TotalFiltered int `json:"total_filtered"`
PassedFilter int `json:"passed_filter"`
}
type EvaluationStatistics struct {
TotalEvaluations int `json:"total_evaluations"`
SuccessfulEvaluations int `json:"successful_evaluations"`
}
type PermissionChange struct {
RoleID string `json:"role_id"`
Permission string `json:"permission"`
Action string `json:"action"`
Timestamp time.Time `json:"timestamp"`
}
type SecurityEvent struct {
EventType string `json:"event_type"`
RoleID string `json:"role_id"`
Timestamp time.Time `json:"timestamp"`
Details map[string]interface{} `json:"details"`
}
type AuditFilter struct {
RoleIDs []string `json:"role_ids,omitempty"`
EventTypes []string `json:"event_types,omitempty"`
StartTime *time.Time `json:"start_time,omitempty"`
EndTime *time.Time `json:"end_time,omitempty"`
}
type AuditEntry struct {
ID string `json:"id"`
Timestamp time.Time `json:"timestamp"`
EventType string `json:"event_type"`
RoleID string `json:"role_id"`
Details map[string]interface{} `json:"details"`
}
type AuditStatistics struct {
TotalEntries int `json:"total_entries"`
RecentEntries int `json:"recent_entries"`
}
type RetentionPolicy struct {
Duration time.Duration `json:"duration"`
MaxEntries int `json:"max_entries"`
}
type ArchiveResult struct {
ArchivedCount int `json:"archived_count"`
Success bool `json:"success"`
}
type EncryptionStatistics struct {
TotalEncrypted int `json:"total_encrypted"`
EncryptionErrors int `json:"encryption_errors"`
}
type AccessPolicy struct {
ID string `json:"id"`
Name string `json:"name"`
Rules []string `json:"rules"`
CreatedAt time.Time `json:"created_at"`
}
type PolicyFilter struct {
PolicyIDs []string `json:"policy_ids,omitempty"`
Names []string `json:"names,omitempty"`
}
type AccessRequest struct {
ID string `json:"id"`
UserID string `json:"user_id"`
RoleID string `json:"role_id"`
Resource string `json:"resource"`
Action string `json:"action"`
Timestamp time.Time `json:"timestamp"`
}
type PolicyEvaluation struct {
PolicyID string `json:"policy_id"`
Result bool `json:"result"`
Reason string `json:"reason"`
Timestamp time.Time `json:"timestamp"`
}
type PolicyValidation struct {
Valid bool `json:"valid"`
Errors []string `json:"errors"`
Warnings []string `json:"warnings"`
}
type UserSession struct {
ID string `json:"id"`
UserID string `json:"user_id"`
RoleIDs []string `json:"role_ids"`
CreatedAt time.Time `json:"created_at"`
LastAccessed time.Time `json:"last_accessed"`
ExpiresAt time.Time `json:"expires_at"`
Active bool `json:"active"`
}
type SessionUpdate struct {
SessionID string `json:"session_id"`
RoleIDs []string `json:"role_ids,omitempty"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
Active *bool `json:"active,omitempty"`
}
type CleanupResult struct {
CleanedSessions int `json:"cleaned_sessions"`
Success bool `json:"success"`
}
type SessionStatistics struct {
ActiveSessions int `json:"active_sessions"`
TotalSessions int `json:"total_sessions"`
ExpiredSessions int `json:"expired_sessions"`
}
type Delegation struct {
ID string `json:"id"`
DelegatorID string `json:"delegator_id"`
DelegateID string `json:"delegate_id"`
RoleID string `json:"role_id"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
Active bool `json:"active"`
}
type DelegationValidation struct {
Valid bool `json:"valid"`
Errors []string `json:"errors"`
Warnings []string `json:"warnings"`
}
type DelegationStatistics struct {
ActiveDelegations int `json:"active_delegations"`
TotalDelegations int `json:"total_delegations"`
ExpiredDelegations int `json:"expired_delegations"`
}
// Permission represents a specific permission within the system
type Permission string
@@ -75,7 +243,7 @@ type Role struct {
Name string `json:"name"` // Human-readable role name
Description string `json:"description"` // Role description
Permissions []Permission `json:"permissions"` // Granted permissions
AccessLevel crypto.AccessLevel `json:"access_level"` // Maximum access level
AccessLevel security.AccessLevel `json:"access_level"` // Maximum access level
Priority int `json:"priority"` // Role priority for conflicts
// Hierarchy
@@ -182,7 +350,7 @@ type ContextPermissions struct {
CanWrite bool `json:"can_write"` // Can write/modify context
CanDelete bool `json:"can_delete"` // Can delete context
CanDistribute bool `json:"can_distribute"` // Can distribute context
AccessLevel crypto.AccessLevel `json:"access_level"` // Granted access level
AccessLevel security.AccessLevel `json:"access_level"` // Granted access level
AllowedFields []string `json:"allowed_fields"` // Fields user can access
RestrictedFields []string `json:"restricted_fields"` // Fields user cannot access
Conditions []*PermissionCondition `json:"conditions"` // Access conditions
@@ -204,7 +372,7 @@ type AccessToken struct {
Token string `json:"token"` // Token string
UserID string `json:"user_id"` // User identifier
Permissions []Permission `json:"permissions"` // Granted permissions
AccessLevel crypto.AccessLevel `json:"access_level"` // Granted access level
AccessLevel security.AccessLevel `json:"access_level"` // Granted access level
IssuedAt time.Time `json:"issued_at"` // When issued
ExpiresAt time.Time `json:"expires_at"` // When expires
Scope []string `json:"scope"` // Token scope
@@ -251,7 +419,7 @@ type LabeledContext struct {
Context *slurpContext.ContextNode `json:"context"` // Original context
SecurityLabels []*SecurityLabel `json:"security_labels"` // Applied security labels
ClassificationLevel string `json:"classification_level"` // Overall classification
RequiredClearance crypto.AccessLevel `json:"required_clearance"` // Required clearance level
RequiredClearance security.AccessLevel `json:"required_clearance"` // Required clearance level
LabeledAt time.Time `json:"labeled_at"` // When labels were applied
LabeledBy string `json:"labeled_by"` // Who/what applied labels
}
@@ -262,7 +430,7 @@ type SecurityLabel struct {
Value string `json:"value"` // Label value
Confidence float64 `json:"confidence"` // Labeling confidence
AppliedReason string `json:"applied_reason"` // Why label was applied
RequiredLevel crypto.AccessLevel `json:"required_level"` // Required access level
RequiredLevel security.AccessLevel `json:"required_level"` // Required access level
Metadata map[string]interface{} `json:"metadata"` // Additional metadata
}
@@ -439,7 +607,7 @@ type EncryptedData struct {
Data []byte `json:"data"` // Encrypted data
EncryptionMethod string `json:"encryption_method"` // Encryption method used
RoleKeys map[string]string `json:"role_keys"` // Encrypted keys by role
AccessLevels map[string]crypto.AccessLevel `json:"access_levels"` // Access levels by role
AccessLevels map[string]security.AccessLevel `json:"access_levels"` // Access levels by role
CreatedAt time.Time `json:"created_at"` // When encrypted
ExpiresAt *time.Time `json:"expires_at,omitempty"` // When encryption expires
Metadata map[string]interface{} `json:"metadata"` // Additional metadata