utils

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2026 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AvailableImages = map[string]Images{

	"debian-12-x86_64": {
		Name:         "debian-12-x86_64",
		Description:  "Debian 12 (Bookworm) x86_64 cloud image (generic cloud)",
		Distro:       "debian",
		Version:      "12",
		Arch:         "x86_64",
		Platform:     "Linux/UNIX",
		CreatedAt:    time.Date(2025, 10, 6, 0, 0, 0, 0, time.UTC),
		URL:          "https://cdimage.debian.org/cdimage/cloud/bookworm/latest/debian-12-generic-amd64.tar.xz",
		Checksum:     "https://cdimage.debian.org/cdimage/cloud/bookworm/latest/SHA512SUMS",
		ChecksumType: "sha512",
		BootMode:     "bios",
		Starred:      true,
	},

	"debian-12-arm64": {
		Name:         "debian-12-arm64",
		Description:  "Debian 12 (Bookworm) arm64 cloud image (generic cloud)",
		Distro:       "debian",
		Version:      "12",
		Arch:         "arm64",
		Platform:     "Linux/UNIX",
		CreatedAt:    time.Date(2025, 10, 6, 0, 0, 0, 0, time.UTC),
		URL:          "https://cdimage.debian.org/cdimage/cloud/bookworm/latest/debian-12-generic-arm64.tar.xz",
		Checksum:     "https://cdimage.debian.org/cdimage/cloud/bookworm/latest/SHA512SUMS",
		ChecksumType: "sha512",
		BootMode:     "bios",
		Starred:      true,
	},

	"ubuntu-24.04-x86_64": {

		Name:         "ubuntu-24.04-x86_64",
		Description:  "Ubuntu 24.04 LTS (Noble Numbat) x86_64 cloud image",
		Distro:       "ubuntu",
		Version:      "24.04",
		Arch:         "x86_64",
		Platform:     "Linux/UNIX",
		CreatedAt:    time.Date(2025, 10, 6, 0, 0, 0, 0, time.UTC),
		URL:          "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img",
		Checksum:     "https://cloud-images.ubuntu.com/noble/current/SHA256SUMS",
		ChecksumType: "sha256",
		BootMode:     "bios",
		Starred:      false,
	},

	"ubuntu-24.04-arm64": {

		Name:         "ubuntu-24.04-arm64",
		Description:  "Ubuntu 24.04 LTS (Noble Numbat) arm64 cloud image",
		Distro:       "ubuntu",
		Version:      "24.04",
		Arch:         "arm64",
		Platform:     "Linux/UNIX",
		CreatedAt:    time.Date(2025, 10, 6, 0, 0, 0, 0, time.UTC),
		URL:          "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-arm64.img",
		Checksum:     "https://cloud-images.ubuntu.com/noble/current/SHA256SUMS",
		ChecksumType: "sha256",
		BootMode:     "bios",
		Starred:      false,
	},

	"alpine-3.22.2-x86_64": {
		Name:         "alpine-3.22.2-x86_64",
		Description:  "Alpine Linux 3.22.2 x86_64 cloud image",
		Distro:       "alpine",
		Version:      "3.22.2",
		Arch:         "x86_64",
		Platform:     "Linux/UNIX",
		CreatedAt:    time.Date(2025, 10, 6, 0, 0, 0, 0, time.UTC),
		URL:          "https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/cloud/generic_alpine-3.22.2-x86_64-bios-cloudinit-r0.qcow2",
		Checksum:     "https://dl-cdn.alpinelinux.org/alpine/v3.22/releases/cloud/generic_alpine-3.22.2-x86_64-bios-cloudinit-r0.qcow2.sha512",
		ChecksumType: "sha512",
		BootMode:     "bios",
		Starred:      false,
	},
}
View Source
var ErrQCOWDetected = errors.New("qcow format detected")

Functions

func CreateS3Client

func CreateS3Client(cfg *config.Config) *s3.S3

func DownloadFileWithProgress

func DownloadFileWithProgress(url string, name string, filename string, timeout time.Duration) (err error)

func ExtractDiskImageFromFile

