types

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package types provides type definitions for the application

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ValidateVolume

func ValidateVolume(v *VolumeConfig, instanceRegion string) error

ValidateVolume checks if the volume configuration is valid

Types

type CreateUserRequest

type CreateUserRequest struct {
	Username     string          `json:"username" gorm:"not null;unique"`
	Email        string          `json:"email" gorm:""`
	Role         models.UserRole `json:"role" gorm:"index"`
	PublicSSHKey string          `json:"public_ssh_key" gorm:""`
}

CreateUserRequest represents a request to create a new user

func (CreateUserRequest) Validate

func (u CreateUserRequest) Validate() error

Validate validates the create user request

type CreateUserResponse

type CreateUserResponse struct {
	UserID uint `json:"id"`
}

CreateUserResponse represents the response from the create user endpoint

type DeleteInstanceRequest

type DeleteInstanceRequest struct {
	InstanceID uint `json:"instance_id" validate:"required"` // Instance ID to delete
}

DeleteInstanceRequest represents the request body for deleting a single instance

type DeleteInstancesRequest added in v0.0.2

type DeleteInstancesRequest struct {
	OwnerID       uint     `json:"owner_id" validate:"required"`             // Owner ID
	ProjectName   string   `json:"project_name" validate:"required"`         // Project name
	InstanceNames []string `json:"instance_names" validate:"required,min=1"` // Instances to delete
}

DeleteInstancesRequest represents the request body for deleting instances

type InstanceRequest

type InstanceRequest struct {
	// DB Model Data - User Defined
	Name     string            `json:"name"`     // Name for instance, or instances if number_of_instances > 1
	OwnerID  uint              `json:"owner_id"` // Owner ID of the instance
	Provider models.ProviderID `json:"provider"` // Cloud provider (e.g., "do")
	Region   string            `json:"region"`   // Region where instances will be created
	Size     string            `json:"size"`     // Instance size/type
	Image    string            `json:"image"`    // OS image to use
	Tags     []string          `json:"tags"`     // Tags to apply to instances

	// DB Model Data - Internally set during creation
	InstanceID    uint            `json:"instance_id"`              // Instance ID
	PublicIP      string          `json:"public_ip"`                // Public IP address
	VolumeIDs     []string        `json:"volume_ids,omitempty"`     // List of attached volume IDs
	VolumeDetails []VolumeDetails `json:"volume_details,omitempty"` // Detailed information about attached volumes

	// User Defined Configs
	ProjectName       string         `json:"project_name"`
	SSHKeyName        string         `json:"ssh_key_name"`              // Name of the SSH key to use
	NumberOfInstances int            `json:"number_of_instances"`       // Number of instances to create
	Provision         bool           `json:"provision"`                 // Whether to run Ansible provisioning
	PayloadPath       string         `json:"payload_path,omitempty"`    // Local path to the payload script on the API server
	ExecutePayload    bool           `json:"execute_payload,omitempty"` // Whether to execute the payload after copying
	Volumes           []VolumeConfig `json:"volumes"`                   // Optional volumes to attach

	// Talis Server Configs - Optional
	SSHKeyType string `json:"ssh_key_type,omitempty"` // Type of the private SSH key for Ansible (e.g., "rsa", "ed25519"). Defaults to "rsa".
	SSHKeyPath string `json:"ssh_key_path,omitempty"` // Custom path to the private SSH key file for Ansible. Overrides defaults.

	// Internal Configs - Set by the Talis Server
	Action             string `json:"action"`
	ProviderInstanceID int    `json:"provider_instance_id"` // Provider-specific instance ID
	LastTaskID         uint   `json:"last_task_id"`         // ID of the last task
}

InstanceRequest represents an RPC request for a single instance NOTE: These should be cleaned up and replaced with specific RPC request types

func (*InstanceRequest) Validate

func (i *InstanceRequest) Validate() error

Validate validates the instance configuration

type ListResponse

