Help us shape the future of Go! Take the 2026 Go Developer Survey

state

package
v0.5.11 Latest Latest
Warning

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

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

Documentation

Overview

Package state provides unified state management for Prism.

This file provides the unified state management that eliminates the unnecessary ProfileAwareStateManager wrapper while maintaining all functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnhancedProfileProvider

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

EnhancedProfileProvider integrates with the ManagerEnhanced profile system

func NewEnhancedProfileProvider

func NewEnhancedProfileProvider() (*EnhancedProfileProvider, error)

NewEnhancedProfileProvider creates a profile provider using the ManagerEnhanced system

func (*EnhancedProfileProvider) GetCurrentProfile

func (epp *EnhancedProfileProvider) GetCurrentProfile() (string, error)

GetCurrentProfile returns the current profile's AWS profile name

func (*EnhancedProfileProvider) GetProfileManager

func (epp *EnhancedProfileProvider) GetProfileManager() *profile.ManagerEnhanced

GetProfileManager returns the underlying profile manager for advanced operations

type Manager

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

Manager handles state persistence

func NewManager

func NewManager() (*Manager, error)

NewManager creates a new state manager

func (*Manager) AddUserToGroup

func (m *Manager) AddUserToGroup(ctx context.Context, userID, groupID string) error

AddUserToGroup adds a user to a group

func (*Manager) ClearAPIKey

func (m *Manager) ClearAPIKey() error

ClearAPIKey removes the API key from the configuration

func (*Manager) CreateGroup

func (m *Manager) CreateGroup(ctx context.Context, group *usermgmt.Group) (*usermgmt.Group, error)

CreateGroup creates a new group

func (*Manager) CreateUser

func (m *Manager) CreateUser(ctx context.Context, user *usermgmt.User) (*usermgmt.User, error)

CreateUser creates a new user

func (*Manager) DeleteGroup

func (m *Manager) DeleteGroup(ctx context.Context, id string) error

DeleteGroup deletes a group

func (*Manager) DeleteUser

func (m *Manager) DeleteUser(ctx context.Context, id string) error

DeleteUser deletes a user

func (*Manager) GetAPIKey

func (m *Manager) GetAPIKey() (string, time.Time, error)

GetAPIKey retrieves the current API key

func (*Manager) GetGroup

func (m *Manager) GetGroup(ctx context.Context, id string) (*usermgmt.Group, error)

GetGroup gets a group by ID

func (*Manager) GetGroupByName

func (m *Manager) GetGroupByName(ctx context.Context, name string) (*usermgmt.Group, error)

GetGroupByName gets a group by name

func (*Manager) GetGroupUsers

func (m *Manager) GetGroupUsers(ctx context.Context, groupID string, pagination *usermgmt.PaginationOptions) (*usermgmt.PaginatedUsers, error)

GetGroupUsers gets the users in a group

func (*Manager) GetGroups

func (m *Manager) GetGroups(ctx context.Context, filter *usermgmt.GroupFilter, pagination *usermgmt.PaginationOptions) (*usermgmt.PaginatedGroups, error)

GetGroups gets groups matching the specified filter

func (*Manager) GetUser

func (m *Manager) GetUser(ctx context.Context, id string) (*usermgmt.User, error)

GetUser gets a user by ID

func (*Manager) GetUserByEmail

func (m *Manager) GetUserByEmail(ctx context.Context, email string) (*usermgmt.User, error)

GetUserByEmail gets a user by email

func (*Manager) GetUserByUsername

func (m *Manager) GetUserByUsername(ctx context.Context, username string) (*usermgmt.User, error)

GetUserByUsername gets a user by username

func (*Manager) GetUserGroups

func (m *Manager) GetUserGroups(ctx context.Context, userID string) ([]*usermgmt.Group, error)

GetUserGroups gets the groups a user belongs to

func (*Manager) GetUsers

func (m *Manager) GetUsers(ctx context.Context, filter *usermgmt.UserFilter, pagination *usermgmt.PaginationOptions) (*usermgmt.PaginatedUsers, error)

GetUsers gets users matching the specified filter

func (*Manager) IsUserInGroup

func (m *Manager) IsUserInGroup(ctx context.Context, userID, groupID string) (bool, error)

IsUserInGroup checks if a user is in a group

func (*Manager) LoadState

func (m *Manager) LoadState() (*types.State, error)

LoadState loads the current state from disk

func (*Manager) LoadUserState

func (m *Manager) LoadUserState() (*UserState, error)

LoadUserState loads the user state from disk

func (*Manager) RemoveInstance

func (m *Manager) RemoveInstance(name string) error

RemoveInstance removes an instance from state

func (*Manager) RemoveStorageVolume

func (m *Manager) RemoveStorageVolume(name string) error

RemoveStorageVolume removes a storage volume from state

func (*Manager) RemoveUserFromGroup

func (m *Manager) RemoveUserFromGroup(ctx context.Context, userID, groupID string) error

RemoveUserFromGroup removes a user from a group

func (*Manager) SaveAPIKey

func (m *Manager) SaveAPIKey(apiKey string) error

SaveAPIKey saves a new API key to the configuration

func (*Manager) SaveInstance

func (m *Manager) SaveInstance(instance types.Instance) error

SaveInstance saves a single instance to state

func (*Manager) SaveState

func (m *Manager) SaveState(state *types.State) error

SaveState saves the current state to disk

func (*Manager) SaveStorageVolume

func (m *Manager) SaveStorageVolume(volume types.StorageVolume) error

SaveStorageVolume saves a single storage volume to state

func (*Manager) SaveUserState

func (m *Manager) SaveUserState(state *UserState) error

SaveUserState saves the user state to disk

func (*Manager) UpdateConfig