func ExtractDiskImageFromFile(imagepath string, tmpdir string) (diskimage string, err error)

AMI / image extraction utils

func FormatNBDSocketURI added in v0.2.0

func FormatNBDSocketURI(socketPath string) string

FormatNBDSocketURI formats a socket path as an NBD URI for QEMU. Returns format: nbd:unix:/path/to/socket.sock

func FormatNBDTCPURI added in v0.2.0

func FormatNBDTCPURI(host string, port int) string

FormatNBDTCPURI formats a host:port as an NBD URI for QEMU. Returns format: nbd://host:port

func GenerateErrorPayload

func GenerateErrorPayload(code string) (jsonResponse []byte)

Generate JSON Error Payload

func GeneratePidFile

func GeneratePidFile(name string) (string, error)

func GenerateSocketFile

func GenerateSocketFile(name string) (string, error)

GenerateSocketFile generates a socket file path for the given name. Deprecated: Use GenerateUniqueSocketFile for new code to ensure uniqueness.

func GenerateUniqueSocketFile added in v0.2.0

func GenerateUniqueSocketFile(volname string) (string, error)

GenerateUniqueSocketFile generates a unique socket file path with unix nano timestamp. Format: nbd-{volname}-{unixnano}.sock This ensures each mount operation gets a unique socket path.

func GenerateXMLPayload

func GenerateXMLPayload(locationName string, payload any) any

wrapWithLocation decorates payload with the requested locationName tag.

func IsSocketURI added in v0.2.0

func IsSocketURI(nbdURI string) bool

IsSocketURI returns true if the NBD URI is a Unix socket path. Socket URIs end with ".sock" or contain "unix:".

func KillProcess

func KillProcess(pid int) error

func MarshalJsonPayload

func MarshalJsonPayload(input any, jsonData []byte) []byte

func MarshalToXML

func MarshalToXML(payload any) ([]byte, error)

Convert interface to XML

func ReadPidFile

func ReadPidFile(name string) (int, error)

func RemovePidFile

func RemovePidFile(serviceName string) error

func SafeInt64ToUint64 added in v0.2.0

func SafeInt64ToUint64(v int64) uint64

SafeInt64ToUint64 converts int64 to uint64, returning 0 if negative

func SafeIntToUint64 added in v0.2.0

func SafeIntToUint64(v int) uint64

SafeIntToUint64 converts int to uint64, returning 0 if negative

func SafeUint64ToInt64 added in v0.2.0

func SafeUint64ToInt64(v uint64) int64

SafeUint64ToInt64 converts uint64 to int64, capping at math.MaxInt64

func StopProcess

func StopProcess(serviceName string) error

func UnmarshalJsonPayload

func UnmarshalJsonPayload(input any, jsonData []byte) []byte

func ValidateErrorPayload

func ValidateErrorPayload(payload []byte) (responseError ec2.ResponseError, err error)

Validate the payload is an ec2.ResponseError

func ValidateKeyPairName

func ValidateKeyPairName(name string) error

ValidateKeyPairName validates that a key pair name only contains allowed characters: - Uppercase A-Z - Lowercase a-z - Digits 0-9 - Hyphen (-) - Underscore (_) - Period (.) This prevents path traversal attacks and invalid characters like /etc/passwd, ../../../, etc. Returns ErrorInvalidKeyPairFormat if validation fails

func WaitForPidFileRemoval

func WaitForPidFileRemoval(instanceID string, timeout time.Duration) error

func WritePidFile

func WritePidFile(name string, pid int) error

Types

type Images

type Images struct {
	Name         string    `json:"name"`
	Description  string    `json:"description"`
	Distro       string    `json:"distro"`
	Version      string    `json:"version"`
	Arch         string    `json:"arch"`
	Platform     string    `json:"platform"`
	CreatedAt    time.Time `json:"created_at"`
	URL          string    `json:"url"`
	Checksum     string    `json:"checksum"`
	ChecksumType string    `json:"checksum_type"`
	BootMode     string    `json:"boot_mode"`
	Starred      bool      `json:"starred"`
}

Jump to

Keyboard shortcuts

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