dao

package
v0.0.0-...-5f0b682 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultLimit  = 100
	DefaultOffset = 0
)
View Source
const (
	AwsWizardAccountNumberSetting = "aws_wizard_account_number"
	RetrySourceCreationSetting    = "retry_source_creation"
)
View Source
const (
	// PgUniqueConstraintViolation is PostgreSQL error code for unique index violation (more here: https://www.postgresql.org/docs/current/errcodes-appendix.html)
	PgUniqueConstraintViolation = "23505"
)

PostgreSQL Error Codes

Variables

View Source
var (
	DB *gorm.DB

	Vault          vault.VaultClient
	SecretsManager amazon.SecretsManagerClient
)
View Source
var GetApplicationAuthenticationDao func(*RequestParams) ApplicationAuthenticationDao

GetApplicationAuthenticationDao is a function definition that can be replaced in runtime in case some other DAO provider is needed.

View Source
var GetApplicationDao func(*RequestParams) ApplicationDao

GetApplicationDao is a function definition that can be replaced in runtime in case some other DAO provider is needed.

View Source
var GetApplicationTypeDao func(*int64) ApplicationTypeDao

GetApplicationTypeDao is a function definition that can be replaced in runtime in case some other DAO provider is needed.

View Source
var GetAuthenticationDao func(daoParams *RequestParams) AuthenticationDao

GetAuthenticationDao is a function definition that can be replaced in runtime in case some other DAO provider is needed.

View Source
var GetEndpointDao func(*int64) EndpointDao

GetEndpointDao is a function definition that can be replaced in runtime in case some other DAO provider is needed.

View Source
var GetMetaDataDao func() MetaDataDao

GetMetaDataDao is a function definition that can be replaced in runtime in case some other DAO provider is needed.

View Source
var GetRhcConnectionDao func(*RequestParams) RhcConnectionDao

GetRhcConnectionDao is a function definition that can be replaced in runtime in case some other DAO provider is needed.

View Source
var GetSecretDao func(daoParams *RequestParams) SecretDao
View Source
var GetSourceDao func(*RequestParams) SourceDao

GetSourceDao is a function definition that can be replaced in runtime in case some other DAO provider is needed.

View Source
var GetSourceTypeDao func() SourceTypeDao

GetSourceTypeDao is a function definition that can be replaced in runtime in case some other DAO provider is needed.

View Source
var GetTenantDao func() TenantDao

GetTenantDao is a function definition that can be replaced in runtime in case some other DAO provider is needed.

View Source
var GetUserDao func(*int64) UserDao
View Source
var Static typeCache

Package level Type cache - to be accessed from anywhere

Functions

func BulkMessageFromSource

func BulkMessageFromSource(source *m.Source, authentication *m.Authentication) (map[string]interface{}, error)
	Method generates bulk message for Source record.
	authentication - specify resource (ResourceID and ResourceType) of
                     which authentications are fetched to BulkMessage
                   - specify application_authentications in BulkMessage otherwise
                     application_authentications are obtained from authentications UIDs
					 in BulkMessage

func CreateApplication

func CreateApplication(sourceID int64, applicationTypeID int64, tenantID int64, userID *int64) (*m.Application, error)

func CreateApplicationAuthentication

func CreateApplicationAuthentication(authID int64, appID int64, hello int64, userID *int64) (*m.ApplicationAuthentication, error)

func CreateAuthenticationFromApplication

func CreateAuthenticationFromApplication(appID int64, tenantID int64, userID *int64) (*m.Authentication, error)

func CreateSecretByName

func CreateSecretByName(name string, tenantID *int64, userID *int64) (*m.Authentication, error)

func CreateSource

func CreateSource(sourceTypeID int64, tenantID int64, userID *int64) (*m.Source, error)

func CreateSourceWithSubResources

func CreateSourceWithSubResources(sourceTypeID int64, applicationTypeID int64, accountNumber string, userIDFromHeader *string) (*m.BulkCreateOutput, *m.User, error)

func CreateTenantForAccountNumber

func CreateTenantForAccountNumber(accountNumber string) (*int64, error)

func CreateUserForUserID

func CreateUserForUserID(userIDFromHeader string, tenantID int64) (*m.User, error)

func GetAvailabilityStatusFromStatusMessage

func GetAvailabilityStatusFromStatusMessage(tenantID int64, resourceID string, resourceType string) (string, error)

func GetFromResourceType

func GetFromResourceType(resourceType string, tenantID int64) (m.EventModelDao, error)

func Init

func Init()

func PopulateMockStaticTypeCache

func PopulateMockStaticTypeCache() error

func PopulateStaticTypeCache

func PopulateStaticTypeCache() error

