models

package
v0.1.46 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 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"`
	// 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"`
	// AccountType is the type of the account.
	AccountType string `json:"account_type"`
	// LimitJetStreamMaxDiskStorage is the limit for JetStream maximum disk storage.
	LimitJetStreamMaxDiskStorage int64 `json:"limit_jetstream_max_disk_storage"`
	// LimitJetStreamMaxStreams is the limit for JetStream maximum streams.
	LimitJetStreamMaxStreams int64 `json:"limit_jetstream_max_streams"`
	// LimitJetStreamMaxAckPending is the limit for JetStream maximum ack pending.
	LimitJetStreamMaxAckPending int64 `json:"limit_jetstream_max_ack_pending"`
	/// LimitJetStreamMaxStreamBytes is the limit for JetStream maximum stream bytes.
	LimitJetStreamMaxStreamBytes int64 `json:"limit_jetstream_max_stream_bytes"`
	// LimitJetStreamMaxBytesRequired indicates if JetStream maximum bytes required is limited.
	LimitJetStreamMaxBytesRequired bool `json:"limit_jetstream_max_bytes_required"`
	// LimitJetStreamMaxConsumers indicates if JetStream maximum consumer is limited.
	LimitJetStreamMaxConsumers int64 `json:"limit_jetstream_max_consumers"`
	// 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 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"`
	// SystemAccount is the account that is used to manage the systems.
	SystemAccount Account `json:"system_account" gorm:"Constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
	// SystemAccountID is the account that is used to manage the systems.
	SystemAccountID uuid.UUID `json:"system_account_id" gorm:"type:uuid"`
	// AccountServerURL is the URL of the account server.
	AccountServerURL string `json:"account_server_url" form:"account_server_url" xml:"account_server_url" validate:"url"`
	// Accounts is the accounts that are associated with the operator.
	Accounts []Account `json:"accounts" gorm:"many2many:operator_accounts;foreignKey:ID;joinForeignKey:OperatorID;joinReferences:AccountID"`
	// 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 */
	// 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" query:"limit"`
	// Offset is the number of items to skip.
	Offset int `json:"offset" xml:"offset" form:"offset" query:"limit"`
	// Search is the search term to filter the results.
	Search string `json:"search" xml:"search" form:"search" query:"limit"`
	// Sort is the sorting order.
	Sort string `json:"sort,omitempty" xml:"sort" form:"sort" query:"limit"`
	// 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]) GetRows added in v0.1.24

func (p *Pagination[R]) GetRows() []*R

GetRows returns the rows as pointers.

func (*Pagination[R]) GetSort

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

GetSort returns the sort.

func (*Pagination[R]) GetTotalRows added in v0.1.24

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

GetTotalRows returns the total rows.

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" gorm:"foreignKey:ID;polymorphic:Owner;polymorphicValue:signing_key_group"`
	// 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()" xml:"id" params:"id"`
	// Name is the name of the system.
	Name string `json:"name" gorm:"unique" xml:"name" form:"name" validate:"required,min=3,max=128"`
	// Description is the description of the system.
	Description string `json:"description" form:"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" validate:"-"`
	OperatorID uuid.UUID `json:"operator_id" form:"operator_id" validate:"required,uuid"`
	// Tags is the tags that are associated with the system.
	Tags []*Tag `json:"tags" gorm:"polymorphic:Taggable;polymorphicValue:system;" validate:"-"`
	// 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) Bytes added in v0.1.24

func (t *Token) Bytes() []byte

Bytes returns the token as a byte slice.

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:user"`
	// 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"`
	// UserLimits is the user limits.
	UserLimits UserLimits `json:"limits"`
	// 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.

type UserLimits added in v0.1.24

type UserLimits struct {
	// UserID is the user identifier.
	UserID uuid.UUID `json:"user_id"`
	// MaxSubscriptions is the maximum number of subscriptions the user can have.
	MaxSubscriptions int `json:"max_subscriptions"`
	// MaxJWTLiftime is the maximum payload size the user can have.
	MaxJWTLiftime time.Duration `json:"jwt_lifetime"`
	// MaxPayloadSize is the maximum payload size the user can have.
	MaxPayloadSize int `json:"max_payload_size"`
	// MaxDataRate is the maximum data rate the user can have.
	MaxDataRate int `json:"max_data_rate"`
}

UserLimits ...

Jump to

Keyboard shortcuts

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