model

package
v0.5.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CertificateSigningRequestAPIVersion added in v0.5.0

func CertificateSigningRequestAPIVersion() string

func CertificateSigningRequestsToApiResource added in v0.4.0

func CertificateSigningRequestsToApiResource(csrs []CertificateSigningRequest, cont *string, numRemaining *int64) (api.CertificateSigningRequestList, error)

func DeviceAPIVersion added in v0.5.0

func DeviceAPIVersion() string

func DevicesToApiResource added in v0.4.0

func DevicesToApiResource(devices []Device, cont *string, numRemaining *int64) (api.DeviceList, error)

func EnrollmentRequestAPIVersion added in v0.5.0

func EnrollmentRequestAPIVersion() string

func EnrollmentRequestsToApiResource added in v0.4.0

func EnrollmentRequestsToApiResource(ers []EnrollmentRequest, cont *string, numRemaining *int64) (api.EnrollmentRequestList, error)

func FleetAPIVersion added in v0.5.0

func FleetAPIVersion() string

func FleetsToApiResource added in v0.4.0

func FleetsToApiResource(fleets []Fleet, cont *string, numRemaining *int64) (api.FleetList, error)

func RepositoriesToApiResource added in v0.4.0

func RepositoriesToApiResource(repos []Repository, cont *string, numRemaining *int64) (api.RepositoryList, error)

func RepositoryAPIVersion added in v0.5.0

func RepositoryAPIVersion() string

func ResourceSyncAPIVersion added in v0.5.0

func ResourceSyncAPIVersion() string

func ResourceSyncsToApiResource added in v0.4.0

func ResourceSyncsToApiResource(rss []ResourceSync, cont *string, numRemaining *int64) (api.ResourceSyncList, error)

func TemplateVersionAPIVersion added in v0.5.0

func TemplateVersionAPIVersion() string

func TemplateVersionsToApiResource added in v0.4.0

func TemplateVersionsToApiResource(tvs []TemplateVersion, cont *string, numRemaining *int64) (api.TemplateVersionList, error)

Types

type APIResourceOption

type APIResourceOption func(*apiResourceOptions)

func WithDevicesSummary added in v0.4.0

func WithDevicesSummary(devicesSummary *api.DevicesSummary) APIResourceOption

func WithRendered added in v0.5.0

func WithRendered(knownRenderedVersion *string) APIResourceOption

type CertificateSigningRequest

type CertificateSigningRequest struct {
	Resource

	// The desired state of the certificate signing request, stored as opaque JSON object.
	Spec *JSONField[api.CertificateSigningRequestSpec] `gorm:"type:jsonb"`

	// The last reported state of the certificate signing request, stored as opaque JSON object.
	Status *JSONField[api.CertificateSigningRequestStatus] `gorm:"type:jsonb"`
}

func CertificateSigningRequestPtrToCertificateSigningRequest added in v0.4.0

func CertificateSigningRequestPtrToCertificateSigningRequest(p *CertificateSigningRequest) *CertificateSigningRequest

func NewCertificateSigningRequestFromApiResource

func NewCertificateSigningRequestFromApiResource(resource *api.CertificateSigningRequest) (*CertificateSigningRequest, error)

func (*CertificateSigningRequest) GetKind added in v0.4.0

func (csr *CertificateSigningRequest) GetKind() string

func (*CertificateSigningRequest) GetSpec added in v0.4.0

func (csr *CertificateSigningRequest) GetSpec() any

func (*CertificateSigningRequest) GetStatusAsJson added in v0.4.0

func (csr *CertificateSigningRequest) GetStatusAsJson() ([]byte, error)

func (*CertificateSigningRequest) HasNilSpec added in v0.4.0

func (csr *CertificateSigningRequest) HasNilSpec() bool

func (*CertificateSigningRequest) HasSameSpecAs added in v0.4.0

func (csr *CertificateSigningRequest) HasSameSpecAs(otherResource any) bool

func (*CertificateSigningRequest) ListSelectors added in v0.4.0

