ids

package
v1.19.0 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

README

ids

Nominal UUID types for the resource identifiers the region API owns.

Purpose

Provides distinct named types over uuid.UUID for every resource category the region service addresses through its public API:

Type Identifies
RegionID regions
IdentityID cloud identities
NetworkID networks
SecurityGroupID security groups
LoadBalancerID load balancers
VolumeID block storage volumes
ServerID servers
SSHCertificateAuthorityID SSH certificate authorities
FileStorageID file storage
ImageID images
FlavorID flavors

Each type is a distinct named type — not an alias — so the compiler prevents a NetworkID from being passed where a ServerID is expected, and so on across all types.

Each type implements encoding.TextUnmarshaler by delegating to uuid.UUID, so the oapi-codegen parameter binder validates UUID format at path-parameter binding time before any handler is reached. Non-UUID path values produce a 400 at the routing layer rather than propagating into business logic.

Scope

These types run from the router down to the provider layer — not the API layer alone. The region service mints UUIDs for its own CRD-backed resources (Region, Identity, Network, SecurityGroup, LoadBalancer, Volume, Server, SSHCertificateAuthority, FileStorage) and addresses provider-owned Image/Flavor resources by their provider-assigned UUIDs. They appear on:

  • the generated OpenAPI surface (path parameters and request/response body fields);
  • CRD spec fields that hold region-owned UUIDs — currently the Server CRD's FlavorID, Image.ID, SecurityGroups[].ID and Networks[].ID. Because the types are uuid.UUID-backed ([16]byte), each declaration carries +kubebuilder:validation:Type=string (and Format=uuid) so controller-gen emits a string schema rather than a byte array; the existing TextMarshaler handles the etcd round-trip, so no data migration is needed;
  • the provider interface for image operations (GetImage, DeleteImage, and the AvailableToOrganization/OwnedByOrganization query predicates). The other provider methods take whole CRD objects and so carry their typed IDs inside the object — no signature change needed.

Conversion back to a plain string happens only at genuine sinks: an external provider SDK call (gophercloud/OpenStack), a by-name Kubernetes lookup (GetRaw/ObjectKey), a label value, or a read-model/status field still string-typed by design (e.g. v1 ServerNetwork.Id, ServerSecurityGroup.Id). Resources recover their own and their owners' typed IDs fail-closed from names and labels via accessor methods on the CRD types (Network.NetworkID(), Server.RegionID(), *.OrganizationID()/OrganizationAndProjectID()).

Identifiers owned by other services — organizationId, projectId, userId — use the identity service's pkg/ids types, not these. Provider-internal identifiers exposed only through hidden APIs (vlanId, subnetId, routerId, serverGroupId) remain plain strings — they live in another system's namespace, not region's.

Conversion

Inward (string → typed ID): Use Parse* for untrusted or stored input (Kubernetes labels, resource names, request body fields read back from storage); it returns an error so a malformed value fails closed rather than panicking. The panic-on-error MustParse* constructors live in the test-only idstest package — not here — so they cannot be reached on a request path; use them only with known-good literals in tests. Path parameters are validated by the oapi-codegen binder via UnmarshalText before the handler runs.

Outward (typed ID → string): Call .String() to produce the canonical hyphenated UUID string — only at the sinks above (external SDK calls, by-name Kubernetes lookups, label values, string read-model fields, log messages).

VolumeID follows the same UUID v4 identity model as the other Region resource IDs that do not have a concrete natural uniqueness key. Volume display names are metadata, not part of the stored identity model.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileStorageID

type FileStorageID uuid.UUID

FileStorageID is a UUID-backed identifier for file storage. It is a distinct named type so the compiler prevents accidental interchange with any other ID type. UnmarshalText delegates to uuid.UUID, so the oapi-codegen runtime rejects non-UUID path parameter values before any handler is reached.

+kubebuilder:validation:Type=string +kubebuilder:validation:Format=uuid

func ParseFileStorageID

func ParseFileStorageID(s string) (FileStorageID, error)

ParseFileStorageID parses s as a UUID into a FileStorageID, returning an error if s is not a valid UUID.

func (FileStorageID) MarshalText

func (v FileStorageID) MarshalText() ([]byte, error)

func (FileStorageID) String

func (v FileStorageID) String() string

func (*FileStorageID) UnmarshalText

func (v *FileStorageID) UnmarshalText(b []byte) error

type FlavorID

type FlavorID uuid.UUID

