models

package
v0.1.14 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Paginate

func Paginate[R any](value interface{}, pagination *Pagination[R], db *gorm.DB) func(db *gorm.DB) *gorm.DB

Paginate returns a function that paginates the results.

Types

type Account

type Account struct {
	// ID is the unique identifier for the account.
	ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;default:gen_random_uuid()"`
	// Name is the name of the account.
	Name string `json:"name"`

	// Operator is the operator that created the account.
	Operator   Operator  `json:"operator"`
	OperatorID uuid.UUID `json:"operator_id" gorm:"foreignKey:ID"`

	// Key is the issuer key identifier.
	Key   NKey   `json:"key"`
	KeyID string `json:"key_id" gorm:"foreignKey:ID"`

	// Token is the JWT token used to authenticate the account.
	Token   Token  `json:"token" gorm:"foreignKey:TokenID"`
	TokenID string `json:"token_id"`

	// SigningKeys is the list of signing keys the account has.
	SigningKeys []NKey `json:"signing_keys" gorm:"many2many:account_signing_keys;foreignKey:ID;joinForeignKey:AccountID;joinReferences:SigningKeyID"`

	// Users is the list of users that the account has.
	Users []User `json:"users" gorm:"foreignKey:AccountID"`

	// OwnedBy is the owner of the account. This is usually a team.
	OwnedBy Ownership `json:"owner" gorm:"polymorphic:Ownable;polymorphicValue:account;"`

	// CreatedAt is the time the account was created.
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the time the account was updated.
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt is the time the account was deleted.
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

Account ...

type Allow

type Allow struct {
	// ID is the unique identifier for the ownership.
	ID int `json:"id" gorm:"primary_key"`
	// AllowableID is the unique identifier for the resource allowed to.
	AllowableID uuid.UUID `json:"owner_id"`
	// AllowableType is the type of the resource that is allowed to.
	AllowableType string `json:"owner_type"`
	// TeamID is the .
	TeamID uuid.UUID `json:"team_id"`
	// Team is the team that is allowed to.
	Team Team `json:"team" gorm:"foreignKey:TeamID"`
	// CreatedAt is the time the ownership was created.
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the time the ownership was updated.
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt is the time the ownership was deleted.
	DeletedAt gorm.DeletedAt `json:"deleted_at"`
}

Allow ...

type AllowableType

type AllowableType string

AllowableType is a polymorphic type for allow.

const (
	// TeamAllowable is a team.
	TeamAllowable AllowableType = "team"
	// UserAllowable is a user.
	UserAllowable AllowableType = "user"
)

OwnableType are the different types of ownable resources.

type Cluster

type Cluster struct {
	// ID is the unique identifier for the cluster.
	ID string `json:"id" gorm:"primaryKey,type:uuid;default:gen_random_uuid()"`
	// Name is the name of the cluster.
	Name string `json:"name" gorm:"unique" validate:"required,min=3,max=128"`
	// Description is the description of the cluster.
	Description string `json:"description" validate:"max=1024"`
	// ServerURL is the URL of the server.
	ServerURL string `json:"url" validate:"required"`
	// SystemID is the ID of the system the cluster belongs to.
	SystemID uuid.UUID `json:"system_id"`
	// CreatedAt is the time the cluster was created.
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the time the cluster was updated.
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt is the time the cluster was deleted.
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

Cluster ...

func (*Cluster) ToAPI

func (c *Cluster) ToAPI() *openapi.Cluster

ToAPI converts the database model to the API model.

type FromAPI

type FromAPI[T any] interface {
	FromAPI(api *T)
}

FromAPI ...

type NKey

type NKey struct {
	// ID is the public key portion of the NKey.
	ID string `json:"id" gorm:"primaryKey"`
	// Seed is the private key portion of the NKey.
	Seed []byte `json:"seed"`
	// CreatedAt is the timestamp the key was created
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the timestamp the key was last updated
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt is the timestamp the key was deleted
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

NKey holds a private key and its metadata.

type Operator

type Operator struct {
	// ID is the unique identifier for the operator.
	ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;default:gen_random_uuid()"`
	// Name is the name of the operator.
	Name string `json:"name" validate:"required,min=3,max=128"`
	// Description is the description of the operator.
	Description string `json:"description" validate:"max=1024"`

	// Key is the issuer key identifier.
	Key   NKey   `json:"key"`
	KeyID string `json:"key_id" gorm:"foreignKey:ID"`

	// Token is the JWT token used to authenticate the account.
	Token   Token  `json:"token" gorm:"foreignKey:TokenID"`
	TokenID string `json:"token_id"`

	// Systems is the list of systems that the operator has.
	Systems []System `json:"systems" gorm:"many2many:operator_systems;foreignKey:ID;joinForeignKey:OperatorID;joinReferences:SystemID"`

	// Accounts is the list of accounts that the operator has.
	SigningKeys []NKey `` /* 126-byte string literal not displayed */

	// Owner is the owner of the operator.
	Owner Ownership `json:"owner" gorm:"polymorphic:Ownable;polymorphicValue:operator;"`

	// CreatedAt is the time the operator was created.
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the time the operator was updated.
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt is the time the operator was deleted.
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

Operator is the operator that is used to manage the systems.

type OwnableType

type OwnableType string

OwnableType is a polymorphic type for ownership.

const (
	// SystemOwnable is a system.
	SystemOwnable OwnableType = "system"
	// AccountOwnable is an account.
	AccountOwnable OwnableType = "account"
	// OperatorOwnable is an operator.
	OperatorOwnable OwnableType = "operator"
	// UserOwnable is a user.
	UserOwnable OwnableType = "user"
)

OwnableType are the different types of ownable resources.

type Ownership

type Ownership struct {
	// ID is the unique identifier for the ownership.
	ID int `json:"id" gorm:"primary_key"`
	// OwnableID is the unique identifier for .
	OwnableID uuid.UUID `json:"owner_id"`
	// OwnableType is the type of the owner.
	OwnableType string `json:"owner_type"`
	// TeamID is the identifier of the team.
	TeamID uuid.UUID `json:"team_id"`
	// Team is the team that this is owned by.
	Team Team `json:"team" gorm:"foreignKey:TeamID"`
	// CreatedAt is the time the ownership was created.
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the time the ownership was updated.
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt is the time the ownership was deleted.
	DeletedAt gorm.DeletedAt `json:"deleted_at"`
}

Ownership ...

type Pagination

type Pagination[R any] struct {
	// Limit is the number of items to return.
	Limit int `json:"limit" xml:"limit" form:"limit"`
	// Offset is the number of items to skip.
	Offset int `json:"offset" xml:"offset" form:"offset"`
	// Search is the search term to filter the results.
	Search string `json:"search" xml:"search" form:"search"`
	// Sort is the sorting order.
	Sort string `json:"sort,omitempty" xml:"sort" form:"sort"`
	// TotalRows is the total number of rows.
	TotalRows int `json:"total_rows"`
	// TotalPages is the total number of pages.
	TotalPages int `json:"total_pages"`
	// Rows is the items to return.
	Rows []R `json:"rows"`
}

Pagination is a struct that contains the pagination information.

func NewPagination

func NewPagination[R any]() Pagination[R]

NewPagination returns a new pagination.

func (*Pagination[R]) GetLimit

func (p *Pagination[R]) GetLimit() int

GetLimit returns the limit.

func (*Pagination[R]) GetOffset

func (p *Pagination[R]) GetOffset() int

GetOffset returns the page.

func (*Pagination[R]) GetSort

func (p *Pagination[R]) GetSort() string

GetSort returns the sort.

type System

type System struct {
	// ID is the unique identifier for the system.
	ID uuid.UUID `json:"id" gorm:"type:uuid;default:gen_random_uuid()"`
	// Name is the name of the system.
	Name string `json:"name" gorm:"unique" validate:"required,min=3,max=128"`
	// Description is the description of the system.
	Description string `json:"description" validate:"max=1024"`

	// Clusters is the clusters that are associated with the system.
	Clusters []Cluster `json:"clusters" gorm:"foreignKey:SystemID"`

	// Operator is the operator this is associated with this system to operate.
	Operator   Operator   `json:"operator" gorm:"foreignKey:OperatorID"`
	OperatorID *uuid.UUID `json:"operator_id"`

	// SystemAccount is the account that is used to control the system.
	// The system account needs to be signed by the operator.
	SystemAccount   Account    `json:"system_account" gorm:"foreignKey:SystemAccountID"`
	SystemAccountID *uuid.UUID `json:"system_account_id"`

	// Tags is the tags that are associated with the system.
	Tags []*Tag `json:"tags" gorm:"polymorphic:Taggable;polymorphicValue:system;"`

	// OwnedBy is the owner of the account. This is usually a team.
	OwnedBy Ownership `json:"owned_by" gorm:"polymorphic:Ownable;polymorphicValue:system;"`

	// AllowedBy is the allowed by of the account. This is usually a team.
	AllowedBy []Allow `json:"allowed_by" gorm:"polymorphic:Allowable;polymorphicValue:system;"`

	// CreatedAt is the time the system was created.
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the time the system was updated.
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt is the time the system was deleted.
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

System ...

func (*System) FromAPI

func (s *System) FromAPI(api *openapi.System)

FromAPI converts the API model to the database model.

type Tag

type Tag struct {
	// ID is the unique identifier for the tag.
	ID int `json:"id" gorm:"primary_key"`
	// Name is the name of the tag.
	Name string `json:"name"`
	// TaggableID is the unique identifier for the taggable.
	TaggableID uuid.UUID `json:"taggable_id"`
	// TaggableType is the type of the taggable.
	TaggableType TaggableType `json:"taggable_type"`
	// CreatedAt is the time the tag was created.
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the time the tag was updated.
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt is the time the tag was deleted.
	DeletedAt gorm.DeletedAt `json:"deleted_at"`
}

Tag is the model for adding tags to resources.

type TaggableType

type TaggableType string

TaggableType ...

const (
	SystemTaggable TaggableType = "system"
)

TaggableType ...

type Team

type Team struct {
	*authz.Team
	// The systems that the teams have access to.
	Systems []*System `gorm:"many2many:team_systems;"`
}

Team ...

type ToAPI

type ToAPI[T any] interface {
	ToAPI() *T
}

ToAPI ...

type Token

type Token struct {
	// ID is the unique identifier for the token.
	// This is the public key portion of the NKey.
	ID string `json:"token_id" gorm:"primaryKey"`
	// Token is the JWT token used to authenticate the account.
	Token string `json:"token"`

	// CreatedAt is the time the token was created.
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the time the token was updated.
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt is the time the token was deleted.
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

Token ...

type User

type User struct {
	// ID is the unique identifier for the user.
	ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;default:gen_random_uuid()"`
	// Name is the name of the user.
	Name string `json:"name" validate:"required,min=3,max=128"`
	// Description is the description of the user.
	Description string `json:"description" validate:"max=1024"`

	// Account is the account that created the user.
	Account   Account   `json:"account"`
	AccountID uuid.UUID `json:"account_id" gorm:"foreignKey:ID"`

	// Key is the issuer key identifier.
	Key   NKey   `json:"key"`
	KeyID string `json:"key_id" gorm:"foreignKey:ID"`

	// Token is the JWT token used to authenticate the account.
	Token   Token  `json:"token" gorm:"foreignKey:TokenID"`
	TokenID string `json:"token_id"`

	// OwnedBy is the owner of the account. This is usually a team.
	OwnedBy Ownership `json:"owner" gorm:"polymorphic:Ownable;polymorphicValue:user;"`

	// CreatedAt is the time the user was created.
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the time the user was updated.
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt is the time the user was deleted.
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

User ...

Jump to

Keyboard shortcuts

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