func (*CertificateSigningRequest) ResolveSelector added in v0.4.0

func (CertificateSigningRequest) String

func (csr CertificateSigningRequest) String() string

func (*CertificateSigningRequest) ToApiResource

type Device

type Device struct {
	Resource

	// The alias for the device.
	Alias *string `selector:"metadata.alias"`

	// The desired state, stored as opaque JSON object.
	Spec *JSONField[api.DeviceSpec] `gorm:"type:jsonb"`

	// The last reported state, stored as opaque JSON object.
	Status *JSONField[api.DeviceStatus] `gorm:"type:jsonb"`

	// Conditions set by the service, as opposed to the agent.
	ServiceConditions *JSONField[ServiceConditions]

	// The rendered device config
	RenderedConfig *JSONField[*[]api.ConfigProviderSpec] `gorm:"type:jsonb"`

	// Timestamp when the device was rendered
	RenderTimestamp time.Time

	// The rendered application provided by the service.
	RenderedApplications *JSONField[*[]api.ApplicationProviderSpec] `gorm:"type:jsonb"`

	// Join table with the relationship of devices to repositories (only maintained for standalone devices)
	Repositories []Repository `gorm:"many2many:device_repos;constraint:OnDelete:CASCADE;"`
}

func NewDeviceFromApiResource

func NewDeviceFromApiResource(resource *api.Device) (*Device, error)

func (*Device) GetKind added in v0.4.0

func (d *Device) GetKind() string

func (*Device) GetStatusAsJson added in v0.4.0

func (d *Device) GetStatusAsJson() ([]byte, error)

func (*Device) HasNilSpec added in v0.4.0

func (d *Device) HasNilSpec() bool

func (*Device) HasSameSpecAs added in v0.4.0

func (d *Device) HasSameSpecAs(otherResource any) bool

func (*Device) ListSelectors added in v0.4.0

func (m *Device) ListSelectors() selector.SelectorNameSet

func (*Device) MapSelectorName added in v0.4.0

func (m *Device) MapSelectorName(name selector.SelectorName) []selector.SelectorName

func (*Device) ResolveSelector added in v0.4.0

func (m *Device) ResolveSelector(name selector.SelectorName) (*selector.SelectorField, error)

func (Device) String

func (d Device) String() string

func (*Device) ToApiResource

func (d *Device) ToApiResource(opts ...APIResourceOption) (*api.Device, error)

type DeviceLabel added in v0.5.0

type DeviceLabel struct {
	OrgID      uuid.UUID `gorm:"primaryKey;type:uuid;index:,composite:device_label_org_device" selector:"metadata.orgid,hidden,private"`
	DeviceName string    `gorm:"primaryKey;index:,composite:device_label_org_device" selector:"metadata.name"`
	LabelKey   string    `gorm:"primaryKey;index:,composite:device_label_key" selector:"metadata.label.key"`
	LabelValue string    `gorm:"index" selector:"metadata.label.value"`

	// Foreign Key Constraint with CASCADE DELETE
	Device Device `gorm:"foreignKey:OrgID,DeviceName;references:OrgID,Name;constraint:OnDelete:CASCADE"`
}

func (*DeviceLabel) ListSelectors added in v0.5.0

func (m *DeviceLabel) ListSelectors() selector.SelectorNameSet

func (*DeviceLabel) MapSelectorName added in v0.5.0

func (m *DeviceLabel) MapSelectorName(name selector.SelectorName) []selector.SelectorName

type EnrollmentRequest

type EnrollmentRequest struct {
	Resource

	// The desired state of the enrollment request, stored as opaque JSON object.
	Spec *JSONField[api.EnrollmentRequestSpec] `gorm:"type:jsonb"`

	// The last reported state of the enrollment request, stored as opaque JSON object.
	Status *JSONField[api.EnrollmentRequestStatus] `gorm:"type:jsonb"`
}

func NewEnrollmentRequestFromApiResource

func NewEnrollmentRequestFromApiResource(resource *api.EnrollmentRequest) (*EnrollmentRequest, error)

