util

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// configuration for phone home
	SitePhoneHomeName    = "phone_home"
	SitePhoneHomePost    = "POST"
	SitePhoneHomePostAll = "all"
	SitePhoneHomeUrl     = "url"
	SiteCloudConfig      = "#cloud-config"
)

Variables

View Source
var (
	LeadingWhitespaceRegexp  = regexp.MustCompile("^\\s+.*")
	TrailingWhitespaceRegexp = regexp.MustCompile(".*\\s+$")
	NotAllWhitespaceRegexp   = regexp.MustCompile("[^\\s]+")
	ShaHashRegex             = regexp.MustCompile("^[A-Fa-f0-9]+$")
	DiskImagePathRegex       = regexp.MustCompile("^/dev/(:?nvme\\d+n\\d+|sd*)")

	ValidationErrorExpectStringType          = errors.New("expect name field to be string type")
	ValidationErrorNameHasLeadingWhitespace  = errors.New("name field has leading whitespace")
	ValidationErrorNameHasTrailingWhitespace = errors.New("name field has trailing whitespace")
	ValidationErrorNameFieldIsEmpty          = errors.New("name field is empty")
	ValidationErrorOnlyWhitespace            = errors.New("field consists only of whitespace")

	// Label restrictions
	LabelKeyMaxLength   = 255
	LabelValueMaxLength = 255
	LabelCountMax       = 10

	// Label validation error messages
	ErrValidationLabelKeyEmpty    = errors.New("one or more labels do not have a key specified")
	ErrValidationLabelKeyLength   = fmt.Errorf("label key must contain at least 1 character and a maximum of %v characters", LabelKeyMaxLength)
	ErrValidationLabelValueLength = fmt.Errorf("label value cannot exceed a maximum of %v characters", LabelValueMaxLength)
	ErrValidationLabelCount       = fmt.Errorf("up to %v key/value pairs can be specified in labels", LabelCountMax)
)
View Source
var (
	CharsetAlphaNumeric = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
)
View Source
var TestCommonCloudInit = `` /* 1890-byte string literal not displayed */
View Source
var TestCommonInvalidCloudInit = `` /* 1948-byte string literal not displayed */
View Source
var TestCommonPhoneHomeCloudInit = `` /* 151-byte string literal not displayed */
View Source
var TestCommonPhoneHomeOnlyCloudInit = `#cloud-config
phone_home:
  url: http://169.254.169.254:7777/latest/meta-data/phone_home
  post: all`
View Source
var TestCommonPhoneHomeSegment = `
phone_home:
  empty_key_for_validation:
  url: http://localhost
  post: all`
View Source
var TestCommonXMLUserData = `` /* 392-byte string literal not displayed */

Functions

func GenerateRandomString

func GenerateRandomString(length int, charset string) string

GenerateRandomString generates a random string of a given length from a specified character set.

func GetUUIDPtrToStrPtr

func GetUUIDPtrToStrPtr(id *uuid.UUID) *string

util.GetUUIDPtrToStrPtr is a utility function to return string pointer from uuid pointer

func InsertPhoneHomeIntoUserData

func InsertPhoneHomeIntoUserData(documentRoot *yaml.Node, url string) error

func IsEmptyStrPtr

func IsEmptyStrPtr(s *string) bool

IsEmptyStrPtr is a utility function to check if the underlying value of a string pointer is empty

func IsNilOrEmptyStrPtr

func IsNilOrEmptyStrPtr(s *string) bool

IsNilOrEmptyStrPtr is a utility function to check if the string pointer is nil or the underlying value is empty

func ProtobufLabelsFromAPILabels

func ProtobufLabelsFromAPILabels(labels map[string]string) []*cwssaws.Label

ProtobufLabelsFromAPILabels converts API labels (map[string]string) to protobuf labels ([]*cwssaws.Label)

func RemovePhoneHomeFromUserData

func RemovePhoneHomeFromUserData(documentRoot *yaml.Node, url *string) error

Walks through the yaml nodes looking for a cloud-init phone-home block If `url` is nil, then any phone-home block found will be removed. If `url` is non-nil, then the phone-home block will only be removed if if the URL matches the value of `url`

func ValidateLabels added in v1.3.0

func ValidateLabels(labels map[string]string) error

ValidateLabels validates optional API label maps (count, keys, values). Returns nil when labels is nil.

func ValidateNameCharacters

func ValidateNameCharacters(value interface{}) error

ValidateNameCharacters is a utility function to lexically validate the name field currently checks for leading or trailing whitespaces could evolve in the future, if there are more constraints

func ValidateNested

func ValidateNested(target interface{}, fieldRules ...*validation.FieldRules) *validation.FieldRules

ValidateNested is a utility function to validate nested struct

Types

This section is empty.

Jump to

Keyboard shortcuts

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