models

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 7 Imported by: 4

Documentation

Overview

Package models hosts all sharing models between api endpoints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RedactURL added in v0.7.1

func RedactURL(u *url.URL) string

RedactURL returns u as a string with the API-key query parameter replaced by REDACTED. The original URL is not modified.

It rewrites RawQuery textually rather than round-tripping through url.Values, so every other parameter survives byte-for-byte: original order, duplicates, and valueless keys all preserved. A redacted error should differ from the real URL by exactly one value — this repo added pkg/net.Encode precisely because Values.Encode re-sorts, and the error path should not reintroduce that.

Exported so callers building their own error text get the same treatment rather than reimplementing it — the alternative is that each caller redacts a slightly different set, which is how one gets missed.

Types

type APIResponse

type APIResponse struct {
	Msg    string `json:"msg"`
	Status bool   `json:"status"`
}

APIResponse represents mutual API response values.

type ClientBase

type ClientBase struct {
	// Base URL for API request. Always be specified with a trailing slash.
	BaseURL *url.URL

	// User agent used when communicating with the SiteHost API.
	UserAgent string

	// API Credentials
	APIKey   string
	ClientID string

	// Host for the GitLab instance backing custom-image repositories.
	// Defaults to "gitlab-clients.sitehost.co.nz". Override via
	// api.SetCustomImageGitHost for staging/test environments.
	CustomImageGitHost string
}

ClientBase includes the base variables for the client struct.

type CloudImage added in v0.4.0

type CloudImage struct {
	ID       string `json:"id"`
	ClientID string `json:"client_id"`
	Label    string `json:"label"`
	Code     string `json:"code"`
	Version  string `json:"version"`
	// this is a string in the api docs for the cloud image call...
	// but below, in the cloud stack image call, it's a struct...
	Labels         string            `json:"labels"`
	Changelog      string            `json:"changelog"`
	DateAdded      string            `json:"date_added"`
	DateUpdated    string            `json:"date_updated"`
	IsPublic       shtypes.MaybeBool `json:"is_public"`
	IsMissing      shtypes.MaybeBool `json:"is_missing"`
	ProjectID      string            `json:"project_id"`
	RegistryID     string            `json:"registry_id"`
	ForkedFrom     string            `json:"forked_from"`
	Pending        string            `json:"pending"`
	ClientName     string            `json:"client_name"`
	ImageType      string            `json:"image_type"`
	RegistryURL    string            `json:"registry_url"`
	VersionCount   int               `json:"version_count"`
	ContainerCount int               `json:"container_count"`
	BuildStatus    string            `json:"build_status"`
}

CloudImage represents an image in the /cloud/image.

type CloudServer added in v0.3.1

type CloudServer struct {
	ID                  string   `json:"id"`
	ClientID            string   `json:"client_id"`
	Name                string   `json:"name"`
	Label               string   `json:"label"`
	State               string   `json:"state"`
	PrimaryIP           string   `json:"primary_ip"`
	IPAddrProxy         string   `json:"ip_addr_proxy"`
	ProductID           string   `json:"product_id"`
	Owner               bool     `json:"owner"`
	ImagesUsed          []string `json:"images_used"`
	ImagesRemaining     int      `json:"images_remaining"`
	ContainersRemaining int      `json:"containers_remaining"`
}

CloudServer is a view of a server that can run stacks on. This server also exists under the server API.

type Container added in v0.3.1

type Container struct {
	Name        string      `json:"name"`
	ContainerID string      `json:"container_id"`
	State       string      `json:"state"`
	Size        string      `json:"size"`
	DateCreated string      `json:"date_created"`
	SslEnabled  bool        `json:"ssl_enabled"`
	IsMissing   interface{} `json:"is_missing"`
	Pending     interface{} `json:"pending"`
}

Container represents a container inside a stack.

type DNSRecord added in v0.3.1