func (*EnrollmentRequest) GetKind added in v0.4.0

func (e *EnrollmentRequest) GetKind() string

func (*EnrollmentRequest) GetStatusAsJson added in v0.4.0

func (e *EnrollmentRequest) GetStatusAsJson() ([]byte, error)

func (*EnrollmentRequest) HasNilSpec added in v0.4.0

func (e *EnrollmentRequest) HasNilSpec() bool

func (*EnrollmentRequest) HasSameSpecAs added in v0.4.0

func (e *EnrollmentRequest) HasSameSpecAs(otherResource any) bool

func (*EnrollmentRequest) ListSelectors added in v0.4.0

func (m *EnrollmentRequest) ListSelectors() selector.SelectorNameSet

func (*EnrollmentRequest) ResolveSelector added in v0.4.0

func (m *EnrollmentRequest) ResolveSelector(name selector.SelectorName) (*selector.SelectorField, error)

func (EnrollmentRequest) String

func (e EnrollmentRequest) String() string

func (*EnrollmentRequest) ToApiResource

func (e *EnrollmentRequest) ToApiResource(opts ...APIResourceOption) (*api.EnrollmentRequest, error)

type Fleet

type Fleet struct {
	Resource

	// The desired state, stored as opaque JSON object.
	Spec *JSONField[api.FleetSpec] `gorm:"type:jsonb"`

	// The last reported state, stored as opaque JSON object.
	Status *JSONField[api.FleetStatus] `gorm:"type:jsonb"`

	// Join table with the relationship of fleets to repositories
	Repositories []Repository `gorm:"many2many:fleet_repos;constraint:OnDelete:CASCADE;"`
}

func FleetPtrToFleet added in v0.4.0

func FleetPtrToFleet(f *Fleet) *Fleet

func NewFleetFromApiResource

func NewFleetFromApiResource(resource *api.Fleet) (*Fleet, error)

func (*Fleet) GetKind added in v0.4.0

func (f *Fleet) GetKind() string

func (*Fleet) GetStatusAsJson added in v0.4.0

func (f *Fleet) GetStatusAsJson() ([]byte, error)

func (*Fleet) HasNilSpec added in v0.4.0

func (f *Fleet) HasNilSpec() bool

func (*Fleet) HasSameSpecAs added in v0.4.0

func (f *Fleet) HasSameSpecAs(otherResource any) bool

func (*Fleet) ListSelectors added in v0.4.0

func (m *Fleet) ListSelectors() selector.SelectorNameSet

func (*Fleet) ResolveSelector added in v0.4.0

func (m *Fleet) ResolveSelector(name selector.SelectorName) (*selector.SelectorField, error)

func (Fleet) String

func (d Fleet) String() string

func (*Fleet) ToApiResource

func (f *Fleet) ToApiResource(opts ...APIResourceOption) (*api.Fleet, error)

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 JSONMap added in v0.4.0

type JSONMap[K comparable, V any] map[K]V

JSONMap represents a generic map that can be stored as JSONB in PostgreSQL.

func MakeJSONMap added in v0.4.0

func MakeJSONMap[K comparable, V any](src map[K]V) JSONMap[K, V]

MakeJSONMap initializes a JSONMap from a standard map.

func (*JSONMap[K, V]) Scan added in v0.4.0

func (m *JSONMap[K, V]) Scan(src interface{}) error

Scan implements the sql.Scanner interface for reading from PostgreSQL.

func (JSONMap[K, V]) Value added in v0.4.0

func (m JSONMap[K, V]) Value() (driver.Value, error)

Value implements the driver.Valuer interface for writing to PostgreSQL.

type Repository

type Repository struct {
	Resource

	// The desired state, stored as opaque JSON object.
	Spec *JSONField[api.RepositorySpec] `gorm:"type:jsonb"`

	// The last reported state, stored as opaque JSON object.
	Status *JSONField[api.RepositoryStatus] `gorm:"type:jsonb"`

	// Join table with the relationship of repository to fleets
	Fleets []Fleet `gorm:"many2many:fleet_repos;constraint:OnDelete:CASCADE;"`

	// Join table with the relationship of repository to devices (only maintained for standalone devices)
	Devices []Device `gorm:"many2many:device_repos;constraint:OnDelete:CASCADE;"`
}

