base

package
v1.1.68-test Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 10 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseRule

func BaseRule() *validate.Rule

BaseRule ports Base = Joi.object({id, name, kind, version, description, tags, created, lastModified, links}). Resources compose it via Reflect(self) plus their spec/status keys.

func ContainsJSWhitespace

func ContainsJSWhitespace(s string) bool

ContainsJSWhitespace reports whether s contains a character JavaScript's `\s` matches.

func DescriptionDefaultsToName

func DescriptionDefaultsToName(obj any, h *validate.Helper) (any, error)

DescriptionDefaultsToName ports the common createSchema fork `description: DescriptionRule().Default(Joi.ref('name'))`: when description is absent/empty, default it to the name. Shared across kinds, so it reads the two fields by json name; attach with `.CustomTyped(base.DescriptionDefaultsToName)` on a resource's ValidationRule.

func DescriptionRule

func DescriptionRule() *validate.Rule

DescriptionRule ports description: Joi.string().trim().max(250).allow(”).

func DomainIsValid

func DomainIsValid(domain string, minSegments int) bool

DomainIsValid ports @hapi/address analyzeDomain (the no-tlds path): the shared predicate behind Joi's string.domain and string.hostname. minSegments is Joi's minDomainSegments (2 by default, 1 for hostname()).

func ErrorAtKey

func ErrorAtKey(h *validate.Helper, key, typ, format string, args ...any) *validate.Error

ErrorAtKey anchors an error at a CHILD key of the object a container custom runs on, for the Joi error types whose context carries no `value` (any.required, any.unknown). Helper.ErrorAt always stamps one, so the stamp is dropped here — without this, a hand-raised `"provider" is required` either blamed the whole object (path []) or carried a context key Joi does not emit.

func ExpandImageLink(value, org, gvc string) (string, error)

ExpandImageLink ports base.ts:199-238 ImageLink.custom (the coercion half). A literal image (no leading "/") passes through unchanged; a link expands like a LocalLink but only workload/identity are gvc-scoped for images.

func ExpandLocalLink(value, org, gvc string) (string, error)

ExpandLocalLink ports base.ts:152-195 LocalLink.custom: lowercase-check, then route the `//kind/name` link to org- or gvc-expansion (gvc-scoped kinds need the request gvc), passing through internal + already-absolute same-org links.

func ExpandOrgLocalLink(link, org string) string

ExpandOrgLocalLink ports base.ts expandOrgLocalLink: a `//`-prefixed link is rewritten under the org; an absolute link passes through.

func GetPart

func GetPart(href string, part int) string

func HostnameCustom

func HostnameCustom(value any, h *validate.Helper) (any, error)

HostnameCustom is HostnameRule's check, exported for the leaf types that chain a second custom after it (orgLogging's EsAmazonHost).

func HostnameRule

func HostnameRule() *validate.Rule

HostnameRule ports Joi.string().hostname(): a domain with at least one segment, or an IP literal. The error is Joi's `string.hostname`, quoting the LABEL.

func IPRule

func IPRule(versions []string, cidr string) *validate.Rule

IPRule ports Joi.string().ip({version, cidr}). versions may be empty (Joi's "all versions" default, which reports string.ip rather than string.ipVersion); cidr is "optional" (Joi's default) | "required" | "forbidden".

The error is Joi's, down to the context: string.ipVersion carries {cidr, version} and string.ip carries {cidr}; the label — not the value — is what the message quotes, so the caller can see WHICH field is wrong.

func ImageLinkRule

func ImageLinkRule() *validate.Rule

ImageLinkRule ports ImageLink = Joi.string().trim().custom(expand).custom(kind).

func IsInternalLink(v string) bool

IsInternalLink reports a cpln://internal/<alias> link.

func IsValidKind

func IsValidKind(s string) bool

IsValidKind reports whether s is one of the Kind enum values (base.ts:252 Kind.valid). Exported so callers can validate a kind against the FULL enum — e.g. /admin/org/-addPolicy, which accepts any Kind (bb.Kind.validate), not only the subset a normal org bootstrap seeds builtin policies for.

func JSString

func JSString(v any) string

JSString is `${v}` — JavaScript's ToString:

  • nil -> "null" (an undefined value renders as "undefined"; callers that distinguish the two pass JSUndefined explicitly)
  • bool -> "true" / "false"
  • number -> the shortest round-tripping form ("1", "1.5", "1e+21")
  • string -> itself
  • array/slice -> Array.prototype.toString: elements joined by "," with null/undefined rendering as the empty string (recursively)
  • anything else -> "[object Object]"

func KindsJSON

func KindsJSON(kinds []string) string

KindsJSON renders the kind list as toKind does for its error message.

func LastPart

func LastPart(href string) string

func LinkKindOK

func LinkKindOK(value string, kinds []string, org, gvc string) bool

LinkKindOK ports base.ts:80 toKind for an ALREADY-expanded (absolute or internal) link: valid if it points at one of the listed kinds in the same org/gvc.

func LinkRule

func LinkRule() *validate.Rule

LinkRule ports Link = Joi.object({rel: required trim, href: required trim}).