func (m *Manager) UpdateConfig(config types.Config) error

UpdateConfig updates the configuration

func (*Manager) UpdateGroup

func (m *Manager) UpdateGroup(ctx context.Context, group *usermgmt.Group) (*usermgmt.Group, error)

UpdateGroup updates an existing group

func (*Manager) UpdateUser

func (m *Manager) UpdateUser(ctx context.Context, user *usermgmt.User) (*usermgmt.User, error)

UpdateUser updates an existing user using Strategy Pattern (SOLID: Single Responsibility)

type ProfileProvider

type ProfileProvider interface {
	GetCurrentProfile() (string, error) // Returns current profile ID
}

ProfileProvider interface allows plugging in different profile systems

type StaticProfileProvider

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

StaticProfileProvider is a simple profile provider for testing

func NewStaticProfileProvider

func NewStaticProfileProvider(profile string) *StaticProfileProvider

NewStaticProfileProvider creates a profile provider that returns a fixed profile

func (*StaticProfileProvider) GetCurrentProfile

func (spp *StaticProfileProvider) GetCurrentProfile() (string, error)

GetCurrentProfile returns the static profile

type UnifiedManager

type UnifiedManager struct {
	*Manager // Embed the base manager for all core functionality
	// contains filtered or unexported fields
}

UnifiedManager provides state management with optional profile integration. This replaces both the base Manager and the ProfileAwareStateManager wrapper.

func GetDefaultManager

func GetDefaultManager() (*UnifiedManager, error)

GetDefaultManager returns a unified manager (replaces state.NewManager)

func GetManagerWithProfiles

func GetManagerWithProfiles(provider ProfileProvider) (*UnifiedManager, error)

GetManagerWithProfiles returns a unified manager with profile support

func NewProfileAwareManager

func NewProfileAwareManager() (*UnifiedManager, error)

Legacy compatibility - this replaces ProfileAwareStateManager

func NewUnifiedManager

func NewUnifiedManager() (*UnifiedManager, error)

NewUnifiedManager creates a unified state manager

func NewUnifiedManagerWithEnhancedProfiles

func NewUnifiedManagerWithEnhancedProfiles() (*UnifiedManager, error)

Convenience function to create unified state manager with enhanced profile integration

func NewUnifiedManagerWithProfiles

func NewUnifiedManagerWithProfiles(provider ProfileProvider) (*UnifiedManager, error)

NewUnifiedManagerWithProfiles creates a unified manager with profile integration

func (*UnifiedManager) GetCurrentProfile

func (um *UnifiedManager) GetCurrentProfile() (string, error)

GetCurrentProfile returns the current profile if a provider is set

func (*UnifiedManager) LoadState

func (um *UnifiedManager) LoadState() (*types.State, error)

LoadState loads state (profile-aware if provider is set)

func (*UnifiedManager) LoadStateForProfile

func (um *UnifiedManager) LoadStateForProfile() (*types.State, error)

LoadStateForProfile loads state with profile context (if available)

func (*UnifiedManager) SaveState

func (um *UnifiedManager) SaveState(state *types.State) error

SaveState saves state (profile-aware if provider is set)

func (*UnifiedManager) SaveStateForProfile

func (um *UnifiedManager) SaveStateForProfile(state *types.State) error

SaveStateForProfile saves state with profile context (if available)

type UserGroupMembershipManager

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

UserGroupMembershipManager manages user group relationships (Single Responsibility - SOLID)

func (*UserGroupMembershipManager) UpdateGroupMembership

func (g *UserGroupMembershipManager) UpdateGroupMembership(ctx context.Context, state *UserState, user *usermgmt.User) error

UpdateGroupMembership synchronizes user group memberships

type UserMappingUpdater

type UserMappingUpdater struct{}

UserMappingUpdater updates username and email mappings (Single Responsibility - SOLID)

func (*UserMappingUpdater) UpdateMappings

func (u *UserMappingUpdater) UpdateMappings(state *UserState, oldUser, newUser *usermgmt.User)

UpdateMappings updates username and email mappings in state

type UserState

type UserState struct {
	// Users is a map of user ID to user
	Users map[string]*usermgmt.User `json:"users"`

	// Groups is a map of group ID to group
	Groups map[string]*usermgmt.Group `json:"groups"`

	// UserGroups is a map of user ID to list of group IDs
	UserGroups map[string][]string `json:"user_groups"`

	// UsersByUsername is a map of username to user ID
	UsersByUsername map[string]string `json:"users_by_username"`

	// UsersByEmail is a map of email to user ID
	UsersByEmail map[string]string `json:"users_by_email"`

	// GroupsByName is a map of group name to group ID
	GroupsByName map[string]string `json:"groups_by_name"`
}

UserState represents the user state stored on disk

type UserUpdateOrchestrator

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

UserUpdateOrchestrator coordinates user update operations (Strategy Pattern - SOLID)

func NewUserUpdateOrchestrator

func NewUserUpdateOrchestrator(manager *Manager) *UserUpdateOrchestrator

NewUserUpdateOrchestrator creates user update orchestrator

func (*UserUpdateOrchestrator) ExecuteUpdate

func (o *UserUpdateOrchestrator) ExecuteUpdate(ctx context.Context, state *UserState, user *usermgmt.User, manager *Manager) (*usermgmt.User, error)

ExecuteUpdate performs complete user update using SOLID strategy pattern

type UserUpdateValidator

type UserUpdateValidator struct{}

UserUpdateValidator validates user update operations (Single Responsibility - SOLID)

func (*UserUpdateValidator) ValidateUpdate

func (v *UserUpdateValidator) ValidateUpdate(state *UserState, user *usermgmt.User) error

ValidateUpdate performs all validation checks for user updates

Jump to

Keyboard shortcuts

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