func NewRepositoryFromApiResource

func NewRepositoryFromApiResource(resource *api.Repository) (*Repository, error)

func (*Repository) GetKind added in v0.4.0

func (r *Repository) GetKind() string

func (*Repository) GetStatusAsJson added in v0.4.0

func (r *Repository) GetStatusAsJson() ([]byte, error)

func (*Repository) HasNilSpec added in v0.4.0

func (r *Repository) HasNilSpec() bool

func (*Repository) HasSameSpecAs added in v0.4.0

func (r *Repository) HasSameSpecAs(otherResource any) bool

func (*Repository) ListSelectors added in v0.4.0

func (m *Repository) ListSelectors() selector.SelectorNameSet

func (*Repository) ResolveSelector added in v0.4.0

func (m *Repository) ResolveSelector(name selector.SelectorName) (*selector.SelectorField, error)

func (Repository) String

func (r Repository) String() string

func (*Repository) ToApiResource

func (r *Repository) ToApiResource(opts ...APIResourceOption) (*api.Repository, error)

type Resource

type Resource struct {

	// Uniquely identifies the tenant the resource belongs to.
	// Assigned by IAM. Immutable.
	OrgID uuid.UUID `gorm:"type:uuid;primaryKey;index:,composite:org_name,priority:1"`

	// Uniquely identifies the resource within a tenant and schema.
	// Depending on the schema (kind), assigned by the device management system or the crypto identity of the device (public key). Immutable.
	// This may become a URN later, so it's important API users treat this as an opaque handle.
	Name string `gorm:"primaryKey;index:,composite:org_name,priority:2" selector:"metadata.name"`

	// The "kind/name" of the resource owner of this resource.
	Owner *string `gorm:"index:owner_idx" selector:"metadata.owner"`

	// Labels associated with the resource, used for selecting and querying objects.
	// Labels are stored as a JSONB object, supporting flexible indexing and querying capabilities.
	Labels JSONMap[string, string] `gorm:"type:jsonb" selector:"metadata.labels,hidden,private"`

	// Annotations associated with the resource, used for storing additional metadata.
	// Similar to labels, annotations are stored as a JSONB object to support flexible indexing and querying.
	Annotations JSONMap[string, string] `gorm:"type:jsonb" selector:"metadata.annotations,hidden,private"`

	Generation      *int64
	ResourceVersion *int64
	CreatedAt       time.Time `selector:"metadata.creationTimestamp"`
	UpdatedAt       time.Time
	DeletedAt       gorm.DeletedAt `gorm:"index"`
}

func (*Resource) BeforeCreate

func (r *Resource) BeforeCreate(tx *gorm.DB) error

func (*Resource) GetAnnotations added in v0.4.0

func (r *Resource) GetAnnotations() JSONMap[string, string]

func (*Resource) GetGeneration added in v0.4.0

func (r *Resource) GetGeneration() *int64

func (*Resource) GetLabels added in v0.4.0

func (r *Resource) GetLabels() JSONMap[string, string]

func (*Resource) GetName added in v0.4.0

func (r *Resource) GetName() string

func (*Resource) GetNonNilFieldsFromResource added in v0.4.0

func (r *Resource) GetNonNilFieldsFromResource() []string

func (*Resource) GetOrgID added in v0.4.0

func (r *Resource) GetOrgID() uuid.UUID

func (*Resource) GetOwner added in v0.4.0

func (r *Resource) GetOwner() *string

func (*Resource) GetResourceVersion added in v0.4.0

func (r *Resource) GetResourceVersion() *int64

func (*Resource) SetAnnotations added in v0.4.0

func (r *Resource) SetAnnotations(annotations JSONMap[string, string])

func (*Resource) SetGeneration added in v0.4.0

