model

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SnapshotVersionV1 = 1 + iota
	SnapshotVersionV2
)
View Source
const (
	SourceTypeAgent   string = "agent"
	SourceTypeRvtools string = "rvtools"
)
View Source
const (
	JobStatusPending    = "pending"
	JobStatusParsing    = "parsing"
	JobStatusValidating = "validating"
	JobStatusCompleted  = "completed"
	JobStatusFailed     = "failed"
	JobStatusCancelled  = "cancelled"
)

Job status constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	gorm.Model
	ID         uuid.UUID `json:"id" gorm:"primaryKey"`
	Status     string
	StatusInfo string
	CredUrl    string
	Version    string
	SourceID   uuid.UUID
}

func NewAgentForSource

func NewAgentForSource(id uuid.UUID, source Source) Agent

func (Agent) String

func (a Agent) String() string

type AgentList

type AgentList []Agent

type Assessment

type Assessment struct {
	ID             uuid.UUID `gorm:"primaryKey;column:id;type:VARCHAR(255);"`
	CreatedAt      time.Time `gorm:"not null;default:now()"`
	UpdatedAt      *time.Time
	Name           string     `gorm:"not null;uniqueIndex:org_id_user_name"`
	OrgID          string     `gorm:"not null;uniqueIndex:org_id_user_name;index:assessments_org_id_idx"`
	Username       string     `gorm:"type:VARCHAR(255);uniqueIndex:org_id_user_name"`
	OwnerFirstName *string    `gorm:"type:VARCHAR(100)"`
	OwnerLastName  *string    `gorm:"type:VARCHAR(100)"`
	SourceType     string     `gorm:"not null;type:VARCHAR(100)"`
	SourceID       *uuid.UUID `gorm:"type:TEXT"`
	Snapshots      []Snapshot `gorm:"foreignKey:AssessmentID;references:ID;constraint:OnDelete:CASCADE;"`
}

func (Assessment) String

func (a Assessment) String() string

type AssessmentList

type AssessmentList []Assessment

type CustomerAssessments added in v0.2.2

type CustomerAssessments struct {
	AgentCount  int
	RvToolCount int
}

type ImageInfra

type ImageInfra struct {
	gorm.Model
	SourceID         uuid.UUID `gorm:"primaryKey"`
	HttpProxyUrl     string
	HttpsProxyUrl    string
	NoProxyDomains   string
	CertificateChain string
	SshPublicKey     string
	ImageTokenKey    string
	IpAddress        string
	SubnetMask       string
	DefaultGateway   string
	Dns              string
	AgentVersion     *string
}

type InventoryStats

type InventoryStats struct {
	Vms                                VmStats
	Os                                 OsStats
	TotalCustomers                     int
	TotalAssessmentsByCustomerBySource map[string]CustomerAssessments
	TotalInventories                   int
	Storage                            []StorageCustomerStats
}

func NewInventoryStats

func NewInventoryStats(assessments []Assessment) InventoryStats

type JSONField

type JSONField[T any] struct {
	Data T
}

JSONField wraps an arbitrary struct so that it can be included in a GORM model, for use in a JSON/JSONB field

func MakeJSONField

func MakeJSONField[T any](data T) *JSONField[T]

Return a copy of 'data', wrapped in a JSONField object

func (JSONField[T]) MarshalJSON

func (j JSONField[T]) MarshalJSON() ([]byte, error)

func (*JSONField[T]) Scan

func (j *JSONField[T]) Scan(src any) error

func (*JSONField[T]) UnmarshalJSON

func (j *JSONField[T]) UnmarshalJSON(b []byte) error

func (JSONField[T]) Value

func (j JSONField[T]) Value() (driver.Value, error)

type Key

type Key struct {
	gorm.Model
	OrgID      string          `gorm:"primaryKey"`
	ID         string          `gorm:"not null;unique"`
	PrivateKey *rsa.PrivateKey `gorm:"type:text;not null;serializer:key_serializer"`
}

type KeySerializer

type KeySerializer struct{}

func (KeySerializer) Scan

func (ks KeySerializer) Scan(ctx context.Context, field *schema.Field, dst reflect.Value, dbValue interface{}) (err error)

func (KeySerializer) Value

func (ks KeySerializer) Value(ctx context.Context, field *schema.Field, dst reflect.Value, fieldValue interface{}) (interface{}, error)

type Label

type Label struct {
	Key      string `gorm:"primaryKey;column:key;type:VARCHAR;size:100;"`
	Value    string `gorm:"column:value;type:VARCHAR;size:100;not null"`
	SourceID string `gorm:"primaryKey;column:source_id;type:TEXT;"`
}

type Operation added in v0.10.0

type Operation int

Operation represents a write operation type.

const (
	OperationTouch  Operation = iota // create or idempotent update (upsert)
	OperationDelete                  // delete
)

type OsStats

type OsStats struct {
	// TotalTypes is total of os types. (e.g. how many different os we found)
	Total int
}

type Permission added in v0.10.0

type Permission string

Permission represents a computed permission derived from relations.

const (
	ReadPermission   Permission = "read"
	EditPermission   Permission = "edit"
	SharePermission  Permission = "share"
	DeletePermission Permission = "delete"
)

func (Permission) In added in v0.10.0

func (p Permission) In(perms []Permission) bool

In returns true if the permission is present in the given slice.

func (Permission) Relations added in v0.10.0

func (p Permission) Relations() []string

Relations returns the relation types that grant this permission.