FlavorID is a UUID-backed identifier for flavors. The platform addresses flavors by their provider-assigned UUID; it is a distinct named type so the compiler prevents accidental interchange with any other ID type. UnmarshalText delegates to uuid.UUID, so the oapi-codegen runtime rejects non-UUID path parameter values before any handler is reached.

+kubebuilder:validation:Type=string +kubebuilder:validation:Format=uuid

func ParseFlavorID

func ParseFlavorID(s string) (FlavorID, error)

ParseFlavorID parses s as a UUID into a FlavorID, returning an error if s is not a valid UUID.

func (FlavorID) MarshalText

func (v FlavorID) MarshalText() ([]byte, error)

func (FlavorID) String

func (v FlavorID) String() string

func (*FlavorID) UnmarshalText

func (v *FlavorID) UnmarshalText(b []byte) error

type IdentityID

type IdentityID uuid.UUID

IdentityID is a UUID-backed identifier for cloud identities. It is a distinct named type so the compiler prevents accidental interchange with any other ID type. UnmarshalText delegates to uuid.UUID, so the oapi-codegen runtime rejects non-UUID path parameter values before any handler is reached.

+kubebuilder:validation:Type=string +kubebuilder:validation:Format=uuid

func ParseIdentityID

func ParseIdentityID(s string) (IdentityID, error)

ParseIdentityID parses s as a UUID into an IdentityID, returning an error if s is not a valid UUID.

func (IdentityID) MarshalText

func (v IdentityID) MarshalText() ([]byte, error)

func (IdentityID) String

func (v IdentityID) String() string

func (*IdentityID) UnmarshalText

func (v *IdentityID) UnmarshalText(b []byte) error

type ImageID

type ImageID uuid.UUID

ImageID is a UUID-backed identifier for images. The platform addresses images by their provider-assigned UUID; it is a distinct named type so the compiler prevents accidental interchange with any other ID type. UnmarshalText delegates to uuid.UUID, so the oapi-codegen runtime rejects non-UUID path parameter values before any handler is reached.

+kubebuilder:validation:Type=string +kubebuilder:validation:Format=uuid

func ParseImageID

func ParseImageID(s string) (ImageID, error)

ParseImageID parses s as a UUID into an ImageID, returning an error if s is not a valid UUID.

func (ImageID) MarshalText

func (v ImageID) MarshalText() ([]byte, error)

func (ImageID) String

func (v ImageID) String() string

func (*ImageID) UnmarshalText

func (v *ImageID) UnmarshalText(b []byte) error

type LoadBalancerID

type LoadBalancerID uuid.UUID

LoadBalancerID is a UUID-backed identifier for load balancers. It is a distinct named type so the compiler prevents accidental interchange with any other ID type. UnmarshalText delegates to uuid.UUID, so the oapi-codegen runtime rejects non-UUID path parameter values before any handler is reached.

+kubebuilder:validation:Type=string +kubebuilder:validation:Format=uuid

func ParseLoadBalancerID

func ParseLoadBalancerID(s string) (LoadBalancerID, error)

ParseLoadBalancerID parses s as a UUID into a LoadBalancerID, returning an error if s is not a valid UUID.

func (LoadBalancerID) MarshalText

func (v LoadBalancerID) MarshalText() ([]byte, error)

func (LoadBalancerID) String

func (v LoadBalancerID) String() string

func (*LoadBalancerID) UnmarshalText

func (v *LoadBalancerID) UnmarshalText(b []byte) error

type NetworkID

type NetworkID uuid.UUID

NetworkID is a UUID-backed identifier for networks. It is a distinct named type so the compiler prevents accidental interchange with any other ID type. UnmarshalText delegates to uuid.UUID, so the oapi-codegen runtime rejects non-UUID path parameter values before any handler is reached.

+kubebuilder:validation:Type=string +kubebuilder:validation:Format=uuid

func ParseNetworkID

func ParseNetworkID(s string) (NetworkID, error)

ParseNetworkID parses s as a UUID into a NetworkID, returning an error if s is not a valid UUID.

func (NetworkID) MarshalText

func (v NetworkID) MarshalText() ([]byte, error)

func (NetworkID) String

func (v NetworkID) String() string

func (*NetworkID) UnmarshalText

func (v *NetworkID) UnmarshalText(b []byte) error

type RegionID

type RegionID uuid.UUID

RegionID is a UUID-backed identifier for regions. It is a distinct named type so the compiler prevents accidental interchange with any other ID type. UnmarshalText delegates to uuid.UUID, so the oapi-codegen runtime rejects non-UUID path parameter values before any handler is reached.

