types

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 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 CreateRequest

type CreateRequest struct {
	Name        string            `json:"name"`         // Name of the job
	ProjectName string            `json:"project_name"` // Project name of the job
	WebhookURL  string            `json:"webhook_url"`  // Webhook URL of the job
	Instances   []InstanceRequest `json:"instances"`    // Instances to create
}

CreateRequest represents a request to create infrastructure

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 {
	ProjectName   string   `json:"project_name" validate:"required"`         // Project name
	InstanceNames []string `json:"instance_names" validate:"required,min=1"` // Instances to delete
}

DeleteInstanceRequest represents the request body for deleting instances

type InstanceConfig

type InstanceConfig struct {
	Region            string         `json:"region"`                // Region where to create the instance
	OwnerID           uint           `json:"owner_id"`              // Owner ID of the instance
	Size              string         `json:"size"`                  // Size/type of the instance
	Image             string         `json:"image"`                 // OS image to use
	SSHKeyID          string         `json:"ssh_key_id"`            // SSH key name to use
	Tags              []string       `json:"tags,omitempty"`        // Tags to apply to the instance
	NumberOfInstances int            `json:"number_of_instances"`   // Number of instances to create
	CustomName        string         `json:"custom_name,omitempty"` // Optional custom name for this specific instance
	Volumes           []VolumeConfig `json:"volumes,omitempty"`     // Volumes to attach to the instance
}

InstanceConfig represents the configuration for creating an instance

type InstanceInfo

type InstanceInfo struct {
	ID             string            // Provider-specific instance ID
	Name           string            // Instance name
	PublicIP       string            // Public IP address
	Provider       models.ProviderID // Provider name (e.g., "do")
	Region         string            // Region where instance was created
	Size           string            // Instance size/type
	Tags           []string          // Tags of the instance
	Volumes        []string          `json:"volumes,omitempty"`         // List of attached volume IDs
	VolumeDetails  []VolumeDetails   `json:"volume_details,omitempty"`  // Detailed information about attached volumes
	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
}

InstanceInfo represents information about a created instance

type InstanceRequest

type InstanceRequest struct {
	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
	SSHKeyName        string            `json:"ssh_key_name"`              // Name of the SSH key to use
	Tags              []string          `json:"tags"`                      // Tags to apply to instances
	NumberOfInstances int               `json:"number_of_instances"`       // Number of instances to create
	Name              string            `json:"name"`                      // Optional custom name for instances
	Provision         bool              `json:"provision"`                 // Whether to run Ansible provisioning
	Volumes           []VolumeConfig    `json:"volumes"`                   // Optional volumes to attach
	OwnerID           uint              `json:"owner_id"`                  // Owner ID of the instance
	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
	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.
}

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 InstancesRequest

type InstancesRequest struct {
	InstanceName string            `json:"instance_name"`
	ProjectName  string            `json:"project_name"`
	TaskName     string            `json:"-"` // used internally by the Infra API
	Instances    []InstanceRequest `json:"instances"`
	WebhookURL   string            `json:"webhook_url"`
	Action       string            `json:"action"`
	Provider     models.ProviderID `json:"provider"`
	Volumes      []VolumeConfig    `json:"volumes"`
}

InstancesRequest represents an RPC request multiple instances NOTE: These should be cleaned up and replaced with specific RPC request types

func (*InstancesRequest) Validate

func (r *InstancesRequest) Validate() error

Validate validates the infrastructure request

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