type DNSRecord struct {
	ID         string `json:"id"`
	ClientID   string `json:"client_id"`
	Name       string `json:"name"`
	Domain     string `json:"domain"`
	Type       string `json:"type"`
	Content    string `json:"content"`
	TTL        string `json:"ttl"`
	Priority   string `json:"prio"`
	ChangeDate string `json:"change_date"`
	State      string `json:"state"`
}

DNSRecord A dns record from a zone.

type DNSZone added in v0.3.1

type DNSZone struct {
	Name       string `json:"name"`
	ClientID   string `json:"client_id"`
	TemplateID string `json:"template_id"`
	Pending    string `json:"pending"`
}

DNSZone represent a DNS domain.

type Database added in v0.4.0

type Database struct {
	ID          string      `json:"id"`
	DBName      string      `json:"db_name"`
	MySQLHost   string      `json:"mysql_host"`
	Size        interface{} `json:"size"`
	ClientID    string      `json:"client_id"`
	ServerID    string      `json:"server_id"`
	Pending     string      `json:"pending"`
	IsMissing   string      `json:"is_missing"`
	DateAdded   string      `json:"date_added"`
	DateUpdated string      `json:"date_updated"`
	ServerName  string      `json:"server_name"`
	ServerLabel string      `json:"server_label"`
	ServerIP    string      `json:"server_ip"`
	ServerOwner bool        `json:"server_owner"`
	Container   string      `json:"container"`
	Grants      []Grant     `json:"grants"`
}

Database represents a database on a cloud server. Some properties may or may not be populated depending on how we call.

type DatabaseUser added in v0.4.0

type DatabaseUser struct {
	Username    string      `json:"username"`
	Password    string      `json:"password"`
	MysqlHost   string      `json:"mysql_host"`
	ServerID    string      `json:"server_id"`
	ClientID    string      `json:"client_id"`
	Pending     interface{} `json:"pending"`
	IsMissing   string      `json:"is_missing"`
	DateAdded   string      `json:"date_added"`
	DateUpdated string      `json:"date_updated"`
	ServerName  string      `json:"server_name"`
	ServerLabel string      `json:"server_label"`
	Grants      []Grant     `json:"grants"`
}

DatabaseUser represents a database user on a cloud server.

type EnvironmentVariable added in v0.3.1

type EnvironmentVariable struct {
	Name    string `json:"name"`
	Content string `json:"content"`
}

EnvironmentVariable is a stack environment variable key-pair.

type ErrorResponse

type ErrorResponse struct {
	Response *http.Response `json:"-"`
	Message  string         `json:"msg"`
	Status   bool           `json:"status"`
}

ErrorResponse reports the error caused by an API request.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

Error returns a ErrorResponse message.

The URL is redacted before it is formatted. The API key travels as a query parameter, so an unredacted URL puts the caller's credential into every error string — and error strings get wrapped, logged, shipped to log aggregators and pasted into tickets.

type Filtering added in v0.4.0

type Filtering struct {
	SortBy     string `url:"filters[sort_by],omitempty"`
	SortDir    string `url:"filters[sort_dir],omitempty"`
	PageSize   int    `url:"filters[page_size],omitempty"`
	PageNumber int    `url:"filters[page_number],omitempty"`
}

Filtering is a struct for filtering results.

type Grant added in v0.4.0

type Grant struct {
	DBName      string      `json:"db_name"`
	Username    string      `json:"username"`
	Host        string      `json:"host"`
	MySQLHost   string      `json:"mysql_host"`
	Grants      []string    `json:"grants"`
	Pending     interface{} `json:"pending"`
	IsMissing   string      `json:"is_missing"`
	DateAdded   string      `json:"date_added"`
	DateUpdated string      `json:"date_updated"`
}

Grant represents database grants.

type IP

