Documentation
¶
Index ¶
- Variables
- type APIKey
- type CreateUserInput
- type Filter
- type Permission
- type PostgresRepository
- func (r *PostgresRepository) AssignRoles(ctx context.Context, userID string, roleNames []string) error
- func (r *PostgresRepository) CreateAPIKey(ctx context.Context, apiKey *APIKey, keyHash string) error
- func (r *PostgresRepository) CreateUser(ctx context.Context, user *User, passwordHash string) error
- func (r *PostgresRepository) CreateUserIdentity(ctx context.Context, identity *UserIdentity) error
- func (r *PostgresRepository) DeleteAPIKey(ctx context.Context, id string) error
- func (r *PostgresRepository) DeleteUser(ctx context.Context, id string) error
- func (r *PostgresRepository) DeleteUserIdentity(ctx context.Context, userID string, provider string) error
- func (r *PostgresRepository) FindSimilarUsernames(ctx context.Context, searchTerm string, limit int) ([]string, error)
- func (r *PostgresRepository) GetAPIKey(ctx context.Context, id string) (*APIKey, error)
- func (r *PostgresRepository) GetAPIKeyByHash(ctx context.Context, keyToValidate string) (*APIKey, error)
- func (r *PostgresRepository) GetPermissionsByRoleName(ctx context.Context, roleName string) ([]Permission, error)
- func (r *PostgresRepository) GetUser(ctx context.Context, id string) (*User, error)
- func (r *PostgresRepository) GetUserByProviderID(ctx context.Context, provider string, providerUserID string) (*User, error)
- func (r *PostgresRepository) GetUserByUsername(ctx context.Context, username string) (*User, error)
- func (r *PostgresRepository) GetUserIdentities(ctx context.Context, userID string) ([]*UserIdentity, error)
- func (r *PostgresRepository) HasPermission(ctx context.Context, userID string, resourceType string, action string) (bool, error)
- func (r *PostgresRepository) ListAPIKeys(ctx context.Context, userID string) ([]*APIKey, error)
- func (r *PostgresRepository) ListUsers(ctx context.Context, filter Filter) ([]*User, int, error)
- func (r *PostgresRepository) UpdateAPIKeyLastUsed(ctx context.Context, id string) error
- func (r *PostgresRepository) UpdatePreferences(ctx context.Context, userID string, preferences map[string]interface{}) error
- func (r *PostgresRepository) UpdateRoles(ctx context.Context, userID string, roleNames []string) error
- func (r *PostgresRepository) UpdateUser(ctx context.Context, id string, updates map[string]interface{}) error
- func (r *PostgresRepository) UsernameExists(ctx context.Context, username string) (bool, error)
- func (r *PostgresRepository) ValidatePassword(ctx context.Context, userID string, password string) error
- type Repository
- type Role
- type Service
- type ServiceOption
- type UpdateUserInput
- type User
- type UserIdentity
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrUserNotFound = errors.New("user not found") ErrRoleNotFound = errors.New("role not found") ErrInvalidInput = errors.New("invalid input") ErrAlreadyExists = errors.New("user already exists") ErrReservedUsername = errors.New("reserved username") ErrInvalidPassword = errors.New("invalid password") ErrInvalidAPIKey = errors.New("invalid API key") ErrPasswordRequired = errors.New("password is required for non-OAuth users") ErrCannotDeleteSelf = errors.New("user can't delete self") ErrCannotDeleteAdmin = errors.New("can't delete admin user") ErrPasswordChangeRequired = errors.New("password change required") )
Functions ¶
This section is empty.
Types ¶
type CreateUserInput ¶
type CreateUserInput struct {
Username string `json:"username" validate:"required,min=3,max=255"`
Name string `json:"name" validate:"required"`
Password string `json:"password" validate:"required_without=OAuthProvider,min=8"`
ProfilePicture string `json:"profile_picture,omitempty"`
RoleNames []string `json:"role_names" validate:"required,min=1"`
OAuthProvider string `json:"oauth_provider,omitempty"`
OAuthProviderID string `json:"oauth_provider_id,omitempty"`
OAuthProviderData map[string]interface{} `json:"oauth_provider_data,omitempty"`
}
type Permission ¶
type PostgresRepository ¶
type PostgresRepository struct {
// contains filtered or unexported fields
}
func (*PostgresRepository) AssignRoles ¶
func (*PostgresRepository) CreateAPIKey ¶
func (*PostgresRepository) CreateUser ¶
func (*PostgresRepository) CreateUserIdentity ¶
func (r *PostgresRepository) CreateUserIdentity(ctx context.Context, identity *UserIdentity) error
func (*PostgresRepository) DeleteAPIKey ¶
func (r *PostgresRepository) DeleteAPIKey(ctx context.Context, id string) error
func (*PostgresRepository) DeleteUser ¶
func (r *PostgresRepository) DeleteUser(ctx context.Context, id string) error
func (*PostgresRepository) DeleteUserIdentity ¶
func (*PostgresRepository) FindSimilarUsernames ¶ added in v0.5.0
func (r *PostgresRepository) FindSimilarUsernames(ctx context.Context, searchTerm string, limit int) ([]string, error)
FindSimilarUsernames finds usernames similar to the given search term
func (*PostgresRepository) GetAPIKeyByHash ¶
func (*PostgresRepository) GetPermissionsByRoleName ¶ added in v0.2.0
func (r *PostgresRepository) GetPermissionsByRoleName(ctx context.Context, roleName string) ([]Permission, error)
func (*PostgresRepository) GetUserByProviderID ¶
func (*PostgresRepository) GetUserByUsername ¶
func (*PostgresRepository) GetUserIdentities ¶
func (r *PostgresRepository) GetUserIdentities(ctx context.Context, userID string) ([]*UserIdentity, error)
func (*PostgresRepository) HasPermission ¶
func (*PostgresRepository) ListAPIKeys ¶
func (*PostgresRepository) UpdateAPIKeyLastUsed ¶
func (r *PostgresRepository) UpdateAPIKeyLastUsed(ctx context.Context, id string) error
func (*PostgresRepository) UpdatePreferences ¶
func (*PostgresRepository) UpdateRoles ¶
func (*PostgresRepository) UpdateUser ¶
func (*PostgresRepository) UsernameExists ¶
func (*PostgresRepository) ValidatePassword ¶
type Repository ¶
type Repository interface {
CreateUser(ctx context.Context, user *User, password string) error
GetUser(ctx context.Context, id string) (*User, error)
GetUserByUsername(ctx context.Context, email string) (*User, error)
FindSimilarUsernames(ctx context.Context, searchTerm string, limit int) ([]string, error)
GetUserByProviderID(ctx context.Context, provider string, providerUserID string) (*User, error)
UpdateUser(ctx context.Context, id string, updates map[string]interface{}) error
UpdatePreferences(ctx context.Context, userID string, preferences map[string]interface{}) error
DeleteUser(ctx context.Context, id string) error
ListUsers(ctx context.Context, filter Filter) ([]*User, int, error)
CreateUserIdentity(ctx context.Context, identity *UserIdentity) error
GetUserIdentities(ctx context.Context, userID string) ([]*UserIdentity, error)
DeleteUserIdentity(ctx context.Context, userID string, provider string) error
CreateAPIKey(ctx context.Context, apiKey *APIKey, keyHash string) error
GetAPIKey(ctx context.Context, id string) (*APIKey, error)
GetAPIKeyByHash(ctx context.Context, keyHash string) (*APIKey, error)
UpdateAPIKeyLastUsed(ctx context.Context, id string) error
DeleteAPIKey(ctx context.Context, id string) error
ListAPIKeys(ctx context.Context, userID string) ([]*APIKey, error)
AssignRoles(ctx context.Context, userID string, roleNames []string) error
UpdateRoles(ctx context.Context, userID string, roleNames []string) error
HasPermission(ctx context.Context, userID string, resourceType string, action string) (bool, error)
GetPermissionsByRoleName(ctx context.Context, roleName string) ([]Permission, error)
ValidatePassword(ctx context.Context, userID string, password string) error
UsernameExists(ctx context.Context, username string) (bool, error)
}
func NewPostgresRepository ¶
func NewPostgresRepository(db *pgxpool.Pool) Repository
type Role ¶
type Role struct {
ID string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Permissions []Permission `json:"permissions,omitempty"`
}
type Service ¶
type Service interface {
Create(ctx context.Context, input CreateUserInput) (*User, error)
Update(ctx context.Context, id string, input UpdateUserInput) (*User, error)
Delete(ctx context.Context, currentUserId string, id string) error
Get(ctx context.Context, id string) (*User, error)
GetUserByUsername(ctx context.Context, username string) (*User, error)
FindSimilarUsernames(ctx context.Context, searchTerm string, limit int) ([]string, error)
List(ctx context.Context, filter Filter) ([]*User, int, error)
// Authentication
Authenticate(ctx context.Context, username, password string) (*User, error)
ValidateAPIKey(ctx context.Context, apiKey string) (*User, error)
HasPermission(ctx context.Context, userID string, resourceType string, action string) (bool, error)
GetPermissionsByRoleName(ctx context.Context, roleName string) ([]Permission, error)
// OAuth
GetUserByProviderID(ctx context.Context, provider string, providerUserID string) (*User, error)
AuthenticateOAuth(ctx context.Context, provider string, providerUserID string, userInfo map[string]interface{}) (*User, error)
LinkOAuthAccount(ctx context.Context, userID string, provider string, providerUserID string, userInfo map[string]interface{}) error
UnlinkOAuthAccount(ctx context.Context, userID string, provider string) error
// API Keys
CreateAPIKey(ctx context.Context, userID string, name string, expiresIn *time.Duration) (*APIKey, error)
DeleteAPIKey(ctx context.Context, userID string, keyID string) error
ListAPIKeys(ctx context.Context, userID string) ([]*APIKey, error)
UpdatePreferences(ctx context.Context, userID string, preferences map[string]interface{}) error
UpdatePassword(ctx context.Context, userID string, newPassword string) (*User, error)
}
func NewService ¶
func NewService(repo Repository, opts ...ServiceOption) Service
type ServiceOption ¶
type ServiceOption func(*service)
type UpdateUserInput ¶
type UpdateUserInput struct {
Email *string `json:"email,omitempty" validate:"omitempty,email"`
Name *string `json:"name,omitempty"`
ProfilePicture *string `json:"profile_picture,omitempty"`
Password *string `json:"password,omitempty" validate:"omitempty,min=8"`
Active *bool `json:"active,omitempty"`
Preferences map[string]interface{} `json:"preferences,omitempty"`
RoleNames []string `json:"role_names,omitempty" validate:"omitempty,min=1"`
}
type User ¶
type User struct {
ID string `json:"id"`
Username string `json:"username"`
Name string `json:"name"`
ProfilePicture string `json:"profile_picture,omitempty"`
Active bool `json:"active"`
MustChangePassword bool `json:"must_change_password"`
Preferences map[string]interface{} `json:"preferences"`
Roles []Role `json:"roles"`
Identities []UserIdentity `json:"identities,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type UserIdentity ¶
type UserIdentity struct {
ID string `json:"id"`
UserID string `json:"user_id"`
Provider string `json:"provider"`
ProviderUserID string `json:"provider_user_id"`
ProviderEmail string `json:"provider_email"`
ProviderData map[string]interface{} `json:"provider_data"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
Click to show internal directories.
Click to hide internal directories.