func LinksRule

func LinksRule() *validate.Rule

LinksRule ports Links = Joi.array().items(Link).

func LocalLinkRule

func LocalLinkRule() *validate.Rule

LocalLinkRule ports LocalLink = Joi.string().trim().regex(...).custom(expand). Expansion + the lowercase check delegate to linkalgebra.go.

func LocalLinkShapeRule

func LocalLinkShapeRule() *validate.Rule

LocalLinkShapeRule is the SHAPE half of LocalLinkRule — the trim + pattern, without the expansion custom. The central pre-schema link pass (data-service links.go) uses it so a value that is not link-shaped answers with Joi's `string.pattern.base`, as it does in TS where expansion happens INSIDE the schema and so never sees a value the pattern already rejected.

func MarshalExtras

func MarshalExtras(v any, extras Extras) ([]byte, error)

MarshalExtras encodes v (which MUST be a defined-type alias of the real struct, so this does not recurse through its MarshalJSON) and splices the extras back in. A named property always wins over an extra of the same name.

func MemoryToMiB

func MemoryToMiB(memory string) float64

MemoryToMiB ports convertMemoryStringToNumber, which TS keeps three copies of (workload.ts, volumeSet.ts, nodelibs/misc resources.ts) — here it is one.

func RegexRule

func RegexRule() *validate.Rule

RegexRule ports Regex = Joi.string().custom(RE2-compile-check).

func ToKind

func ToKind(kinds ...string) validate.CustomFn

ToKind ports base.ts toKind(...) as a .custom() to append to a LocalLink/ ImageLink rule. It kind-checks the already-expanded link via linkalgebra.go.

func UnmarshalExtras

func UnmarshalExtras(b []byte, v any, extras *Extras) error

UnmarshalExtras decodes into v (a pointer to the alias) and collects every property the struct does not name into *extras.

Types

type ApiError

type ApiError struct {
	Status  *float64 `json:"status,omitzero"`
	Message string   `json:"message,omitzero"`
	Code    string   `json:"code,omitzero"`
	Details any      `json:"details,omitzero"`
	Id      string   `json:"id,omitzero"`
}

type Base

type Base struct {
	Id           string   `json:"id,omitzero"`
	Name         Name     `json:"name,omitzero"`
	Kind         Kind     `json:"kind,omitzero"`
	Version      *float64 `json:"version,omitzero"`
	Description  string   `json:"description,omitzero"`
	Tags         BaseTags `json:"tags,omitzero"`
	Created      string   `json:"created,omitzero"`
	LastModified string   `json:"lastModified,omitzero"`
	Links        Links    `json:"links,omitzero"`
}

func (Base) ValidationRule

func (Base) ValidationRule() *validate.Rule

ValidationRule makes the canonical Base type self-validating.

type BaseTags

type BaseTags map[string]any

type CloudProvider

type CloudProvider string
const (
	CloudProviderAws   CloudProvider = "aws"
	CloudProviderGcp   CloudProvider = "gcp"
	CloudProviderAzure CloudProvider = "azure"
	CloudProviderNgs   CloudProvider = "ngs"
)

func (CloudProvider) ValidationRule

func (CloudProvider) ValidationRule() *validate.Rule

ValidationRule ports CloudProvider = Joi.string().valid('aws','gcp','azure','ngs').

type Extras

type Extras map[string]any

Extras holds the unnamed properties of an `unknown(true)` object.

func (Extras) ExtrasMarker

func (Extras) ExtrasMarker()

ExtrasMarker tells the validate engine's decoder that allowed unknown keys of the enclosing struct belong here.

type GenericList

type GenericList[T any] struct {
	Kind     ListKind     `json:"kind,omitzero"`
	ItemKind ListItemKind `json:"itemKind,omitzero"`
	Items    []T          `json:"items,omitzero"`
	Links    []Link       `json:"links,omitzero"`
}
type ImageLink string

func (ImageLink) ValidationRule

func (ImageLink) ValidationRule() *validate.Rule

ValidationRule makes the canonical ImageLink type self-validating.

type Kind

type Kind string
const (
	KindOrg                  Kind = "org"
	KindCloudaccount         Kind = "cloudaccount"
	KindPolicy               Kind = "policy"
	KindUser                 Kind = "user"
	KindGroup                Kind = "group"
	KindResource             Kind = "resource"
	KindTask                 Kind = "task"
	KindPermissions          Kind = "permissions"
	KindServiceaccount       Kind = "serviceaccount"
	KindSecret               Kind = "secret"
	KindLocation             Kind = "location"
	KindGvc                  Kind = "gvc"
	KindWorkload             Kind = "workload"
	KindQuota                Kind = "quota"
	KindIdentity             Kind = "identity"
	KindDeployment           Kind = "deployment"
	KindEvent                Kind = "event"
	KindDomain               Kind = "domain"
	KindImage                Kind = "image"
	KindIpset                Kind = "ipset"
	KindResourcepolicy       Kind = "resourcepolicy"
	KindAgent                Kind = "agent"
	KindAccessreport         Kind = "accessreport"
	KindPolicymembership     Kind = "policymembership"
	KindDbcluster            Kind = "dbcluster"
	KindAuditctx             Kind = "auditctx"
	KindMemcachecluster      Kind = "memcachecluster"
	KindSpicedbcluster       Kind = "spicedbcluster"
	KindTenant               Kind = "tenant"
	KindMk8S                 Kind = "mk8s"
	KindCommand              Kind = "command"
	KindImagesummary         Kind = "imagesummary"
	KindVolumeset            Kind = "volumeset"
	KindSandboximage         Kind = "sandboximage"
	KindCertificategenerator Kind = "certificategenerator"
)