+kubebuilder:validation:Type=string +kubebuilder:validation:Format=uuid

func ParseRegionID

func ParseRegionID(s string) (RegionID, error)

ParseRegionID parses s as a UUID into a RegionID, returning an error if s is not a valid UUID.

func (RegionID) MarshalText

func (v RegionID) MarshalText() ([]byte, error)

func (RegionID) String

func (v RegionID) String() string

func (*RegionID) UnmarshalText

func (v *RegionID) UnmarshalText(b []byte) error

type SSHCertificateAuthorityID

type SSHCertificateAuthorityID uuid.UUID

SSHCertificateAuthorityID is a UUID-backed identifier for SSH certificate authorities. It is a distinct named type so the compiler prevents accidental interchange with any other ID type. UnmarshalText delegates to uuid.UUID, so the oapi-codegen runtime rejects non-UUID path parameter values before any handler is reached.

+kubebuilder:validation:Type=string +kubebuilder:validation:Format=uuid

func ParseSSHCertificateAuthorityID

func ParseSSHCertificateAuthorityID(s string) (SSHCertificateAuthorityID, error)

ParseSSHCertificateAuthorityID parses s as a UUID into an SSHCertificateAuthorityID, returning an error if s is not a valid UUID.

func (SSHCertificateAuthorityID) MarshalText

func (v SSHCertificateAuthorityID) MarshalText() ([]byte, error)

func (SSHCertificateAuthorityID) String

func (v SSHCertificateAuthorityID) String() string

func (*SSHCertificateAuthorityID) UnmarshalText

func (v *SSHCertificateAuthorityID) UnmarshalText(b []byte) error

type SecurityGroupID

type SecurityGroupID uuid.UUID

SecurityGroupID is a UUID-backed identifier for security groups. It is a distinct named type so the compiler prevents accidental interchange with any other ID type. UnmarshalText delegates to uuid.UUID, so the oapi-codegen runtime rejects non-UUID path parameter values before any handler is reached.

+kubebuilder:validation:Type=string +kubebuilder:validation:Format=uuid

func ParseSecurityGroupID

func ParseSecurityGroupID(s string) (SecurityGroupID, error)

ParseSecurityGroupID parses s as a UUID into a SecurityGroupID, returning an error if s is not a valid UUID.

func (SecurityGroupID) MarshalText

func (v SecurityGroupID) MarshalText() ([]byte, error)

func (SecurityGroupID) String

func (v SecurityGroupID) String() string

func (*SecurityGroupID) UnmarshalText

func (v *SecurityGroupID) UnmarshalText(b []byte) error

type ServerID

type ServerID uuid.UUID

ServerID is a UUID-backed identifier for servers. It is a distinct named type so the compiler prevents accidental interchange with any other ID type. UnmarshalText delegates to uuid.UUID, so the oapi-codegen runtime rejects non-UUID path parameter values before any handler is reached.

+kubebuilder:validation:Type=string +kubebuilder:validation:Format=uuid

func ParseServerID

func ParseServerID(s string) (ServerID, error)

ParseServerID parses s as a UUID into a ServerID, returning an error if s is not a valid UUID.

func (ServerID) MarshalText

func (v ServerID) MarshalText() ([]byte, error)

func (ServerID) String

func (v ServerID) String() string

func (*ServerID) UnmarshalText

func (v *ServerID) UnmarshalText(b []byte) error

type VolumeID added in v1.19.0

type VolumeID uuid.UUID

VolumeID is a UUID-backed identifier for block storage volumes. It is a distinct named type so the compiler prevents accidental interchange with any other ID type. UnmarshalText delegates to uuid.UUID, so the oapi-codegen runtime rejects non-UUID path parameter values before any handler is reached.

+kubebuilder:validation:Type=string +kubebuilder:validation:Format=uuid

func ParseVolumeID added in v1.19.0

func ParseVolumeID(s string) (VolumeID, error)

ParseVolumeID parses s as a UUID into a VolumeID, returning an error if s is not a valid UUID.

func (VolumeID) MarshalText added in v1.19.0

func (v VolumeID) MarshalText() ([]byte, error)

func (VolumeID) String added in v1.19.0

func (v VolumeID) String() string

func (*VolumeID) UnmarshalText added in v1.19.0

func (v *VolumeID) UnmarshalText(b []byte) error

Directories

Path Synopsis
Package idstest provides panic-on-error constructors for the typed resource identifiers in pkg/ids.
Package idstest provides panic-on-error constructors for the typed resource identifiers in pkg/ids.

Jump to

Keyboard shortcuts

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