models

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ManagementDBClient

type ManagementDBClient interface {
	/*
		Ready checks whether the client is ready for use.

		 @return nil if ready, or an error otherwise
	*/
	Ready() error

	/*
		AlignRolesWithConfig aligns the role entries in the DB with the configuration provided

		 @param ctxt context.Context - context calling this API
		 @param configuredRoles []string - the list of configured roles
		 @return whether successful
	*/
	AlignRolesWithConfig(ctxt context.Context, configuredRoles []string) error

	/*
		ListAllRoles query for the list of known roles within the DB

		 @param ctxt context.Context - context calling this API
		 @return the list roles in the DB
	*/
	ListAllRoles(ctxt context.Context) ([]string, error)

	/*
		GetUsersOfRole query for the list of users which have that role.

		 @param ctxt context.Context - context calling this API
		 @param role string - the role
		 @return the list of users
	*/
	GetUsersOfRole(ctxt context.Context, role string) ([]UserInfo, error)

	/*
		DefineUser define a user entry with roles

		 @param ctxt context.Context - context calling this API
		 @param config UserConfig - user config
		 @param roles []string - roles for this user
		 @return whether successful
	*/
	DefineUser(ctxt context.Context, config UserConfig, roles []string) error

	/*
		GetUser query for a user by ID

		 @param ctxt context.Context - context calling this API
		 @param id string - user entry ID
		 @return the user information
	*/
	GetUser(ctxt context.Context, id string) (UserDetails, error)

	/*
		ListAllUsers query for all users in system

		 @param ctxt context.Context - context calling this API
		 @return the list of users in system
	*/
	ListAllUsers(ctxt context.Context) ([]UserInfo, error)

	/*
		DeleteUser deletes a user

		 @param ctxt context.Context - context calling this API
		 @param id string - user entry ID
		 @return whether successful
	*/
	DeleteUser(ctxt context.Context, id string) error

	/*
		UpdateUser update the parameters for a user

		 @param ctxt context.Context - context calling this API
		 @param id string - user entry ID
		 @param newConfig UserConfig - new user config
		 @return whether successful
	*/
	UpdateUser(ctxt context.Context, id string, newConfig UserConfig) error

	/*
		AddRolesToUser add new roles to a user

		 @param ctxt context.Context - context calling this API
		 @param id string - user entry ID
		 @param newRoles []string - new roles for this user
		 @return whether successful
	*/
	AddRolesToUser(ctxt context.Context, id string, newRoles []string) error

	/*
		SetUserRoles change the roles of a user

		 @param ctxt context.Context - context calling this API
		 @param id string - user entry ID
		 @param newRoles []string - new roles for this user
		 @return whether successful
	*/
	SetUserRoles(ctxt context.Context, id string, newRoles []string) error

	/*
		RemoveRolesFromUser remove roles from user

		 @param ctxt context.Context - context calling this API
		 @param id string - user entry ID
		 @param roles []string - roles to remove from user
		 @return whether successful
	*/
	RemoveRolesFromUser(ctxt context.Context, id string, roles []string) error
}

ManagementDBClient is the DB client for managing user and roles

func CreateManagementDBClient

func CreateManagementDBClient(db *gorm.DB, validateSupport common.CustomFieldValidator) (
	ManagementDBClient, error,
)

CreateManagementDBClient create a new DB client

@param db *gorm.DB - GORM DB client
@return client

type UserConfig

type UserConfig struct {
	// UserID is the user's ID
	UserID string `json:"user_id" gorm:"uniqueIndex" validate:"required,user_id"`
	// UserName is the username
	Username *string `json:"username,omitempty" validate:"omitempty,username"`
	// Email is the user's email
	Email *string `json:"email,omitempty" validate:"omitempty,email"`
	// FirstName is the user's first name / given name
	FirstName *string `json:"first_name,omitempty" validate:"omitempty,personal_name"`
	// LastName is the user's last name / surname / family name
	LastName *string `json:"last_name,omitempty" validate:"omitempty,personal_name"`
}

UserConfig is user create / update parameters

type UserDetails

type UserDetails struct {
	UserInfo
	// Roles are the roles associated with the user
	Roles []string `json:"roles"`
}

UserDetails is information regarding a user with additional information

type UserInfo

type UserInfo struct {
	// CreatedAt is when the user entry is created
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is when the user entry was last updated
	UpdatedAt time.Time `json:"updated_at"`
	UserConfig
}

UserInfo is information regarding a user

Jump to

Keyboard shortcuts

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