type IP struct {
	ID         string `json:"id"`
	ServerID   string `json:"server_id"`
	Bridge     string `json:"bridge"`
	MacAddr    string `json:"mac_addr"`
	IPType     string `json:"ip_type"`
	Prefix     string `json:"prefix"`
	Primary    bool   `json:"primary"`
	AddrFamily int    `json:"addr_family"`
	NetworkID  string `json:"network_id"`
	Rdns       string `json:"rdns"`
	IPAddr     string `json:"ip_addr"`
	Network    string `json:"network"`
	Gateway    string `json:"gateway"`
	Netmask    string `json:"netmask"`
	Broadcast  string `json:"broadcast"`
}

IP represents the ips attached to the Server.

type IPAddress added in v0.4.0

type IPAddress struct {
	IP            string `json:"ip_addr"`
	Netmask       string `json:"netmask"`
	Prefix        string `json:"prefix"`
	Reserved      string `json:"reserved"`
	RDNS          string `json:"rdns"`
	Family        string `json:"addr_family"`
	DateAllocated string `json:"date_allocated"`
}

IPAddress does what it says on the can. It's an IP address.

**IPv6 wire-shape quirk + normalisation.** /bandwidth/get_ip_list.json serialises IPv6 addresses with ':' replaced by '.' (and '::' as '..'), e.g. "2403.7000.8000.300..ce/128" rather than "2403:7000:8000:300::ce/128". The mangled form is rejected by every IP-input endpoint, so a naive read-then-write round-trip breaks for IPv6 addresses retrieved from this struct.

Custom UnmarshalJSON canonicalises the IP back to standard IPv6 syntax when Family is "6" — '..' → '::' first, then remaining '.' between hextets → ':'. IPv4 (family "4") is passed through untouched. After unmarshalling, the IP field is safe to feed back into any IP-input endpoint.

The mangling is localised to /bandwidth/get_ip_list.json — /bandwidth/get_usage_summary.json and /server/list_servers.json both emit canonical IPv6 — but the normaliser is benign on already-canonical strings, so it doesn't matter where the IPAddress originated.

func (*IPAddress) UnmarshalJSON added in v0.7.0

func (ip *IPAddress) UnmarshalJSON(data []byte) error

UnmarshalJSON normalises mangled IPv6 IP fields — see type docs.

type Job added in v0.5.0

type Job struct {
	ID   int    `json:"id"`
	Type string `json:"type"`
}

Job represents reference to a job.

type JobDetails

type JobDetails struct {
	State     string `json:"state"`
	Created   string `json:"created"`
	Started   string `json:"started"`
	Completed string `json:"completed"`
	Logs      []Log  `json:"logs"`
	Message   string `json:"message"`
}

JobDetails represents the job information returned by job/get.json.

Message is populated when the job has surfaced a top-level error or status message — typically present on state="Failed" and on some completed-but-noisy outcomes. It mirrors the API's `return.message` field and is the right place to read a human-friendly explanation of why a job failed (e.g. "Image not typed", "job already running on this stack"). Distinct from the per-step Logs entries.

type Kernel

type Kernel struct {
	Default    bool   `json:"default"`
	Kernel     string `json:"kernel"`
	Initrd     string `json:"initrd"`
	Modules    string `json:"modules"`
	Hypervisor string `json:"hypervisor"`
}

Kernel represents the kernel available to the Server.

type Log

type Log struct {
	Date    string `json:"date"`
	Level   string `json:"level"`
	Message string `json:"message"`
}

Log represents the logs attached to the JobDetails.

type Pagination added in v0.3.1

type Pagination struct {
	TotalItems   int `json:"total_items"`
	CurrentItems int `json:"current_items"`
	CurrentPage  int `json:"current_page"`
	TotalPages   int `json:"total_pages"`
}

Pagination represents the pagination information return by the API.

type Partition