func (Kind) ValidationRule

func (Kind) ValidationRule() *validate.Rule

ValidationRule ports Kind = Joi.string().valid(...).

type Link struct {
	Rel  string `json:"rel"`
	Href string `json:"href"`
}

func (Link) ValidationRule

func (Link) ValidationRule() *validate.Rule

ValidationRule makes the canonical Link type self-validating.

type Links []Link

func (Links) FindHref

func (l Links) FindHref(rel string) string

func (Links) Gvc

func (l Links) Gvc() string

func (Links) Org

func (l Links) Org() string

func (Links) ValidationRule

func (Links) ValidationRule() *validate.Rule

ValidationRule makes the canonical Links type self-validating.

type List

type List struct {
	Kind     ListKind     `json:"kind,omitzero"`
	ItemKind ListItemKind `json:"itemKind,omitzero"`
	Items    []any        `json:"items"`
	Links    []Link       `json:"links"`
}

type ListItemKind

type ListItemKind string
const (
	ListItemKindOrg                  ListItemKind = "org"
	ListItemKindCloudaccount         ListItemKind = "cloudaccount"
	ListItemKindPolicy               ListItemKind = "policy"
	ListItemKindUser                 ListItemKind = "user"
	ListItemKindGroup                ListItemKind = "group"
	ListItemKindResource             ListItemKind = "resource"
	ListItemKindTask                 ListItemKind = "task"
	ListItemKindPermissions          ListItemKind = "permissions"
	ListItemKindServiceaccount       ListItemKind = "serviceaccount"
	ListItemKindSecret               ListItemKind = "secret"
	ListItemKindLocation             ListItemKind = "location"
	ListItemKindGvc                  ListItemKind = "gvc"
	ListItemKindWorkload             ListItemKind = "workload"
	ListItemKindQuota                ListItemKind = "quota"
	ListItemKindIdentity             ListItemKind = "identity"
	ListItemKindDeployment           ListItemKind = "deployment"
	ListItemKindEvent                ListItemKind = "event"
	ListItemKindAccount              ListItemKind = "account"
	ListItemKindDomain               ListItemKind = "domain"
	ListItemKindImage                ListItemKind = "image"
	ListItemKindIpset                ListItemKind = "ipset"
	ListItemKindResourcepolicy       ListItemKind = "resourcepolicy"
	ListItemKindAccessreport         ListItemKind = "accessreport"
	ListItemKindAgent                ListItemKind = "agent"
	ListItemKindAuditctx             ListItemKind = "auditctx"
	ListItemKindDbcluster            ListItemKind = "dbcluster"
	ListItemKindMemcachecluster      ListItemKind = "memcachecluster"
	ListItemKindSpicedbcluster       ListItemKind = "spicedbcluster"
	ListItemKindTenant               ListItemKind = "tenant"
	ListItemKindMk8S                 ListItemKind = "mk8s"
	ListItemKindCommand              ListItemKind = "command"
	ListItemKindPolicymembership     ListItemKind = "policymembership"
	ListItemKindPrimitive            ListItemKind = "primitive"
	ListItemKindForeign              ListItemKind = "foreign"
	ListItemKindLink                 ListItemKind = "link"
	ListItemKindImagesummary         ListItemKind = "imagesummary"
	ListItemKindVolumeset            ListItemKind = "volumeset"
	ListItemKindSandboximage         ListItemKind = "sandboximage"
	ListItemKindCertificategenerator ListItemKind = "certificategenerator"
)

type ListKind

type ListKind string
const (
	ListKindList ListKind = "list"
)
type LocalLink string

func (LocalLink) ValidationRule

func (LocalLink) ValidationRule() *validate.Rule

ValidationRule makes the canonical LocalLink type self-validating.

type MultiZoneOptions

type MultiZoneOptions struct {
	Enabled *bool `json:"enabled,omitzero"`
}

type Name

type Name string

func (Name) ValidationRule

func (Name) ValidationRule() *validate.Rule

ValidationRule ports Name = Joi.string().regex(...).meta({unmodifiable}).max(64).

type Regex

type Regex string

func (Regex) ValidationRule

func (Regex) ValidationRule() *validate.Rule

ValidationRule makes the canonical Regex type self-validating.

type Tags

type Tags map[string]any

func (Tags) ValidationRule

func (Tags) ValidationRule() *validate.Rule

ValidationRule ports Tags = Joi.object().pattern(Joi.string(), Joi.any()).custom(...).

Jump to

Keyboard shortcuts

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