func (r *Resource) SetGeneration(generation *int64)

func (*Resource) SetLabels added in v0.4.0

func (r *Resource) SetLabels(labels JSONMap[string, string])

func (*Resource) SetOrgID added in v0.4.0

func (r *Resource) SetOrgID(orgId uuid.UUID)

func (*Resource) SetOwner added in v0.4.0

func (r *Resource) SetOwner(owner *string)

func (*Resource) SetResourceVersion added in v0.4.0

func (r *Resource) SetResourceVersion(version *int64)

type ResourceInterface added in v0.4.0

type ResourceInterface interface {
	GetKind() string
	GetName() string
	GetOrgID() uuid.UUID
	SetOrgID(uuid.UUID)
	GetResourceVersion() *int64
	SetResourceVersion(*int64)
	GetGeneration() *int64
	SetGeneration(*int64)
	GetOwner() *string
	SetOwner(*string)
	GetLabels() JSONMap[string, string]
	SetLabels(JSONMap[string, string])
	GetAnnotations() JSONMap[string, string]
	SetAnnotations(JSONMap[string, string])
	GetNonNilFieldsFromResource() []string
	HasNilSpec() bool
	HasSameSpecAs(any) bool
	GetStatusAsJson() ([]byte, error)
}

type ResourceSync

type ResourceSync struct {
	Resource

	// The desired state, stored as opaque JSON object.
	Spec *JSONField[api.ResourceSyncSpec] `gorm:"type:jsonb"`

	// The last reported state, stored as opaque JSON object.
	Status *JSONField[api.ResourceSyncStatus] `gorm:"type:jsonb"`
}

func NewResourceSyncFromApiResource

func NewResourceSyncFromApiResource(resource *api.ResourceSync) (*ResourceSync, error)

func (*ResourceSync) AddPathAccessCondition

func (rs *ResourceSync) AddPathAccessCondition(err error)

func (*ResourceSync) AddRepoAccessCondition

func (rs *ResourceSync) AddRepoAccessCondition(err error)

func (*ResourceSync) AddRepoNotFoundCondition

func (rs *ResourceSync) AddRepoNotFoundCondition(err error)

func (*ResourceSync) AddResourceParsedCondition

func (rs *ResourceSync) AddResourceParsedCondition(err error)

func (*ResourceSync) AddSyncedCondition

func (rs *ResourceSync) AddSyncedCondition(err error)

func (*ResourceSync) GetKind added in v0.4.0

func (rs *ResourceSync) GetKind() string

func (*ResourceSync) GetStatusAsJson added in v0.4.0

func (rs *ResourceSync) GetStatusAsJson() ([]byte, error)

func (*ResourceSync) HasNilSpec added in v0.4.0

func (rs *ResourceSync) HasNilSpec() bool

func (*ResourceSync) HasSameSpecAs added in v0.4.0

func (rs *ResourceSync) HasSameSpecAs(otherResource any) bool

func (*ResourceSync) ListSelectors added in v0.4.0

func (m *ResourceSync) ListSelectors() selector.SelectorNameSet

func (*ResourceSync) NeedsSyncToHash

func (rs *ResourceSync) NeedsSyncToHash(hash string) bool

NeedsSyncToHash returns true if the resource needs to be synced to the given hash.

func (*ResourceSync) ResolveSelector added in v0.4.0

func (m *ResourceSync) ResolveSelector(name selector.SelectorName) (*selector.SelectorField, error)

func (*ResourceSync) SetCondition

func (rs *ResourceSync) SetCondition(conditionType api.ConditionType, okReason, failReason string, err error) bool

func (*ResourceSync) String

func (rs *ResourceSync) String() string

func (*ResourceSync) ToApiResource

func (rs *ResourceSync) ToApiResource(opts ...APIResourceOption) (*api.ResourceSync, error)

type ServiceConditions

type ServiceConditions struct {
	Conditions *[]api.Condition `json:"conditions,omitempty"`
}

type TemplateVersion