type Partition struct {
	ID             string `json:"id"`
	Name           string `json:"name"`
	Device         string `json:"device"`
	Mountpoint     string `json:"mountpoint"`
	Size           string `json:"size"`
	NewSize        string `json:"new_size"`
	Fstype         string `json:"fstype"`
	Drbd           string `json:"drbd"`
	Backup         string `json:"backup"`
	DiskTotal      string `json:"disk_total"`
	DiskUsed       string `json:"disk_used"`
	InodesTotal    string `json:"inodes_total"`
	InodesUsed     string `json:"inodes_used"`
	AlertThreshold string `json:"alert_threshold"`
	Type           string `json:"type"`
}

Partition represents the disk partitions attached to the Server.

type Port added in v0.4.0

type Port struct {
	Exposed  bool
	Publish  bool
	Protocol string
}

Port is for storing the exposed port information for a container.

type SSHKey added in v0.3.1

type SSHKey struct {
	ID                string            `json:"id"`
	ClientID          string            `json:"client_id"`
	Label             string            `json:"label"`
	Content           string            `json:"content"`
	DateAdded         string            `json:"date_added"`
	DateUpdated       string            `json:"date_updated"`
	CustomImageAccess shtypes.MaybeBool `json:"custom_image_access"`
}

SSHKey represents an SSH key in the SiteHost Api.

type Server

type Server struct {
	Name             string              `json:"name"`
	Label            string              `json:"label"`
	ClientID         shtypes.MaybeString `json:"client_id"`
	Created          string              `json:"created"`
	Type             string              `json:"type"`
	RAM              string              `json:"ram"`
	Root             string              `json:"root"`
	Disk             shtypes.MaybeBigInt `json:"disk"`
	Cores            shtypes.MaybeBigInt `json:"cores"`
	Core             string              `json:"core"`
	Arch             string              `json:"arch"`
	Kernel           string              `json:"kernel"`
	Initrd           string              `json:"initrd"`
	Modules          string              `json:"modules"`
	Distro           string              `json:"distro"`
	Os               string              `json:"os"`
	Rescue           string              `json:"rescue"`
	Managed          string              `json:"managed"`
	Locked           string              `json:"locked"`
	LockedFrom       string              `json:"locked_from"`
	LockedUntil      string              `json:"locked_until"`
	LockedComment    string              `json:"locked_comment"`
	State            string              `json:"state"`
	MaintDate        string              `json:"maint_date"`
	MaintDateEnd     string              `json:"maint_date_end"`
	EmailLogs        string              `json:"email_logs"`
	VncPort          string              `json:"vnc_port"`
	VncScreen        string              `json:"vnc_screen"`
	IPAddrLimit      string              `json:"ip_addr_limit"`
	Notes            string              `json:"notes"`
	Ips              []IP
	Interfaces       []string      `json:"interfaces"`
	GroupID          string        `json:"group_id"`
	Partitions       []Partition   `json:"partitions"`
	BackupTypes      []interface{} `json:"backup_types"`
	AvailableKernels []Kernel      `json:"available_kernels"`
	ProductCode      string        `json:"product_code"`
	ProductType      string        `json:"product_type"`
	ProductName      string        `json:"product_name"`
	Subscription     Subscription  `json:"subscription"`
	LocationName     string        `json:"location_name"`
	LocationCode     string        `json:"location_code"`
	Mirror           string        `json:"mirror"`
	LastJob          JobDetails    `json:"last_job"`
	BackupsEnabled   bool          `json:"backups_enabled"`
	BackupsProduct   interface{}   `json:"backups_product"`
	LocationNode     string        `json:"location_node"`
}

Server represents a Server in the SiteHost.

type Stack added in v0.3.1

type Stack struct {
	ClientID    string      `json:"client_id"`
	ServerID    string      `json:"server_id"`
	Server      string      `json:"server_name"`
	ServerLabel string      `json:"server_label"`
	Name        string      `json:"name"`
	Label       string      `json:"label"`
	DockerFile  string      `json:"docker_file"`
	IPAddress   string      `json:"ip_addr_server"`
	DateAdded   string      `json:"date_added"`
	DateUpdated string      `json:"date_updated"`
	Containers  []Container `json:"containers"`
	ServerOwner bool        `json:"server_owner"`
	Pending     interface{} `json:"pending"`
	IsMissing   interface{} `json:"is_missing"`
}

