db

package
v0.7.7 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigDatabase

type ConfigDatabase struct {
	InMemory              bool   `envconfig:"default=true"`
	DSN                   string `envconfig:"optional"`
	User                  string `envconfig:"default=admin"`
	Name                  string `envconfig:"default=aname"`
	SSLMode               string `envconfig:"default=disable"`
	Password              string `envconfig:"default=apassword"`
	IP                    string `envconfig:"optional"`
	Instance              string `envconfig:"default=iam-service"`
	InstanceNamespace     string `envconfig:"default=dxp-system"`
	SSLCertName           string `envconfig:"default=iam-service"`
	SSLCertNamespace      string `envconfig:"default=dxp-system"`
	TmpDir                string `envconfig:"default='.'"`
	MaxIdleConns          int    `envconfig:"default=5"`
	MaxOpenConns          int    `envconfig:"default=20"`
	MaxConnLifetime       string `envconfig:"default=30m"`
	LocalData             DatabaseLocalData
	MaxSearchUsersLimit   int `envconfig:"default=5"` // defines the maximum number of users to return in a search
	MaxSearchUsersTimeout int `envconfig:"default=5"` // defines the maximum time to wait for a search to complete
}

type DataLoader

type DataLoader interface {
	LoadTenantConfigData(filePath string) error
	LoadRoleData(filePath string) error
	Close() error
	GetGormDB() *gorm.DB
}

type Database

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

Database defines a connection to a DB

func New

func New(cfg ConfigDatabase, dbConn *gorm.DB, logger *logger.Logger, migrate bool, isLocal bool) (*Database, error)

New returns an initialized Database struct

func (*Database) Close

func (d *Database) Close() error

Close closes the database connection

func (*Database) DeleteInvite

func (d *Database) DeleteInvite(ctx context.Context, criteria Invite) error

func (*Database) DeleteInvitesForEmail

func (d *Database) DeleteInvitesForEmail(ctx context.Context, tenantID, email string) error

func (*Database) GetGormDB

func (d *Database) GetGormDB() *gorm.DB

func (*Database) GetInvitesForEmail

func (d *Database) GetInvitesForEmail(ctx context.Context, tenantID, email string) ([]Invite, error)

func (*Database) GetInvitesForEntity

func (d *Database) GetInvitesForEntity(ctx context.Context, tenantID, entityType, entityID string) ([]Invite, error)

func (*Database) GetOrCreateUser

func (d *Database) GetOrCreateUser(ctx context.Context, tenantID string, input graph.UserInput) (*graph.User, error)

func (*Database) GetRolesByTechnicalNames

func (d *Database) GetRolesByTechnicalNames(ctx context.Context, entityType string, technicalNames []string) ([]*Role, error)

func (*Database) GetRolesForEntity

func (d *Database) GetRolesForEntity(ctx context.Context, entityType string, entityID string) ([]Role, error)

func (*Database) GetTenantConfigurationByIssuerAndAudience

func (d *Database) GetTenantConfigurationByIssuerAndAudience(
	ctx context.Context, issuer string, audiences []string,
) (*TenantConfiguration, error)

func (*Database) GetTenantConfigurationForContext

func (d *Database) GetTenantConfigurationForContext(ctx context.Context) (*TenantConfiguration, error)

func (*Database) GetUserByEmail

func (d *Database) GetUserByEmail(ctx context.Context, tenantID string, email string) (*graph.User, error)

GetUserByEmail returns user by email

func (*Database) GetUserByID

func (d *Database) GetUserByID(ctx context.Context, tenantID string, userID string) (*graph.User, error)

GetUserByID returns a member by ID

func (*Database) GetUserHooks

func (d *Database) GetUserHooks() UserHooks

func (*Database) GetUsers

func (d *Database) GetUsers(ctx context.Context, tenantID string, limit int, page int) (*graph.UserConnection, error)

GetUsers returns all existing users for a tenant

func (*Database) GetUsersByUserIDs

func (d *Database) GetUsersByUserIDs(
	ctx context.Context, tenantID string, userIDs []string, limit, page int, searchTerm *string,
	sortBy *graph.SortByInput,
) ([]*graph.User, error)

GetUsersByUserIDs returns a member by ID, limiting response to the current page contents and using a search filter for user_id, first_name, last_name and email

func (*Database) InviteUser

func (d *Database) InviteUser(ctx context.Context, tenantID string, invite graph.Invite, notifyByEmail bool) error

func (*Database) LoadInvitationData

func (d *Database) LoadInvitationData(filePath string) error

func (*Database) LoadRoleData

func (d *Database) LoadRoleData(filePath string) error

func (*Database) LoadTeamData

func (d *Database) LoadTeamData(filePath string, users []*graph.User) error

func (*Database) LoadTenantConfigData

func (d *Database) LoadTenantConfigData(filePath string) error

TODO: TenantContfig update / Delete not yet implemented.

func (*Database) LoadUserData

func (d *Database) LoadUserData(filePath string) ([]*graph.User, error)

func (*Database) LoginUserWithToken added in v0.4.2

func (d *Database) LoginUserWithToken(ctx context.Context, tokenInfo jwt.WebToken, userID string, tenantID string, user *graph.User, email string) error

func (*Database) RemoveRoleFromInvite

func (d *Database) RemoveRoleFromInvite(ctx context.Context, criteria Invite, roleToDelete string) error