type RVToolsJobMetadata added in v0.3.0

type RVToolsJobMetadata struct {
	Status       string     `json:"status,omitempty"`        // parsing, validating
	Error        string     `json:"error,omitempty"`         // error message if failed
	AssessmentID *uuid.UUID `json:"assessment_id,omitempty"` // set when completed
}

RVToolsJobMetadata is stored in river_job.metadata to track progress and results.

type Relation added in v0.10.0

type Relation string

Relation represents a stored relation between a resource and a subject.

const (
	OwnerRelation  Relation = "owner"
	ViewerRelation Relation = "viewer"
	MemberRelation Relation = "member"
)

func (Relation) Permissions added in v0.10.0

func (r Relation) Permissions() []Permission

Permissions returns the permissions that this relation grants.

type RelationSqlModel added in v0.10.0

type RelationSqlModel struct {
	ID               int64  `gorm:"primaryKey;autoIncrement"`
	Resource         string `gorm:"not null;uniqueIndex:uq_resource_relation"`
	ResourceID       string `gorm:"column:resource_id;not null;uniqueIndex:uq_resource_relation"`
	Relation         string `gorm:"not null;uniqueIndex:uq_resource_relation"`
	SubjectNamespace string `gorm:"column:subject_namespace;not null;uniqueIndex:uq_resource_relation"`
	SubjectID        string `gorm:"column:subject_id;not null;uniqueIndex:uq_resource_relation"`
}

RelationSqlModel is the GORM model for the relations table.

func (RelationSqlModel) TableName added in v0.10.0

func (RelationSqlModel) TableName() string

func (RelationSqlModel) ToRelationship added in v0.10.0

func (r RelationSqlModel) ToRelationship() Relationship

type Relationship added in v0.10.0

type Relationship struct {
	ResourceType ResourceType
	ResourceID   string
	Relation     Relation
	Subject      Subject
}

Relationship represents a single tuple: resource_type:resource_id#relation@subject_type:subject_id

func NewRelationship added in v0.10.0

func NewRelationship(resourceType ResourceType, resourceID string, relation Relation, subject Subject) Relationship

func (Relationship) String added in v0.10.0

func (r Relationship) String() string

func (Relationship) ToSql added in v0.10.0

func (rel Relationship) ToSql() RelationSqlModel

type RelationshipUpdate added in v0.10.0

type RelationshipUpdate struct {
	Operation    Operation
	Relationship Relationship
}

RelationshipUpdate pairs an operation with a relationship for batch writes.

type Resource added in v0.10.0

type Resource struct {
	Type        ResourceType
	ID          string
	Permissions []Permission
}

Resource identifies a resource. Permissions is populated by query methods (ListResources, GetPermissions) and nil on input (DeleteRelationships, builder).

func NewAssessmentResource added in v0.10.0

func NewAssessmentResource(id string) Resource

func NewOrgResource added in v0.10.0

func NewOrgResource(id string) Resource

type ResourceType added in v0.10.0

type ResourceType string

ResourceType identifies the type of resource in a relationship tuple.

const (
	AssessmentResource ResourceType = "assessment"
	OrgResource        ResourceType = "org"
)

type Snapshot

type Snapshot struct {
	ID           uint      `gorm:"primaryKey;autoIncrement"`
	CreatedAt    time.Time `gorm:"not null;default:now()"`
	Inventory    []byte    `gorm:"type:jsonb;not null"`
	AssessmentID uuid.UUID `gorm:"not null;type:VARCHAR(255);"`
	Version      uint      `gorm:"type:smallint;not null;default:1"`
}

func (Snapshot) String

func (s Snapshot) String() string

type Source

type Source struct {
	gorm.Model
	ID          uuid.UUID `gorm:"primaryKey;"`
	Name        string    `gorm:"uniqueIndex:sources_org_id_user_name;not null"`
	VCenterID   string
	Username    string `gorm:"uniqueIndex:sources_org_id_user_name"`
	OrgID       string `gorm:"uniqueIndex:sources_org_id_user_name;not null"`
	Inventory   []byte `gorm:"type:jsonb"`
	OnPremises  bool
	Agents      []Agent    `gorm:"constraint:OnDelete:CASCADE;"`
	ImageInfra  ImageInfra `gorm:"constraint:OnDelete:CASCADE;"`
	Labels      []Label    `gorm:"foreignKey:SourceID;references:ID;constraint:OnDelete:CASCADE;"`
	EmailDomain *string
}

func (Source) String

func (s Source) String() string

type SourceList

type SourceList []Source

type StorageCustomerStats

type StorageCustomerStats struct {
	TotalByProvider map[string]int
	Domain          string
}

type Subject added in v0.10.0

type Subject struct {
	ID   string
	Kind SubjectType
}

Subject represents the "who" in a relationship.

func NewOrgSubject added in v0.10.0

func NewOrgSubject(id string) Subject

func NewUserSubject added in v0.10.0

func NewUserSubject(id string) Subject

type SubjectType added in v0.10.0

type SubjectType string

SubjectType identifies the type of subject in a relationship tuple.

const (
	UserSubject SubjectType = "user"
	OrgSubject  SubjectType = "org"
)

type VmStats

type VmStats struct {
	// Total is the total number of vms
	Total int
	// Total number of vm by customer (key is organization id)
	TotalByCustomer map[string]int
	// Total number of vm by OS.
	TotalByOS map[string]int
}

Jump to

Keyboard shortcuts

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