Stack represents a cloud stack and it's configuration.

type StackImage added in v0.4.0

type StackImage struct {
	ID             string                 `json:"id"`
	ClientID       string                 `json:"client_id"`
	Label          string                 `json:"label"`
	Code           string                 `json:"code"`
	Version        string                 `json:"version"`
	Labels         map[string]interface{} `json:"labels"`
	Changelog      string                 `json:"changelog"`
	DateAdded      string                 `json:"date_added"`
	DateUpdated    string                 `json:"date_updated"`
	IsPublic       shtypes.MaybeBool      `json:"is_public"`
	IsMissing      shtypes.MaybeBool      `json:"is_missing"`
	ProjectID      string                 `json:"project_id"`
	RegistryID     string                 `json:"registry_id"`
	ForkedFrom     string                 `json:"forked_from"`
	Pending        interface{}            `json:"pending"`
	ClientName     string                 `json:"client_name"`
	ImageType      string                 `json:"image_type"`
	RegistryURL    string                 `json:"registry_url"`
	VersionCount   int                    `json:"version_count"`
	ContainerCount int                    `json:"container_count"`
	BuildStatus    string                 `json:"build_status"`
	Versions       []StackImageVersion    `json:"versions"`
}

StackImage represents an image in the /cloud/stack/image.

type StackImageVersion added in v0.4.0

type StackImageVersion struct {
	ID          string      `json:"id"`
	ClientID    string      `json:"client_id"`
	ImageIDs    string      `json:"image_id"`
	Version     string      `json:"version"`
	Labels      string      `json:"labels"`
	DateAdded   string      `json:"date_added"`
	DateUpdated string      `json:"date_updated"`
	IsMissing   string      `json:"is_missing"`
	ForceConfig string      `json:"force_config"`
	BuildID     string      `json:"build_id"`
	BuildStatus string      `json:"build_status"`
	Pending     interface{} `json:"pending"`
}

StackImageVersion stores the version information for a StackImage.

type Subscription

type Subscription struct {
	Code  string `json:"code"`
	Name  string `json:"name"`
	Price string `json:"price"`
}

Subscription represents the subscription attached to the Server.

type User added in v0.4.0

type User struct {
	Username       string            `json:"username"`
	ServerID       string            `json:"server_id"`
	ClientID       string            `json:"client_id"`
	HomeDir        string            `json:"home_dir"`
	SSHKeys        []SSHKey          `json:"ssh_keys"`
	Pending        interface{}       `json:"pending"`
	IsMissing      shtypes.MaybeBool `json:"is_missing"`
	DateAdded      string            `json:"date_added"`
	DateUpdated    string            `json:"date_updated"`
	ServerName     string            `json:"server_name"`
	ServerLabel    string            `json:"server_label"`
	ServerOwner    shtypes.MaybeBool `json:"server_owner"`
	Image          string            `json:"image"`
	Containers     []string          `json:"containers"`
	Volumes        []string          `json:"volumes"`
	ReadOnlyConfig shtypes.MaybeBool `json:"read_only_config"`
	IPAddr         string            `json:"ip_addr"`
}

User represents a SSH/SFTP user.

type Volume added in v0.4.0

type Volume struct {
	Hash   string `json:"hash"`
	Source struct {
		Filename string `json:"filename"`
		URL      string `json:"url"`
	} `json:"source"`
	Type string `json:"type"`

	Volumes struct {
		Application struct {
			Dest string `json:"dest"`
			GID  int    `json:"gid"`
			Mode string `json:"mode"`
			UID  int    `json:"uid"`
		} `json:"application"`
	} `json:"volumes"`
}

Volume is for storing the volume information for a container.

Jump to

Keyboard shortcuts

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