func (*Database) RemoveUser

func (d *Database) RemoveUser(ctx context.Context, tenantID string, userID string, email string) (bool, error)

RemoveUser removes user it returns true if user entry is no longer exists.

func (*Database) Save

func (d *Database) Save(user *graph.User) error

func (*Database) SearchUsers

func (d *Database) SearchUsers(ctx context.Context, tenantId, query string) ([]*graph.User, error)

func (*Database) SetConfig

func (d *Database) SetConfig(cfg ConfigDatabase)

func (*Database) SetUserHooks

func (d *Database) SetUserHooks(hooks UserHooks)

type DatabaseLocalData

type DatabaseLocalData struct {
	DataPathUser                string `envconfig:"default=input/user.yaml"`
	DataPathInvitations         string `envconfig:"default=input/invitations.yaml"`
	DataPathTeam                string `envconfig:"default=input/team.yaml"`
	DataPathTenantConfiguration string `envconfig:"default=input/tenantConfigurations.yaml"`
	DataPathRoles               string `envconfig:"optional"`
	DataPathDomainConfiguration string `envconfig:"default=input/domainConfigurations.yaml"`
}

type Invite

type Invite struct {
	TenantID   string `gorm:"primaryKey"`
	Email      string `gorm:"primaryKey"`
	EntityType string `gorm:"primaryKey"`
	EntityID   string `gorm:"primaryKey"`
	Roles      string
}

type InviteList

type InviteList struct {
	Invitations []Invite
}

type Role

type Role struct {
	gorm.Model
	ID            string `gorm:"type:uuid;primaryKey"`
	DisplayName   string `gorm:"not null"`
	TechnicalName string `gorm:"not null;uniqueIndex:idx_technical_name_entity_type_entity_id"`
	EntityType    string `gorm:"not null;uniqueIndex:idx_technical_name_entity_type_entity_id"`
	EntityID      string `gorm:"uniqueIndex:idx_technical_name_entity_type_entity_id;default:''"`
}

func (*Role) BeforeCreate

func (r *Role) BeforeCreate(tx *gorm.DB) (err error)

type Service

type Service interface {
	UserService

	Save(user *graph.User) error
	Close() error

	// tenant
	GetTenantConfigurationForContext(ctx context.Context) (*TenantConfiguration, error)

	// roles
	GetRolesForEntity(ctx context.Context, entityType string, entityID string) ([]Role, error)
	GetRolesByTechnicalNames(ctx context.Context, entityType string, technicalNames []string) ([]*Role, error)
}

type TeamList

type TeamList struct {
	Team []struct {
		ID          string   `json:"id"`
		TenantID    string   `json:"tenantId"`
		Name        string   `json:"name"`
		DisplayName string   `json:"displayName"`
		Members     []string `json:"members"`
		ParentTeam  *string  `json:"parentTeam"`
	}
}

type TenantConfiguration

type TenantConfiguration struct {
	TenantID string `gorm:"primary_key"`
	Issuer   string `gorm:"primary_key"`
	Audience string `gorm:"primary_key"`

	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

type TenantConfigurationsList

type TenantConfigurationsList struct {
	Configs []TenantConfiguration `json:"configs"`
}

type User

type User struct {
	ID                    string  `json:"id"`
	TenantID              string  `json:"tenant_id"`
	UserID                string  `json:"user_id"`
	Email                 string  `json:"email"`
	FirstName             *string `json:"first_name"`
	LastName              *string `json:"last_name"`
	InvitationOutstanding bool
}

type UserHooks

type UserHooks interface {
	UserInvited(ctx context.Context, user *graph.User, tenantID string, scope string, userInvited bool)
	UserCreated(ctx context.Context, user *graph.User, tenantID string)
	UserRemoved(ctx context.Context, user *graph.User, tenantID string)
	UserLogin(ctx context.Context, user *graph.User, tenantID string)
}

type UserList

type UserList struct {
	User []User
}

type UserService

type UserService interface {
	GetUserByID(ctx context.Context, tenantID string, userId string) (*graph.User, error)
	GetUsersByUserIDs(
		ctx context.Context, tenantID string, userIDs []string, limit, page int, searchTerm *string,
		sortBy *graph.SortByInput,
	) ([]*graph.User, error)
	GetUserByEmail(ctx context.Context, tenantID string, email string) (*graph.User, error)
	GetOrCreateUser(ctx context.Context, tenantID string, input graph.UserInput) (*graph.User, error)
	RemoveUser(ctx context.Context, tenantID string, userId string, email string) (bool, error)
	GetUsers(ctx context.Context, tenantID string, limit int, page int) (*graph.UserConnection, error)
	GetInvitesForEntity(ctx context.Context, tenantID, entityType, entityID string) ([]Invite, error)
	RemoveRoleFromInvite(ctx context.Context, criteria Invite, roleToDelete string) error
	DeleteInvite(ctx context.Context, criteria Invite) error
	InviteUser(ctx context.Context, tenantID string, invite graph.Invite, notifyByEmail bool) error
	SearchUsers(ctx context.Context, tenantID, query string) ([]*graph.User, error)
	LoginUserWithToken(ctx context.Context, tokenInfo jwt.WebToken, userID string, tenantID string, user *graph.User, email string) error
	// hooks
	SetUserHooks(hooks UserHooks)
	GetUserHooks() UserHooks
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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