models

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 5 Imported by: 17

Documentation

Index

Constants

View Source
const (
	MqttClientConnectedEventType    = "client_connected"
	MqttClientDisconnectedEventType = "client_disconnected"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ActiveSession

type ActiveSession struct {
	UID      UID       `json:"uid"`
	LastSeen time.Time `json:"last_seen" bson:"last_seen"`
}

type Announcement added in v0.10.10

type Announcement struct {
	UUID    string    `json:"uuid" bson:"uuid"`
	Title   string    `json:"title" bson:"title"`
	Content string    `json:"content" bson:"content"`
	Date    time.Time `json:"date" bson:"date"`
}

type AnnouncementShort added in v0.10.10

type AnnouncementShort struct {
	UUID  string    `json:"uuid" bson:"uuid"`
	Title string    `json:"title" bson:"title"`
	Date  time.Time `json:"date" bson:"date"`
}

type AuthClaims added in v0.2.0

type AuthClaims struct {
	Claims string `json:"claims"`
}

type Billing added in v0.8.0

type Billing struct {
	SubscriptionID   string         `json:"subscription_id" bson:"subscription_id,omitempty"`
	CurrentPeriodEnd time.Time      `json:"current_period_end" bson:"current_period_end,omitempty"`
	PriceID          string         `json:"price_id" bson:"price_id,omitempty"`
	CustomerID       string         `json:"customer_id" bson:"customer_id,omitempty"`
	PaymentMethodID  string         `json:"payment_method_id" bson:"payment_method_id,omitempty"`
	PaymentFailed    *PaymentFailed `json:"payment_failed" bson:"payment_failed,omitempty"`
	State            string         `json:"state" bson:"state,omitempty"`
	Active           bool           `json:"active" bson:"active,omitempty"`
	SubItem          string         `json:"sub_item_id" bson:"sub_item_id,omitempty"`
}

type ConnectedDevice

type ConnectedDevice struct {
	UID      string    `json:"uid"`
	TenantID string    `json:"tenant_id" bson:"tenant_id"`
	LastSeen time.Time `json:"last_seen" bson:"last_seen"`
	Status   string    `json:"status" bson:"status"`
}

type Device

type Device struct {
	// UID is the unique identifier for a device.
	UID              string          `json:"uid"`
	Name             string          `json:"name" bson:"name,omitempty" validate:"required,hostname_rfc1123,excludes=."`
	Identity         *DeviceIdentity `json:"identity"`
	Info             *DeviceInfo     `json:"info"`
	PublicKey        string          `json:"public_key" bson:"public_key"`
	TenantID         string          `json:"tenant_id" bson:"tenant_id"`
	LastSeen         time.Time       `json:"last_seen" bson:"last_seen"`
	Online           bool            `json:"online" bson:",omitempty"`
	Namespace        string          `json:"namespace" bson:",omitempty"`
	Status           DeviceStatus    `json:"status" bson:"status,omitempty" validate:"oneof=accepted rejected pending unused"`
	StatusUpdatedAt  time.Time       `json:"status_updated_at" bson:"status_updated_at,omitempty"`
	CreatedAt        time.Time       `json:"created_at" bson:"created_at,omitempty"`
	RemoteAddr       string          `json:"remote_addr" bson:"remote_addr"`
	Position         *DevicePosition `json:"position" bson:"position"`
	Tags             []string        `json:"tags" bson:"tags,omitempty"`
	PublicURL        bool            `json:"public_url" bson:"public_url,omitempty"`
	PublicURLAddress string          `json:"public_url_address" bson:"public_url_address,omitempty"`
	Acceptable       bool            `json:"acceptable" bson:"acceptable,omitempty"`
}

type DeviceAuth

type DeviceAuth struct {
	Hostname  string          `json:"hostname,omitempty" bson:"hostname,omitempty" validate:"required_without=Identity,omitempty,hostname_rfc1123" hash:"-"`
	Identity  *DeviceIdentity `json:"identity,omitempty" bson:"identity,omitempty" validate:"required_without=Hostname,omitempty"`
	PublicKey string          `json:"public_key"`
	TenantID  string          `json:"tenant_id"`
}

type DeviceAuthClaims

type DeviceAuthClaims struct {
	UID string `json:"uid"`

	AuthClaims           `mapstruct:",squash"`
	jwt.RegisteredClaims `mapstruct:",squash"`
}

type DeviceAuthRequest

type DeviceAuthRequest struct {
	Info     *DeviceInfo `json:"info"`
	Sessions []string    `json:"sessions,omitempty"`
	*DeviceAuth
}

type DeviceAuthResponse

type DeviceAuthResponse struct {
	UID       string `json:"uid"`
	Token     string `json:"token"`
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
}

type DeviceIdentity added in v0.2.1

type DeviceIdentity struct {
	MAC string `json:"mac"`
}

type DeviceInfo added in v0.2.1

type DeviceInfo struct {
	ID         string `json:"id"`
	PrettyName string `json:"pretty_name"`
	Version    string `json:"version"`
	Arch       string `json:"arch"`
	Platform   string `json:"platform"`
}

type DevicePosition added in v0.8.0

type DevicePosition struct {
	Latitude  float64 `json:"latitude" bson:"latitude"`
	Longitude float64 `json:"longitude" bson:"longitude"`
}

type DeviceRemoved added in v0.11.8

type DeviceRemoved struct {
	Device    *Device   `json:"device" bson:"device"`
	Timestamp time.Time `json:"timestamp" bson:"timestamp"`
}

type DeviceStatus added in v0.11.8

type DeviceStatus string
const (
	DeviceStatusAccepted DeviceStatus = "accepted"
	DeviceStatusPending  DeviceStatus = "pending"
	DeviceStatusRejected DeviceStatus = "rejected"
	DeviceStatusRemoved  DeviceStatus = "removed"
	DeviceStatusUnused   DeviceStatus = "unused"
)

type Endpoints

type Endpoints struct {
	API string `json:"api"`
	SSH string `json:"ssh"`
}

type Filter added in v0.3.0

type Filter struct {
	// Type os the filter. Type can be "property" or "operator". When Type is "property", the Params field must is set
	// to PropertyParams structure and when set "operator", the Params field must be set to OperatorParams structure.
	Type string `json:"type,omitempty"`
	// Params is the filter params. Params can be either PropertyParams or OperatorParams.
	Params interface{} `json:"params,omitempty"`
}

Filter is a helper struct to filter results from the database. TODO: Gives a better explanation about the filter and how to use it.

func (*Filter) UnmarshalJSON added in v0.3.2

func (f *Filter) UnmarshalJSON(data []byte) error

type FirewallFilter added in v0.9.1

type FirewallFilter struct {
	Hostname string   `json:"hostname,omitempty" bson:"hostname,omitempty" validate:"required_without=Tags,excluded_with=Tags,regexp"`
	Tags     []string `` /* 164-byte string literal not displayed */
}

FirewallFilter contains the filter rule of a Public Key.

A FirewallFilter can contain either Hostname, string, or Tags, slice of strings never both.

type FirewallRule added in v0.3.3

type FirewallRule struct {
	ID                 string `json:"id,omitempty" bson:"_id,omitempty"`
	TenantID           string `json:"tenant_id" bson:"tenant_id"`
	FirewallRuleFields `bson:",inline"`
}

type FirewallRuleFields added in v0.3.3

type FirewallRuleFields struct {
	Priority int            `json:"priority"`
	Action   string         `json:"action" validate:"required,oneof=allow deny"`
	Active   bool           `json:"active"`
	SourceIP string         `json:"source_ip" bson:"source_ip" validate:"required,regexp"`
	Username string         `json:"username" validate:"required,regexp"`
	Filter   FirewallFilter `json:"filter" bson:"filter" validate:"required"`
}

func (*FirewallRuleFields) Validate added in v0.3.3

func (f *FirewallRuleFields) Validate() error

type FirewallRuleUpdate added in v0.3.3

type FirewallRuleUpdate struct {
	FirewallRuleFields `bson:",inline"`
}

type ID added in v0.5.0

type ID struct {
	ID string
}

type Info added in v0.2.1

type Info struct {
	Version   string    `json:"version"`
	Endpoints Endpoints `json:"endpoints"`
}

type License added in v0.5.0

type License struct {
	RawData   []byte
	CreatedAt time.Time `json:"created_at" bson:"created_at"`
}

type Member added in v0.5.0

type Member struct {
	ID       string `json:"id,omitempty" bson:"id,omitempty"`
	Username string `json:"username,omitempty" bson:"username,omitempty" validate:"min=3,max=30,alphanum,ascii"`
	Role     string `json:"role" bson:"role" validate:"required,oneof=administrator operator observer"`
}

type MqttACLQuery

type MqttACLQuery struct {
	Access   string `query:"access"`
	Username string `query:"username"`
	Topic    string `query:"topic"`
	IPAddr   string `query:"ipaddr"`
}

type MqttAuthQuery

type MqttAuthQuery struct {
	Username string `query:"username"`
	Password string `query:"password"`
	IPAddr   string `query:"ipaddr"`
}

type MqttClientEvent

type MqttClientEvent struct {
	ClientID string `json:"client_id"`
	Username string `json:"username"`
}

type MqttEvent

type MqttEvent struct {
	Action string `json:"action"`

	MqttClientEvent
}

type Namespace added in v0.5.0

type Namespace struct {
	Name         string             `json:"name"  validate:"required,hostname_rfc1123,excludes=.,lowercase"`
	Owner        string             `json:"owner"`
	TenantID     string             `json:"tenant_id" bson:"tenant_id,omitempty"`
	Members      []Member           `json:"members" bson:"members"`
	Settings     *NamespaceSettings `json:"settings"`
	Devices      int                `json:"-" bson:"devices,omitempty"`
	Sessions     int                `json:"-" bson:"sessions,omitempty"`
	MaxDevices   int                `json:"max_devices" bson:"max_devices"`
	DevicesCount int                `json:"devices_count" bson:"devices_count,omitempty"`
	CreatedAt    time.Time          `json:"created_at" bson:"created_at"`
	Billing      *Billing           `json:"billing" bson:"billing,omitempty"`
}

func (*Namespace) HasMaxDevices added in v0.11.8

func (n *Namespace) HasMaxDevices() bool

HasMaxDevices checks if the namespace has a maximum number of devices.

Generally, a namespace has a MaxDevices value greater than 0 when the ShellHub is either in community version or the namespace does not have a billing plan enabled, because, in this case, we set this value to -1.

func (*Namespace) HasMaxDevicesReached added in v0.11.8

func (n *Namespace) HasMaxDevicesReached(removedDevices int64) bool

HasMaxDevicesReached checks if the namespace has reached the maximum number of devices.

This function sum the number of devices in the namespace with the number of devices that were removed from that one and check if this sum is greater than the maximum number of devices.

type NamespaceSettings added in v0.5.0

type NamespaceSettings struct {
	SessionRecord bool `json:"session_record" bson:"session_record,omitempty"`
}

type OperatorParams added in v0.3.2

type OperatorParams struct {
	Name string `json:"name"`
}

type PaymentFailed added in v0.8.0

type PaymentFailed struct {
	Status  bool      `json:"status" bson:"status,omitempty"`
	Amount  float64   `json:"amount" bson:"amount,omitempty"`
	Date    time.Time `json:"date" bson:"date,omitempty"`
	Details string    `json:"details" bson:"details,omitempty"`
}

type PrivateKey added in v0.5.0

type PrivateKey struct {
	Data        []byte    `json:"data"`
	Fingerprint string    `json:"fingerprint"`
	CreatedAt   time.Time `json:"created_at" bson:"created_at"`
}

type PropertyParams added in v0.3.2

type PropertyParams struct {
	Name     string      `json:"name"`
	Operator string      `json:"operator"`
	Value    interface{} `json:"value"`
}

type PublicKey added in v0.5.0

type PublicKey struct {
	Data            []byte    `json:"data"`
	Fingerprint     string    `json:"fingerprint"`
	CreatedAt       time.Time `json:"created_at" bson:"created_at"`
	TenantID        string    `json:"tenant_id" bson:"tenant_id"`
	PublicKeyFields `bson:",inline"`
}

type PublicKeyAuthRequest added in v0.5.0

type PublicKeyAuthRequest struct {
	Fingerprint string `json:"fingerprint"`
	Data        string `json:"data"`
}

type PublicKeyAuthResponse added in v0.5.0

type PublicKeyAuthResponse struct {
	Signature string `json:"signature"`
}

type PublicKeyFields added in v0.5.0

type PublicKeyFields struct {
	Name     string          `json:"name"`
	Username string          `json:"username" bson:"username" validate:"regexp"`
	Filter   PublicKeyFilter `json:"filter" bson:"filter" validate:"required"`
}

func (*PublicKeyFields) Validate added in v0.6.1

func (p *PublicKeyFields) Validate() error

type PublicKeyFilter added in v0.9.1

type PublicKeyFilter struct {
	Hostname string   `json:"hostname,omitempty" bson:"hostname,omitempty" validate:"required_without=Tags,excluded_with=Tags,regexp"`
	Tags     []string `` /* 164-byte string literal not displayed */
}

PublicKeyFilter contains the filter rule of a Public Key.

A PublicKeyFilter can contain either Hostname, string, or Tags, slice of strings never both.

type PublicKeyUpdate added in v0.5.0

type PublicKeyUpdate struct {
	PublicKeyFields `bson:",inline"`
}

type RecordedSession added in v0.4.0

type RecordedSession struct {
	UID      UID       `json:"uid"`
	Message  string    `json:"message" bson:"message"`
	TenantID string    `json:"tenant_id" bson:"tenant_id,omitempty"`
	Time     time.Time `json:"time" bson:"time,omitempty"`
	Width    int       `json:"width" bson:"width,omitempty"`
	Height   int       `json:"height" bson:"height,omitempty"`
}

type Session

type Session struct {
	UID           string          `json:"uid"`
	DeviceUID     UID             `json:"device_uid,omitempty" bson:"device_uid"`
	Device        *Device         `json:"device" bson:"device,omitempty"`
	TenantID      string          `json:"tenant_id" bson:"tenant_id"`
	Username      string          `json:"username"`
	IPAddress     string          `json:"ip_address" bson:"ip_address"`
	StartedAt     time.Time       `json:"started_at" bson:"started_at"`
	LastSeen      time.Time       `json:"last_seen" bson:"last_seen"`
	Active        bool            `json:"active" bson:",omitempty"`
	Closed        bool            `json:"-" bson:"closed"`
	Authenticated bool            `json:"authenticated" bson:"authenticated"`
	Recorded      bool            `json:"recorded" bson:"recorded"`
	Type          string          `json:"type" bson:"type"`
	Term          string          `json:"term" bson:"term"`
	Position      SessionPosition `json:"position" bson:"position"`
}

type SessionPosition added in v0.10.0

type SessionPosition struct {
	Longitude float64 `json:"longitude" bson:"longitude"`
	Latitude  float64 `json:"latitude" bson:"latitude"`
}

type SessionRecorded added in v0.7.3

type SessionRecorded struct {
	UID       string `json:"uid"`
	Namespace string `json:"namespace" bson:"namespace"`
	Message   string `json:"message" bson:"message"`
	Width     int    `json:"width" bson:"width,omitempty"`
	Height    int    `json:"height" bson:"height,omitempty"`
}

type Stats

type Stats struct {
	RegisteredDevices int `json:"registered_devices"`
	OnlineDevices     int `json:"online_devices"`
	ActiveSessions    int `json:"active_sessions"`
	PendingDevices    int `json:"pending_devices"`
	RejectedDevices   int `json:"rejected_devices"`
}

type Status added in v0.7.3

type Status struct {
	Authenticated bool `json:"authenticated"`
}

type SystemInfo added in v0.11.8

type SystemInfo struct {
	Version   string               `json:"version"`
	Endpoints *SystemInfoEndpoints `json:"endpoints"`
}

type SystemInfoEndpoints added in v0.11.8

type SystemInfoEndpoints struct {
	API string `json:"api"`
	SSH string `json:"ssh"`
}

type Tenant added in v0.3.3

type Tenant struct {
	ID string
}

type UID

type UID string

type UsageRecord added in v0.8.0

type UsageRecord struct {
	Timestamp int64      `json:"timestamp" bson:"timestamp,omitempty"`
	Inc       bool       `json:"inc" bson:"type,omitempty"`
	Namespace *Namespace `json:"namespace"`
	Device    *Device    `json:"device"`
}

type User

type User struct {
	ID             string    `json:"id,omitempty" bson:"_id,omitempty"`
	Namespaces     int       `json:"namespaces" bson:"namespaces,omitempty"`
	MaxNamespaces  int       `json:"max_namespaces" bson:"max_namespaces"`
	Confirmed      bool      `json:"confirmed"`
	CreatedAt      time.Time `json:"created_at" bson:"created_at"`
	LastLogin      time.Time `json:"last_login" bson:"last_login"`
	EmailMarketing bool      `json:"email_marketing" bson:"email_marketing"`
	UserData       `bson:",inline"`
	UserPassword   `bson:",inline"`
}

type UserAuthClaims

type UserAuthClaims struct {
	Username string `json:"name"`
	Admin    bool   `json:"admin"`
	Tenant   string `json:"tenant"`
	ID       string `json:"id"`
	Role     string `json:"role"`

	AuthClaims           `mapstruct:",squash"`
	jwt.RegisteredClaims `mapstruct:",squash"`
}

type UserAuthRequest

type UserAuthRequest struct {
	Username string `json:"username"`
	Password string `json:"password"`
}

type UserAuthResponse

type UserAuthResponse struct {
	Token  string `json:"token"`
	User   string `json:"user"`
	Name   string `json:"name"`
	ID     string `json:"id"`
	Tenant string `json:"tenant"`
	Role   string `json:"role"`
	Email  string `json:"email"`
}

type UserData added in v0.8.0

type UserData struct {
	Name     string `json:"name" validate:"required,min=1"`
	Email    string `json:"email" bson:",omitempty" validate:"required,email"`
	Username string `json:"username" bson:",omitempty" validate:"required,username"`
}

type UserPassword added in v0.8.0

type UserPassword struct {
	Password string `json:"password" bson:",omitempty" validate:"required,min=5,max=30"`
}

type UserTokenRecover added in v0.7.2

type UserTokenRecover struct {
	Token     string    `json:"uid"`
	User      string    `json:"user_id"`
	CreatedAt time.Time `json:"created_at" bson:"created_at"`
}

type Username added in v0.5.0

type Username struct {
	ID string
}

Jump to

Keyboard shortcuts

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