models

package
v0.0.0-...-b600c66 Latest Latest
Warning

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

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

Documentation

Overview

Copyright 2022 Red Hat Inc. SPDX-License-Identifier: Apache-2.0

Index

Constants

View Source
const (
	StatusError = iota - 1
	StatusFailed
	StatusPending
	StatusPartial
	StatusComplete
)

Variables

View Source
var ErrRecordNotFound = errors.New("record not found")

Functions

This section is empty.

Types

type APIExport

type APIExport struct {
	ID          uuid.UUID  `json:"id"`
	Name        string     `json:"name"`
	CreatedAt   time.Time  `json:"created_at"`
	CompletedAt *time.Time `json:"completed_at,omitempty"`
	Expires     *time.Time `json:"expires_at,omitempty"`
	Format      string     `json:"format"`
	Status      string     `json:"status"`
}

APIExport represents select fields of the ExportPayload which are returned to the user

type DBInterface

type DBInterface interface {
	APIList(user User, params *QueryParams, offset, limit int, sort, dir string) (result []*APIExport, count int64, err error)

	Create(payload *ExportPayload) (result *ExportPayload, err error)
	Delete(exportUUID uuid.UUID, user User) error
	Get(exportUUID uuid.UUID) (result *ExportPayload, err error)
	GetWithUser(exportUUID uuid.UUID, user User) (result *ExportPayload, err error)
	List(user User) (result []*ExportPayload, err error)
	Raw(sql string, values ...interface{}) *gorm.DB
	Updates(m *ExportPayload, values interface{}) error
	DeleteExpiredExports() error
}

type ExportDB

type ExportDB struct {
	DB  *gorm.DB
	Cfg *config.ExportConfig
}

func (*ExportDB) APIList

func (edb *ExportDB) APIList(user User, params *QueryParams, offset, limit int, sort, dir string) (result []*APIExport, count int64, err error)

func (*ExportDB) Create

func (edb *ExportDB) Create(payload *ExportPayload) (*ExportPayload, error)

func (*ExportDB) Delete

func (edb *ExportDB) Delete(exportUUID uuid.UUID, user User) error

func (*ExportDB) DeleteExpiredExports

func (edb *ExportDB) DeleteExpiredExports() error

func (*ExportDB) Get

func (edb *ExportDB) Get(exportUUID uuid.UUID) (result *ExportPayload, err error)

func (*ExportDB) GetWithUser

func (edb *ExportDB) GetWithUser(exportUUID uuid.UUID, user User) (result *ExportPayload, err error)

func (*ExportDB) List

func (edb *ExportDB) List(user User) (result []*ExportPayload, err error)

func (*ExportDB) Raw

func (edb *ExportDB) Raw(sql string, values ...interface{}) *gorm.DB

func (*ExportDB) Updates

func (edb *ExportDB) Updates(m *ExportPayload, values interface{}) error

type ExportPayload

type ExportPayload struct {
	ID          uuid.UUID `gorm:"type:uuid;primarykey"`
	CreatedAt   time.Time `gorm:"autoCreateTime"`
	UpdatedAt   time.Time `gorm:"autoUpdateTime"`
	CompletedAt *time.Time
	Expires     *time.Time
	RequestID   string
	Name        string
	Format      PayloadFormat `gorm:"type:string"`
	Status      PayloadStatus `gorm:"type:string"`
	Sources     []Source      `gorm:"foreignKey:ExportPayloadID"`
	S3Key       string
	User
}

func (*ExportPayload) BeforeCreate

func (ep *ExportPayload) BeforeCreate(tx *gorm.DB) (err error)

func (*ExportPayload) GetAllSourcesStatus

func (ep *ExportPayload) GetAllSourcesStatus() (int, error)

GetAllSourcesStatus gets the status for all of the sources. This function can return these different states:

  • StatusError - failed to retrieve sources
  • StatusComplete - sources are all complete as success
  • StatusPending - sources are still pending
  • StatusPartial - sources are all complete, some sources are a failure
  • StatusFailed - all sources have failed

func (*ExportPayload) GetSource

func (ep *ExportPayload) GetSource(uid uuid.UUID) (int, *Source, error)

func (*ExportPayload) GetSources

func (ep *ExportPayload) GetSources() ([]Source, error)

func (*ExportPayload) SetSourceStatus

func (ep *ExportPayload) SetSourceStatus(db DBInterface, uid uuid.UUID, status ResourceStatus, sourceError *SourceError) error

func (*ExportPayload) SetStatusComplete

func (ep *ExportPayload) SetStatusComplete(db DBInterface, t *time.Time, s3key string) error

func (*ExportPayload) SetStatusFailed

func (ep *ExportPayload) SetStatusFailed(db DBInterface) error

func (*ExportPayload) SetStatusPartial

func (ep *ExportPayload) SetStatusPartial(db DBInterface, t *time.Time, s3key string) error

func (*ExportPayload) SetStatusRunning

func (ep *ExportPayload) SetStatusRunning(db DBInterface) error

type PayloadFormat

type PayloadFormat string
const (
	CSV  PayloadFormat = "csv"
	JSON PayloadFormat = "json"
)

type PayloadStatus

type PayloadStatus string
const (
	Partial  PayloadStatus = "partial"
	Pending  PayloadStatus = "pending"
	Running  PayloadStatus = "running"
	Complete PayloadStatus = "complete"
	Failed   PayloadStatus = "failed"
)

type QueryParams

type QueryParams struct {
	Name        string
	Created     time.Time
	Expires     time.Time
	Status      string
	Application string
	Resource    string
}

QueryParams for the /export/v1/exports endpoint

type ResourceStatus

type ResourceStatus string
const (
	RPending ResourceStatus = "pending"
	RSuccess ResourceStatus = "success"
	RFailed  ResourceStatus = "failed"
)

type Source

type Source struct {
	ID              uuid.UUID `gorm:"type:uuid;primarykey"`
	ExportPayloadID uuid.UUID `gorm:"type:uuid"`
	Application     string
	Status          ResourceStatus
	Resource        string
	Filters         datatypes.JSON `gorm:"type:json"`
	*SourceError
}

func (*Source) GetFilters

func (es *Source) GetFilters() (map[string]string, error)

type SourceError

type SourceError struct {
	Message string
	Code    int
}

type User

type User struct {
	AccountID      string
	OrganizationID string
	Username       string
}

Jump to

Keyboard shortcuts

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