Fetches every Source+Application Type record from the database and builds out the cache. Returns an error if it fails (e.g. the app shouldn't be running then)

func TestSuiteForSourceWithOwnership

func TestSuiteForSourceWithOwnership(performTest func(suiteData *SourceOwnershipDataTestSuite) error) error

Types

type ApplicationAuthenticationDao

type ApplicationAuthenticationDao interface {
	List(limit, offset int, filters []util.Filter) ([]m.ApplicationAuthentication, int64, error)
	GetById(id *int64) (*m.ApplicationAuthentication, error)
	Create(src *m.ApplicationAuthentication) error
	Update(src *m.ApplicationAuthentication) error
	Delete(id *int64) (*m.ApplicationAuthentication, error)
	Tenant() *int64
	ApplicationAuthenticationsByResource(resourceType string, applications []m.Application, authentications []m.Authentication) ([]m.ApplicationAuthentication, error)
}

type ApplicationDao

type ApplicationDao interface {
	List(limit, offset int, filters []util.Filter) ([]m.Application, int64, error)
	SubCollectionList(primaryCollection interface{}, limit, offset int, filters []util.Filter) ([]m.Application, int64, error)
	GetById(id *int64) (*m.Application, error)
	Create(src *m.Application) error
	Update(src *m.Application) error
	Delete(id *int64) (*m.Application, error)
	Tenant() *int64
	User() *int64
	BulkMessage(resource util.Resource) (map[string]interface{}, error)
	FetchAndUpdateBy(resource util.Resource, updateAttributes map[string]interface{}) (interface{}, error)
	ToEventJSON(resource util.Resource) ([]byte, error)
	// Pause pauses the application.
	Pause(id int64) error
	// Unpause resumes the application.
	Unpause(id int64) error
	GetByIdWithPreload(id *int64, preloads ...string) (*m.Application, error)
	IsSuperkey(id int64) bool
	// DeleteCascade deletes the application along with all its related application authentications.
	DeleteCascade(applicationId int64) ([]m.ApplicationAuthentication, *m.Application, error)
	// Exists returns true if the application exists.
	Exists(applicationId int64) (bool, error)
}

type ApplicationTypeDao

type ApplicationTypeDao interface {
	List(limit, offset int, filters []util.Filter) ([]m.ApplicationType, int64, error)
	SubCollectionList(primaryCollection interface{}, limit, offset int, filters []util.Filter) ([]m.ApplicationType, int64, error)
	GetById(id *int64) (*m.ApplicationType, error)
	Create(src *m.ApplicationType) error
	Update(src *m.ApplicationType) error
	Delete(id *int64) error
	ApplicationTypeCompatibleWithSource(typeId, sourceId int64) error
	GetSuperKeyResultType(applicationTypeId int64, authType string) (string, error)
	ApplicationTypeCompatibleWithSourceType(appTypeId, sourceTypeId int64) error
	GetByName(name string) (*m.ApplicationType, error)
}

type AuthenticationDao

type AuthenticationDao interface {
	List(limit, offset int, filters []util.Filter) ([]m.Authentication, int64, error)
	GetById(id string) (*m.Authentication, error)
	ListForSource(sourceID int64, limit, offset int, filters []util.Filter) ([]m.Authentication, int64, error)
	ListForApplication(applicationID int64, limit, offset int, filters []util.Filter) ([]m.Authentication, int64, error)
	ListForApplicationAuthentication(appAuthID int64, limit, offset int, filters []util.Filter) ([]m.Authentication, int64, error)
	ListForEndpoint(endpointID int64, limit, offset int, filters []util.Filter) ([]m.Authentication, int64, error)
	Create(src *m.Authentication) error
	BulkCreate(src *m.Authentication) error
	Update(src *m.Authentication) error
	Delete(id string) (*m.Authentication, error)
	Tenant() *int64
	AuthenticationsByResource(authentication *m.Authentication) ([]m.Authentication, error)
	BulkMessage(resource util.Resource) (map[string]interface{}, error)
	FetchAndUpdateBy(resource util.Resource, updateAttributes map[string]interface{}) (interface{}, error)
	ToEventJSON(resource util.Resource) ([]byte, error)
	// ListIdsForResource fetches all the authentication IDs for the given resource. The rest of the fields will be
	// either nil or default values.
	ListIdsForResource(resourceType string, resourceIds []int64) ([]m.Authentication, error)
	// BulkDelete deletes all the authentications given as a list, and returns the ones that were deleted.
	BulkDelete(authentications []m.Authentication) ([]m.Authentication, error)
}

type EndpointDao

type EndpointDao interface {
	List(limit, offset int, filters []util.Filter) ([]m.Endpoint, int64, error)
	SubCollectionList(primaryCollection interface{}, limit, offset int, filters []util.Filter) ([]m.Endpoint, int64, error)
	GetById(id *int64) (*m.Endpoint, error)
	Create(src *m.Endpoint) error
	Update(src *m.Endpoint) error
	Delete(id *int64) (*m.Endpoint, error)
	Tenant() *int64
	// CanEndpointBeSetAsDefaultForSource checks if the endpoint can be set as default, by checking if the given source
	// id already has another endpoint marked as default.
	CanEndpointBeSetAsDefaultForSource(sourceId int64) bool
	// IsRoleUniqueForSource checks if the role is unique for the given source ID.
	IsRoleUniqueForSource(role string, sourceId int64) bool
	// SourceHasEndpoints returns true if the provided source has any associated endpoints.
	SourceHasEndpoints(sourceId int64) bool
	BulkMessage(resource util.Resource) (map[string]interface{}, error)
	FetchAndUpdateBy(resource util.Resource, updateAttributes map[string]interface{}) (interface{}, error)
	ToEventJSON(resource util.Resource) ([]byte, error)
	// Exists returns true if the endpoint exists.
	Exists(endpointId int64) (bool, error)
}

type MetaDataDao

type MetaDataDao interface {
	List(limit, offset int, filters []util.Filter) ([]m.MetaData, int64, error)
	SubCollectionList(primaryCollection interface{}, limit, offset int, filters []util.Filter) ([]m.MetaData, int64, error)
	GetById(id *int64) (*m.MetaData, error)
	GetSuperKeySteps(applicationTypeId int64) ([]m.MetaData, error)
	GetSuperKeyAccountNumber(applicationTypeId int64) (string, error)
	ApplicationOptedIntoRetry(applicationTypeId int64) (bool, error)
}

type RequestParams

type RequestParams struct {
	TenantID *int64
	UserID   *int64
	// contains filtered or unexported fields
}

func NewRequestParamsFromContext

func NewRequestParamsFromContext(c echo.Context) (*RequestParams, error)

type RhcConnectionDao

type RhcConnectionDao interface {
	List(limit, offset int, filters []util.Filter) ([]m.RhcConnection, int64, error)
	GetById(id *int64) (*m.RhcConnection, error)
	Create(rhcConnection *m.RhcConnection) (*m.RhcConnection, error)
	Update(rhcConnection *m.RhcConnection) error
	Delete(id *int64) (*m.RhcConnection, error)
	// ListForSource gets all the related connections to the given source id.
	ListForSource(sourceId *int64, limit, offset int, filters []util.Filter) ([]m.RhcConnection, int64, error)
}

type SecretDao

type SecretDao interface {
	Create(src *m.Authentication) error
	Delete(id *int64) error
	GetById(id *int64) (*m.Authentication, error)
	List(limit, offset int, filters []util.Filter) ([]m.Authentication, int64, error)
	NameExistsInCurrentTenant(name string) bool
	Update(src *m.Authentication) error
}

type SourceDao

type SourceDao interface {
	// List lists all the sources from a given tenant, which should be specified in the request.
	List(limit, offset int, filters []util.Filter) ([]m.Source, int64, error)
	// ListInternal lists all the existing sources.
	ListInternal(limit, offset int, filters []util.Filter) ([]m.Source, int64, error)
	SubCollectionList(primaryCollection interface{}, limit, offset int, filters []util.Filter) ([]m.Source, int64, error)
	GetById(id *int64) (*m.Source, error)
	Create(src *m.Source) error
	Update(src *m.Source) error
	Delete(id *int64) (*m.Source, error)
	Tenant() *int64
	User() *int64
	NameExistsInCurrentTenant(name string) bool
	GetByIdWithPreload(id *int64, preloads ...string) (*m.Source, error)
	// ListForRhcConnection gets all the sources that are related to a given rhcConnection id.
	ListForRhcConnection(rhcConnectionId *int64, limit, offset int, filters []util.Filter) ([]m.Source, int64, error)
	BulkMessage(resource util.Resource) (map[string]interface{}, error)
	FetchAndUpdateBy(resource util.Resource, updateAttributes map[string]interface{}) (interface{}, error)
	ToEventJSON(resource util.Resource) ([]byte, error)
	// Pause pauses the given source and all its dependant applications.
	Pause(id int64) error
	// Unpause resumes the given source and all its dependant applications.
	Unpause(id int64) error
	IsSuperkey(id int64) bool
	// DeleteCascade deletes the source along with all its related sub resources. It returns all the deleted
	// sub resources and the source itself.
	DeleteCascade(sourceId int64) ([]m.ApplicationAuthentication, []m.Application, []m.Endpoint, []m.RhcConnection, *m.Source, error)
	// Exists returns true if the source exists.
	Exists(sourceId int64) (bool, error)
}

type SourceOwnershipDataTestSuite

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

func (*SourceOwnershipDataTestSuite) ApplicationAuthenticationNoUser

func (s *SourceOwnershipDataTestSuite) ApplicationAuthenticationNoUser() *m.ApplicationAuthentication

func (*SourceOwnershipDataTestSuite) ApplicationAuthenticationUserA

func (s *SourceOwnershipDataTestSuite) ApplicationAuthenticationUserA() *m.ApplicationAuthentication

func (*SourceOwnershipDataTestSuite) ApplicationAuthenticationUserB

func (s *SourceOwnershipDataTestSuite) ApplicationAuthenticationUserB() *m.ApplicationAuthentication

func (*SourceOwnershipDataTestSuite) ApplicationNoUser

func (s *SourceOwnershipDataTestSuite) ApplicationNoUser() *m.Application

func (*SourceOwnershipDataTestSuite) ApplicationUserA

func (s *SourceOwnershipDataTestSuite) ApplicationUserA() *m.Application

func (*SourceOwnershipDataTestSuite) ApplicationUserB

func (s *SourceOwnershipDataTestSuite) ApplicationUserB() *m.Application

func (*SourceOwnershipDataTestSuite) AuthenticationNoUser

func (s *SourceOwnershipDataTestSuite) AuthenticationNoUser() *m.Authentication

func (*SourceOwnershipDataTestSuite) AuthenticationUserA

func (s *SourceOwnershipDataTestSuite) AuthenticationUserA() *m.Authentication

func (*SourceOwnershipDataTestSuite) AuthenticationUserB

func (s *SourceOwnershipDataTestSuite) AuthenticationUserB() *m.Authentication

func (*SourceOwnershipDataTestSuite) GetRequestParamsUserA

func (s *SourceOwnershipDataTestSuite) GetRequestParamsUserA() *RequestParams

func (*SourceOwnershipDataTestSuite) GetRequestParamsUserB

func (s *SourceOwnershipDataTestSuite) GetRequestParamsUserB() *RequestParams

func (*SourceOwnershipDataTestSuite) SourceIDsNoUser

func (s *SourceOwnershipDataTestSuite) SourceIDsNoUser() []int64

func (*SourceOwnershipDataTestSuite) SourceIDsUserA

func (s *SourceOwnershipDataTestSuite) SourceIDsUserA() []int64

func (*SourceOwnershipDataTestSuite) SourceNoUser

func (s *SourceOwnershipDataTestSuite) SourceNoUser() *m.Source

func (*SourceOwnershipDataTestSuite) SourceUserA

func (s *SourceOwnershipDataTestSuite) SourceUserA() *m.Source

func (*SourceOwnershipDataTestSuite) SourceUserB

func (s *SourceOwnershipDataTestSuite) SourceUserB() *m.Source

func (*SourceOwnershipDataTestSuite) TenantID

func (s *SourceOwnershipDataTestSuite) TenantID() *int64

func (*SourceOwnershipDataTestSuite) UserA

func (s *SourceOwnershipDataTestSuite) UserA() *m.User

func (*SourceOwnershipDataTestSuite) UserWithoutOwnership

func (s *SourceOwnershipDataTestSuite) UserWithoutOwnership() *m.User

type SourceTypeDao

type SourceTypeDao interface {
	List(limit, offset int, filters []util.Filter) ([]m.SourceType, int64, error)
	GetById(id *int64) (*m.SourceType, error)
	Create(src *m.SourceType) error
	Update(src *m.SourceType) error
	Delete(id *int64) error
	GetByName(name string) (*m.SourceType, error)
}

type TenantDao

type TenantDao interface {
	// GetOrCreateTenant returns the tenant associated with the provided identity. It tries to fetch the tenant by its
	// OrgId, and if it is not present, by its EBS account number.
	GetOrCreateTenant(identity *identity.Identity) (*m.Tenant, error)
	// TenantByIdentity returns the tenant associated to the given identity. It tries to fetch the tenant by its OrgId,
	// and if it is not preset, by its EBS account number.
	TenantByIdentity(identity *identity.Identity) (*m.Tenant, error)
	// GetUntranslatedTenants returns a list of tenants which only have an EBS account number and not a corresponding
	// OrgId.
	GetUntranslatedTenants() ([]m.Tenant, error)
	// TranslateTenants attempts to translate tenants which only have an EBS account number. It takes batches of 100
	// tenants and tries to get an "org_id" translation for the "external_tenant" number.
	//
	// Returns the total number of translatable tenants, number of translated tenants, untranslated tenants and each
	// translation operation's results. It doesn't error when a tenant cannot be translated.
	TranslateTenants() (int64, uint64, uint64, []m.TenantTranslation, error)
}

type UserDao

type UserDao interface {
	FindOrCreate(userID string) (*m.User, error)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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