models

package
v0.1.20 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2024 License: Apache-2.0 Imports: 7 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"`
	// Description is the description of the account.
	Description *string `json:"description"`
	// Key is the issuer key identifier.
	Key NKey `json:"key" gorm:"foreignKey:ID;polymorphic:Owner;polymorphicValue:account"`
	// Token is the JWT token used to authenticate the account.
	Token Token `json:"token" gorm:"foreignKey:ID;polymorphic:Owner;polymorphicValue:account"`
	// Operator is the operator this account is associated with.
	Operator Operator `json:"operator" gorm:"foreignKey:OperatorID"`
	// OperatorID is the operator ID.
	OperatorID uuid.UUID `json:"operator_id" gorm:"foreignKey:ID"`
	// SigningKeyGroups is the list of signing key groups the account has.
	SigningKeyGroups []SigningKeyGroup `` /* 141-byte string literal not displayed */
	// Users is the list of users the account has.
	Users []User `json:"users" gorm:"constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	// 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 ...

func (*Account) AfterDelete added in v0.1.17

func (a *Account) AfterDelete(tx *gorm.DB) error

AfterDelete ...

func (*Account) FindSigningKeyGroupByID added in v0.1.17

func (a *Account) FindSigningKeyGroupByID(id uuid.UUID) *SigningKeyGroup

FindSigningKeyGroupByID ...

type AccountPagination added in v0.1.15

type AccountPagination Pagination[Operator]

AccountPagination is the pagination for operators.

type Cluster

type Cluster struct {
	// ID is the unique identifier for the cluster.
	ID uuid.UUID `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 ...

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"`
	// OwnerID is the owner of the token.
	OwnerID uuid.UUID `json:"owner_id"`
	// OwnerType is the type of the owner.
	OwnerType OwnerType `json:"owner_type"`
	// 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.

func (*NKey) KeyPair added in v0.1.15

func (n *NKey) KeyPair() (nkeys.KeyPair, error)

KeyPair is a pair of NKeys.

func (*NKey) PrivateKey added in v0.1.15

func (n *NKey) PrivateKey() ([]byte, error)

PrivateKey returns the private key portion of the NKey.

func (*NKey) PublicKey added in v0.1.15

func (n *NKey) PublicKey() (string, error)

PublicKey returns the public key portion of the NKey.

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" gorm:"foreignKey:ID;polymorphic:Owner;polymorphicValue:operator"`
	// Token is the JWT token used to authenticate the account.
	Token Token `json:"token" gorm:"foreignKey:ID;polymorphic:Owner;polymorphicValue:operator"`
	// SystemAdminAccount is the account that is used to manage the systems.
	SystemAdminAccount   *Account   `json:"system_admin_account"`
	SystemAdminAccountID *uuid.UUID `json:"system_admin_account_id"`
	// Systems is the systems that are associated with the operator.
	Systems []System `json:"systems" gorm:"foreignKey:OperatorID"`
	// SigningKeyGroups is the list of signing key groups the account has.
	SigningKeyGroups []SigningKeyGroup `` /* 143-byte string literal not displayed */
	// Accounts is the list of accounts the operator has.
	Accounts []Account `json:"accounts"`
	// 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.

func NewOperator added in v0.1.17

func NewOperator(name, description string) (Operator, error)

NewOperator is creating a new operator.

func (Operator) Claims added in v0.1.15

func (o Operator) Claims() (*jwt.OperatorClaims, error)

Claims returns the operator claims.

func (Operator) Compare added in v0.1.17

func (o Operator) Compare() int

Compare ...

type OperatorPagination added in v0.1.15

type OperatorPagination Pagination[Operator]

OperatorPagination is the pagination for operators.

type OwnerType added in v0.1.17

type OwnerType string

OwnerType is the struct that is used to define the owner of the token.

const (
	// Operator is the owner of the token.
	OperatorToken OwnerType = "operator"
	// Account is the owner of the token.
	AccountToken OwnerType = "account"
	// User is the owner of the token.
	UserToken OwnerType = "user"
)

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 SigningKeyGroup added in v0.1.15

type SigningKeyGroup struct {
	// ID is the unique identifier for the group.
	ID uuid.UUID `json:"id" gorm:"type:uuid;primary_key;default:gen_random_uuid()"`
	// Name is the name of the group.
	Name string `json:"name" validate:"required,min=3,max=128"`
	// Description is the description of the group.
	Description string `json:"description" validate:"max=1024"`
	// Key is the signing key of this group.
	Key NKey `json:"key"`
	// KeyID is the foreign key for the key.
	KeyID string `json:"key_id" gorm:"foreignKey:ID"`
	// CreatedAt is the time the group was created.
	CreatedAt time.Time `json:"created_at"`
	// UpdatedAt is the time the group was updated.
	UpdatedAt time.Time `json:"updated_at"`
	// DeletedAt is the time the group was deleted.
	DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

SigningKeyGroup is a model for storing the signing key group.

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"`
	// Tags is the tags that are associated with the system.
	Tags []*Tag `json:"tags" gorm:"polymorphic:Taggable;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 ...

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 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"`
	// OwnerID is the owner of the token.
	OwnerID uuid.UUID `json:"owner_id"`
	// OwnerType is the type of the owner.
	OwnerType OwnerType `json:"owner_type"`
	// 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 is a model for storing the the JWT token used to authenticate the user.

func (*Token) Claim added in v0.1.15

func (t *Token) Claim() (*jwt.GenericClaims, error)

Claim is returning the claim of the token.

func (*Token) DeepCopy added in v0.1.15

func (t *Token) DeepCopy() Token

DeepCopy returns a deep copy of the token.

func (*Token) PublicKey added in v0.1.15

func (t *Token) PublicKey() (string, error)

PublicKey returns the public key of the 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"`
	// Key is the issuer key identifier.
	Key NKey `json:"key" gorm:"foreignKey:ID;polymorphic:Owner;polymorphicValue:account"`
	// KeyID is the foreign key for the 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:ID;polymorphic:Owner;polymorphicValue:user"`
	// Account is the account that the user belongs to.
	Account Account `json:"account" gorm:"foreignKey:AccountID"`
	// AccountID is the foreign key for the account.
	AccountID uuid.UUID `json:"account_id"`
	// 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 ...

func (*User) Credentials added in v0.1.15

func (u *User) Credentials() ([]byte, error)

Credentials returns the user's credentials.

Jump to

Keyboard shortcuts

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