Documentation
¶
Overview ¶
Package models provides database model definitions and access patterns for the Go IAM system. All models implement the DbCollection interface and provide BSON field mappings for MongoDB operations.
Index ¶
- type AuthProvider
- type AuthProviderModel
- type AuthProviderParam
- type AuthProviderType
- type Client
- type ClientModel
- type Migration
- type MigrationModel
- type Policy
- type PolicyModel
- type Project
- type ProjectModel
- type Resource
- type ResourceModel
- type Resources
- type Role
- type RoleMap
- type RoleMapModel
- type RoleModel
- type User
- type UserModel
- type UserPolicy
- type UserPolicyMapping
- type UserPolicyMappingValue
- type UserResource
- type UserRoles
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuthProvider ¶
type AuthProvider struct {
Id string `bson:"id"` // Unique identifier for the auth provider
Name string `bson:"name"` // Human-readable name of the auth provider
Icon string `bson:"icon"` // Icon URL or identifier for UI display
Provider AuthProviderType `bson:"provider"` // Type of authentication provider
Params []AuthProviderParam `bson:"params"` // Configuration parameters for the provider
ProjectId string `bson:"project_id"` // ID of the project this provider belongs to
Enabled bool `bson:"enabled"` // Whether the provider is currently active
CreatedAt *time.Time `bson:"created_at"` // Timestamp when the provider was created
UpdatedAt *time.Time `bson:"updated_at"` // Timestamp when the provider was last updated
CreatedBy string `bson:"created_by"` // User who created the provider
UpdatedBy string `bson:"updated_by"` // User who last updated the provider
}
AuthProvider represents an authentication provider in the Go IAM system. Auth providers handle external authentication services like Google, GitHub, etc. Each provider belongs to a project and can be configured with custom parameters.
type AuthProviderModel ¶
type AuthProviderModel struct {
IdKey string // BSON field key for auth provider ID
NameKey string // BSON field key for auth provider name
ProviderKey string // BSON field key for provider type
IsEnabledKey string // BSON field key for enabled status
ProjectIdKey string // BSON field key for project ID
ParamsKey string // BSON field key for provider parameters
// contains filtered or unexported fields
}
AuthProviderModel provides database access patterns and field mappings for AuthProvider entities. It embeds the iam struct to inherit the database name and implements collection operations.
func GetAuthProviderModel ¶
func GetAuthProviderModel() AuthProviderModel
GetAuthProviderModel returns a properly initialized AuthProviderModel with all field mappings. This function provides a singleton pattern for accessing auth provider model operations.
Returns an AuthProviderModel instance with all BSON field keys mapped to their respective field names.
func (AuthProviderModel) DbName ¶
func (i AuthProviderModel) DbName() string
DbName returns the MongoDB database name used by all Go IAM models. This implements the DbCollection interface requirement.
func (AuthProviderModel) Name ¶
func (a AuthProviderModel) Name() string
Name returns the MongoDB collection name for auth providers. This implements the DbCollection interface.
type AuthProviderParam ¶
type AuthProviderParam struct {
Label string `bson:"label"` // Human-readable label for the parameter
Value string `bson:"value"` // Value of the parameter
Key string `bson:"key"` // Unique key identifier for the parameter
IsSecret bool `bson:"is_secret"` // Whether this parameter contains sensitive information
}
AuthProviderParam represents a configuration parameter for an authentication provider. Parameters can include client IDs, secrets, endpoints, and other provider-specific settings.
type AuthProviderType ¶
type AuthProviderType string
AuthProviderType represents the type of authentication provider. This defines the specific implementation used for authentication.
type Client ¶
type Client struct {
Id string `bson:"id"` // Unique identifier for the client
Name string `bson:"name"` // Human-readable name of the client
Description string `bson:"description"` // Detailed description of the client's purpose
Secret string `bson:"secret"` // Client secret for authentication
Tags []string `bson:"tags"` // Tags for categorizing and filtering clients
RedirectURLs []string `bson:"redirect_urls"` // Allowed redirect URLs for OAuth2 flows
DefaultAuthProviderId string `bson:"default_auth_provider_id"` // Default authentication provider for this client
GoIamClient bool `bson:"go_iam_client"` // Indicates if this is a Go-IAM system client
ProjectId string `bson:"project_id"` // ID of the project this client belongs to
ServiceAccountEmail string `bson:"service_account_email"` // Email for service account authentication
Scopes []string `bson:"scopes"` // OAuth2 scopes this client can request
AllowedEmailDomains []string `bson:"allowed_email_domains"` // Allowed email domains for user accounts linked to this client
Enabled bool `bson:"enabled"` // Whether the client is currently active
LinkedUserId string `bson:"linked_user_id"` // User ID for service account clients
CreatedAt *time.Time `bson:"created_at"` // Timestamp when the client was created
CreatedBy string `bson:"created_by"` // User who created the client
UpdatedAt *time.Time `bson:"updated_at"` // Timestamp when the client was last updated
UpdatedBy string `bson:"updated_by"` // User who last updated the client
}
Client represents an OAuth2/OIDC client application in the Go IAM system. Clients are applications that can authenticate users and access protected resources. Each client belongs to a project and can have various configuration options.
type ClientModel ¶
type ClientModel struct {
IdKey string // BSON field key for client ID
NameKey string // BSON field key for client name
TagsKey string // BSON field key for client tags
DescriptionKey string // BSON field key for client description
ProjectIdKey string // BSON field key for project ID
GoIamClientKey string // BSON field key for Go-IAM client flag
LinkedUserIdKey string // BSON field key for linked user ID (service accounts)
AllowedEmailDomainsKey string // BSON field key for allowed email domains
UpdatedAtKey string // BSON field key for last updated timestamp
// contains filtered or unexported fields
}
ClientModel provides database access patterns and field mappings for Client entities. It embeds the iam struct to inherit the database name and implements collection operations.
func GetClientModel ¶
func GetClientModel() ClientModel
GetClientModel returns a properly initialized ClientModel with all field mappings. This function provides a singleton pattern for accessing client model operations.
Returns a ClientModel instance with all BSON field keys mapped to their respective field names.
func (ClientModel) DbName ¶
func (i ClientModel) DbName() string
DbName returns the MongoDB database name used by all Go IAM models. This implements the DbCollection interface requirement.
func (ClientModel) Name ¶
func (c ClientModel) Name() string
Name returns the MongoDB collection name for clients. This implements the DbCollection interface.
type Migration ¶
type Migration struct {
Id string `bson:"id"` // Unique identifier for the migration
Version string `bson:"version"` // Version identifier of the migration
Name string `bson:"name"` // Human-readable name of the migration
Description string `bson:"description"` // Detailed description of what the migration does
AppliedAt *time.Time `bson:"applied_at"` // Timestamp when the migration was applied
Checksum string `bson:"checksum"` // Checksum to verify migration integrity
CreatedAt *time.Time `bson:"created_at"` // Timestamp when the migration record was created
CreatedBy string `bson:"created_by"` // User or system that created the migration record
UpdatedAt *time.Time `bson:"updated_at"` // Timestamp when the migration record was last updated
UpdatedBy string `bson:"updated_by"` // User or system that last updated the migration record
}
Migration represents a database migration record in the Go IAM system. Migrations track schema changes and data transformations applied to the database. This ensures database consistency across different environments and deployments.
type MigrationModel ¶
type MigrationModel struct {
IdKey string // BSON field key for migration ID
VersionKey string // BSON field key for migration version
NameKey string // BSON field key for migration name
DescriptionKey string // BSON field key for migration description
AppliedAtKey string // BSON field key for application timestamp
ChecksumKey string // BSON field key for migration checksum
// contains filtered or unexported fields
}
MigrationModel provides database access patterns and field mappings for Migration entities. It embeds the iam struct to inherit the database name and implements collection operations.
func GetMigrationModel ¶
func GetMigrationModel() MigrationModel
GetMigrationModel returns a properly initialized MigrationModel with all field mappings. This function provides a singleton pattern for accessing migration model operations.
Returns a MigrationModel instance with all BSON field keys mapped to their respective field names.
func (MigrationModel) DbName ¶
func (i MigrationModel) DbName() string
DbName returns the MongoDB database name used by all Go IAM models. This implements the DbCollection interface requirement.
func (MigrationModel) Name ¶
func (m MigrationModel) Name() string
Name returns the MongoDB collection name for migrations. This implements the DbCollection interface.
type Policy ¶
type Policy struct {
Id string `bson:"id"` // Unique identifier for the policy
Name string `bson:"name"` // Human-readable name of the policy
Roles map[string]string `bson:"roles"` // Map of role IDs to role names associated with this policy
Description string `bson:"description"` // Detailed description of the policy's purpose
CreatedAt *time.Time `bson:"created_at"` // Timestamp when the policy was created
CreatedBy string `bson:"created_by"` // User who created the policy
}
Policy represents a resource-based policy that associates roles with resources. Policies define fine-grained access control rules that can be applied to users and resources.
type PolicyModel ¶
type PolicyModel struct {
IdKey string // BSON field key for policy ID
NameKey string // BSON field key for policy name
RolesKey string // BSON field key for policy roles
DescriptionKey string // BSON field key for policy description
// contains filtered or unexported fields
}
PolicyModel provides database access patterns and field mappings for Policy entities. It embeds the iam struct to inherit the database name and implements collection operations.
func GetPolicyModel ¶
func GetPolicyModel() PolicyModel
GetPolicyModel returns a properly initialized PolicyModel with all field mappings. This function provides a singleton pattern for accessing policy model operations.
Returns a PolicyModel instance with all BSON field keys mapped to their respective field names.
func (PolicyModel) DbName ¶
func (i PolicyModel) DbName() string
DbName returns the MongoDB database name used by all Go IAM models. This implements the DbCollection interface requirement.
func (PolicyModel) Name ¶
func (p PolicyModel) Name() string
Name returns the MongoDB collection name for policies. This implements the DbCollection interface.
type Project ¶
type Project struct {
Id string `bson:"id"` // Unique identifier for the project
Name string `bson:"name"` // Human-readable name of the project
Tags []string `bson:"tags"` // Tags for categorizing and filtering projects
Description string `bson:"description"` // Detailed description of the project's purpose
CreatedAt *time.Time `bson:"created_at"` // Timestamp when the project was created
CreatedBy string `bson:"created_by"` // User who created the project
UpdatedAt *time.Time `bson:"updated_at"` // Timestamp when the project was last updated
UpdatedBy string `bson:"updated_by"` // User who last updated the project
}
Project represents a project entity in the Go IAM system. Projects are organizational units that contain users, clients, roles, and resources. They provide isolation and multi-tenancy in the IAM system.
type ProjectModel ¶
type ProjectModel struct {
IdKey string // BSON field key for project ID
NameKey string // BSON field key for project name
TagsKey string // BSON field key for project tags
DescriptionKey string // BSON field key for project description
// contains filtered or unexported fields
}
ProjectModel provides database access patterns and field mappings for Project entities. It embeds the iam struct to inherit the database name and implements collection operations.
func GetProjectModel ¶
func GetProjectModel() ProjectModel
GetProjectModel returns a properly initialized ProjectModel with all field mappings. This function provides a singleton pattern for accessing project model operations.
Returns a ProjectModel instance with all BSON field keys mapped to their respective field names.
func (ProjectModel) DbName ¶
func (i ProjectModel) DbName() string
DbName returns the MongoDB database name used by all Go IAM models. This implements the DbCollection interface requirement.
func (ProjectModel) Name ¶
func (p ProjectModel) Name() string
Name returns the MongoDB collection name for projects. This implements the DbCollection interface.
type Resource ¶
type Resource struct {
ID string `bson:"id,omitempty"` // Unique identifier for the resource
Name string `bson:"name"` // Human-readable name of the resource
Description string `bson:"description"` // Detailed description of the resource
Key string `bson:"key"` // Unique key identifier for the resource
ProjectId string `bson:"project_id"` // ID of the project this resource belongs to
Enabled bool `bson:"enabled"` // Whether the resource is currently active
CreatedAt *time.Time `bson:"created_at"` // Timestamp when the resource was created
CreatedBy string `bson:"created_by"` // User who created the resource
UpdatedAt *time.Time `bson:"updated_at"` // Timestamp when the resource was last updated
UpdatedBy string `bson:"updated_by"` // User who last updated the resource
DeletedAt *time.Time `bson:"deleted_at,omitempty"` // Timestamp when the resource was soft deleted
}
Resource represents a resource entity in the Go IAM system. Resources are entities that can be protected and accessed through the IAM system. They can be assigned to roles and have policies applied to control access.
type ResourceModel ¶
type ResourceModel struct {
IdKey string // BSON field key for resource ID
NameKey string // BSON field key for resource name
DescriptionKey string // BSON field key for resource description
KeyKey string // BSON field key for resource key
EnabledKey string // BSON field key for enabled status
ProjectIdKey string // BSON field key for project ID
// contains filtered or unexported fields
}
ResourceModel provides database access patterns and field mappings for Resource entities. It embeds the iam struct to inherit the database name and implements collection operations.
func GetResourceModel ¶
func GetResourceModel() ResourceModel
GetResourceModel returns a properly initialized ResourceModel with all field mappings. This function provides a singleton pattern for accessing resource model operations.
Returns a ResourceModel instance with all BSON field keys mapped to their respective field names.
func (ResourceModel) DbName ¶
func (i ResourceModel) DbName() string
DbName returns the MongoDB database name used by all Go IAM models. This implements the DbCollection interface requirement.
func (ResourceModel) Name ¶
func (r ResourceModel) Name() string
Name returns the MongoDB collection name for resources. This implements the DbCollection interface.
type Resources ¶
type Resources struct {
Id string `bson:"id"` // Unique identifier of the resource
Key string `bson:"key"` // Unique key identifier for the resource
Name string `bson:"name"` // Human-readable name of the resource
}
Resources represents a resource that can be associated with a role. Resources define the entities that roles can have permissions on.
type Role ¶
type Role struct {
Id string `bson:"id"` // Unique identifier for the role
ProjectId string `bson:"project_id"` // ID of the project this role belongs to
Name string `bson:"name"` // Human-readable name of the role
Description string `bson:"description"` // Detailed description of the role's purpose
Resources map[string]Resources `bson:"resources"` // Map of resources this role has access to
Enabled bool `bson:"enabled"` // Whether the role is currently active
CreatedAt time.Time `bson:"created_at"` // Timestamp when the role was created
CreatedBy string `bson:"created_by"` // User who created the role
UpdatedAt time.Time `bson:"updated_at"` // Timestamp when the role was last updated
UpdatedBy string `bson:"updated_by"` // User who last updated the role
}
Role represents a role entity in the Go IAM system. Roles define collections of permissions that can be assigned to users. Each role belongs to a project and can have access to multiple resources.
type RoleMap ¶
type RoleMap struct {
RoleId string `bson:"role_id"` // ID of the role in the mapping
UserId []string `bson:"user_id"` // Array of user IDs assigned to this role
}
RoleMap represents a mapping between roles and users in the Go IAM system. This provides a many-to-many relationship between roles and users, allowing efficient querying of user-role associations.
type RoleMapModel ¶
type RoleMapModel struct {
RoleIdKey string // BSON field key for role ID
UserIdKey string // BSON field key for user ID array
// contains filtered or unexported fields
}
RoleMapModel provides database access patterns and field mappings for RoleMap entities. It embeds the iam struct to inherit the database name and implements collection operations.
func GetRoleMap ¶
func GetRoleMap() RoleMapModel
GetRoleMap returns a properly initialized RoleMapModel with all field mappings. This function provides a singleton pattern for accessing role map model operations.
Returns a RoleMapModel instance with all BSON field keys mapped to their respective field names.
func (RoleMapModel) DbName ¶
func (i RoleMapModel) DbName() string
DbName returns the MongoDB database name used by all Go IAM models. This implements the DbCollection interface requirement.
func (RoleMapModel) Name ¶
func (u RoleMapModel) Name() string
Name returns the MongoDB collection name for role mappings. This implements the DbCollection interface.
type RoleModel ¶
type RoleModel struct {
IdKey string // BSON field key for role ID
ProjectIdKey string // BSON field key for project ID
NameKey string // BSON field key for role name
DescriptionKey string // BSON field key for role description
ResourcesKey string // BSON field key for role resources
CreatedAtKey string // BSON field key for creation timestamp
CreatedByKey string // BSON field key for creator
UpdatedAtKey string // BSON field key for update timestamp
EnabledKey string // BSON field key for enabled status
UpdatedByKey string // BSON field key for updater
// contains filtered or unexported fields
}
RoleModel provides database access patterns and field mappings for Role entities. It embeds the iam struct to inherit the database name and implements collection operations.
func GetRoleModel ¶
func GetRoleModel() RoleModel
GetRoleModel returns a properly initialized RoleModel with all field mappings. This function provides a singleton pattern for accessing role model operations.
Returns a RoleModel instance with all BSON field keys mapped to their respective field names.
type User ¶
type User struct {
Id string `bson:"id"` // Unique identifier for the user
ProjectId string `bson:"project_id"` // ID of the project this user belongs to
Name string `bson:"name"` // Display name of the user
Email string `bson:"email"` // Email address of the user
Phone string `bson:"phone"` // Phone number of the user
Enabled bool `bson:"enabled"` // Whether the user account is active
ProfilePic string `bson:"profile_pic"` // URL or path to the user's profile picture
Expiry *time.Time `bson:"expiry"` // Optional expiration date for the user account
Roles map[string]UserRoles `bson:"roles"` // Roles assigned to the user
Resources map[string]UserResource `bson:"resources"` // Resources the user has access to
Policies map[string]UserPolicy `bson:"policies"` // Policies applied to the user
LinkedClientId string `bson:"linked_client_id,omitempty"` // Client ID for service account users
CreatedAt *time.Time `bson:"created_at"` // Timestamp when the user was created
CreatedBy string `bson:"created_by"` // User who created this user
UpdatedAt *time.Time `bson:"updated_at"` // Timestamp when the user was last updated
UpdatedBy string `bson:"updated_by"` // User who last updated this user
}
User represents a user entity in the Go IAM system. Users are the primary subjects of authentication and authorization, with assigned roles, resources, and policies that determine their access rights.
type UserModel ¶
type UserModel struct {
IdKey string // BSON field key for user ID
NameKey string // BSON field key for user name
EmailKey string // BSON field key for user email
PhoneKey string // BSON field key for user phone
EnabledKey string // BSON field key for enabled status
RolesIdKey string // BSON field key for user roles
PoliciesKey string // BSON field key for user policies
ResourcesKey string // BSON field key for user resources
IsEnabledKey string // BSON field key for enabled status (alternative)
ProjectIDKey string // BSON field key for project ID
ExpiryKey string // BSON field key for account expiry
// contains filtered or unexported fields
}
UserModel provides database access patterns and field mappings for User entities. It embeds the iam struct to inherit the database name and implements collection operations. UserModel provides database access patterns and field mappings for User entities. It embeds the iam struct to inherit the database name and implements collection operations.
func GetUserModel ¶
func GetUserModel() UserModel
GetUserModel returns a properly initialized UserModel with all field mappings. This function provides a singleton pattern for accessing user model operations.
Returns a UserModel instance with all BSON field keys mapped to their respective field names.
type UserPolicy ¶
type UserPolicy struct {
Name string `bson:"name,omitempty"` // Name of the policy
Mapping UserPolicyMapping `bson:"mapping,omitempty"` // Dynamic value mappings for policy arguments
}
UserPolicy represents a policy assignment to a user with dynamic value mapping. Policies define fine-grained permissions and can have configurable arguments.
type UserPolicyMapping ¶
type UserPolicyMapping struct {
Arguments map[string]UserPolicyMappingValue `bson:"arguments,omitempty"` // Argument name to value mappings
}
UserPolicyMapping contains argument mappings for policy execution. This allows policies to have dynamic values based on user context.
type UserPolicyMappingValue ¶
type UserPolicyMappingValue struct {
Static string `bson:"static,omitempty"` // Static value for the policy argument
}
UserPolicyMappingValue represents a mapped value for policy arguments. Currently supports static values, but can be extended for dynamic values.
type UserResource ¶
type UserResource struct {
RoleIds map[string]bool `bson:"role_ids"` // Map of role IDs assigned to this resource
PolicyIds map[string]bool `bson:"policy_ids"` // Map of policy IDs applied to this resource
Key string `bson:"key"` // Unique key identifier for the resource
Name string `bson:"name"` // Human-readable name of the resource
}
UserResource represents a resource that a user has access to. Resources can have associated roles and policies that define the user's permissions.