type TemplateVersion struct {
	OrgID           uuid.UUID               `gorm:"type:uuid;primary_key;"`
	Name            string                  `gorm:"primary_key;" selector:"metadata.name"`
	FleetName       string                  `gorm:"primary_key;" selector:"metadata.owner"`
	Fleet           Fleet                   `gorm:"foreignkey:OrgID,FleetName;constraint:OnDelete:CASCADE;"`
	Labels          JSONMap[string, string] `gorm:"type:jsonb" selector:"metadata.labels,hidden,private"`
	Annotations     JSONMap[string, string] `gorm:"type:jsonb" selector:"metadata.annotations,hidden,private"`
	Generation      *int64
	ResourceVersion *int64
	CreatedAt       time.Time `selector:"metadata.creationTimestamp"`
	UpdatedAt       time.Time
	DeletedAt       gorm.DeletedAt `gorm:"index"`

	// The desired state, stored as opaque JSON object.
	Spec *JSONField[api.TemplateVersionSpec] `gorm:"type:jsonb"`

	// The last reported state, stored as opaque JSON object.
	Status *JSONField[api.TemplateVersionStatus] `gorm:"type:jsonb"`
}

func NewTemplateVersionFromApiResource

func NewTemplateVersionFromApiResource(resource *api.TemplateVersion) (*TemplateVersion, error)

func (*TemplateVersion) GetAnnotations added in v0.4.0

func (tv *TemplateVersion) GetAnnotations() JSONMap[string, string]

func (*TemplateVersion) GetGeneration added in v0.4.0

func (tv *TemplateVersion) GetGeneration() *int64

func (*TemplateVersion) GetKind added in v0.4.0

func (tv *TemplateVersion) GetKind() string

func (*TemplateVersion) GetLabels added in v0.4.0

func (tv *TemplateVersion) GetLabels() JSONMap[string, string]

func (*TemplateVersion) GetName added in v0.4.0

func (tv *TemplateVersion) GetName() string

func (*TemplateVersion) GetNonNilFieldsFromResource added in v0.4.0

func (tv *TemplateVersion) GetNonNilFieldsFromResource() []string

func (*TemplateVersion) GetOrgID added in v0.4.0

func (tv *TemplateVersion) GetOrgID() uuid.UUID

func (*TemplateVersion) GetOwner added in v0.4.0

func (tv *TemplateVersion) GetOwner() *string

func (*TemplateVersion) GetResourceVersion added in v0.4.0

func (tv *TemplateVersion) GetResourceVersion() *int64

func (*TemplateVersion) GetStatusAsJson added in v0.4.0

func (tv *TemplateVersion) GetStatusAsJson() ([]byte, error)

func (*TemplateVersion) HasNilSpec added in v0.4.0

func (tv *TemplateVersion) HasNilSpec() bool

func (*TemplateVersion) HasSameSpecAs added in v0.4.0

func (tv *TemplateVersion) HasSameSpecAs(otherResource any) bool

func (*TemplateVersion) SetAnnotations added in v0.4.0

func (tv *TemplateVersion) SetAnnotations(annotations JSONMap[string, string])

func (*TemplateVersion) SetGeneration added in v0.4.0

func (tv *TemplateVersion) SetGeneration(generation *int64)

func (*TemplateVersion) SetLabels added in v0.4.0

func (tv *TemplateVersion) SetLabels(labels JSONMap[string, string])

func (*TemplateVersion) SetOrgID added in v0.4.0

func (tv *TemplateVersion) SetOrgID(orgId uuid.UUID)

func (*TemplateVersion) SetOwner added in v0.4.0

func (tv *TemplateVersion) SetOwner(owner *string)

func (*TemplateVersion) SetResourceVersion added in v0.4.0

func (tv *TemplateVersion) SetResourceVersion(version *int64)

func (TemplateVersion) String

func (tv TemplateVersion) String() string

func (*TemplateVersion) ToApiResource

func (tv *TemplateVersion) ToApiResource(opts ...APIResourceOption) (*api.TemplateVersion, error)

Jump to

Keyboard shortcuts

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