type ListResponse[T any] struct {
	Rows       []T                `json:"rows"`
	Pagination PaginationResponse `json:"pagination"`
}

ListResponse defines a generic response structure for listing resources

type PaginationResponse

type PaginationResponse struct {
	Total  int `json:"total"`  // Total number of values
	Page   int `json:"page"`   // Current page number
	Limit  int `json:"limit"`  // Number of items per page
	Offset int `json:"offset"` // Offset from start of results
}

PaginationResponse represents pagination information

type PublicIPs

type PublicIPs struct {
	PublicIP string `json:"public_ip"`
}

PublicIPs represents the public IPs of the instances

type PublicIPsResponse

type PublicIPsResponse struct {
	PublicIPs  []PublicIPs        `json:"public_ips"` // List of public IPs
	Pagination PaginationResponse `json:"pagination"` // Pagination information
}

PublicIPsResponse represents the response from the public IPs endpoint

type Response

type Response struct {
	ID     uint   `json:"id"`     // ID of the infrastructure job
	Status string `json:"status"` // Status of the infrastructure job
}

Response represents the response from the infrastructure API

type Slug

type Slug string

Slug is a type for the slug field in the response It is mainly used for the client to understand the type of the response

const (
	SuccessSlug      Slug = "success"
	ErrorSlug        Slug = "error"
	InvalidInputSlug Slug = "invalid-input"
	ServerErrorSlug  Slug = "server-error"
	NotFoundSlug     Slug = "not-found"
)

nolint:gochecknoglobals

type SlugResponse

type SlugResponse struct {
	Slug  Slug        `json:"slug"`
	Error string      `json:"error"`
	Data  interface{} `json:"data"`
}

SlugResponse is the response type for the API TODO: I think this needs to be revised, I think a generic APIResponse type would be better. The Client methods would need to be updated to ingest the APIResponse type and then decode the data into the appropriate type.

func ErrInvalidInput

func ErrInvalidInput(msg string) SlugResponse

ErrInvalidInput returns a SlugResponse with the InvalidInputSlug and the error message

func ErrNotFound

func ErrNotFound(msg string) SlugResponse

ErrNotFound returns a SlugResponse with the NotFoundSlug and the error message

func ErrServer

func ErrServer(msg string) SlugResponse

ErrServer returns a SlugResponse with the ServerErrorSlug and the error message

func Success

func Success(data interface{}) SlugResponse

Success returns a SlugResponse with the SuccessSlug and the data

type TaskResponse

type TaskResponse struct {
	TaskName string `json:"task_name"` // Name of the task
}

TaskResponse represents the response when a task is created or acted upon.

type UserResponse

type UserResponse struct {
	// This can be a single user or null when returning multiple users
	User models.User `json:"user,omitempty"`

	// This can be an array of users or null when returning a single user
	Users []models.User `json:"users,omitempty"`

	// Pagination info included only when returning multiple users
	Pagination *PaginationResponse `json:"pagination,omitempty"`
}

UserResponse is a flexible response type for both single and multiple user scenarios

type VolumeConfig

type VolumeConfig struct {
	Name       string `json:"name"`        // Name of the volume
	SizeGB     int    `json:"size_gb"`     // Size in gigabytes
	Region     string `json:"region"`      // Region where to create the volume
	FileSystem string `json:"filesystem"`  // File system type (optional)
	MountPoint string `json:"mount_point"` // Where to mount the volume
}

VolumeConfig represents the configuration for a volume

type VolumeDetails

type VolumeDetails struct {
	ID         string `json:"id"`          // Volume ID
	Name       string `json:"name"`        // Volume name
	Region     string `json:"region"`      // Region where volume was created
	SizeGB     int    `json:"size_gb"`     // Size in gigabytes
	MountPoint string `json:"mount_point"` // Where the volume is mounted
}

VolumeDetails represents detailed information about a created volume

Jump to

Keyboard shortcuts

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