runtime

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: Apache-2.0 Imports: 15 Imported by: 70

Documentation

Index

Constants

View Source
const (
	// IdentityAttributeType     is the key for the type attribute in an identity.
	// It is used to identity the type of a resource and is standardized to always be empty or a parseable Type
	// See TypeFromString for more information.
	IdentityAttributeType = "type"
	// IdentityAttributeHostname is the key for the hostname attribute in an identity.
	// It is used to identity the hostname of a target system (e.g. a registry server).
	IdentityAttributeHostname = "hostname"
	// IdentityAttributeScheme is the key for the scheme attribute in an identity.
	// It is used to identity the scheme of a target system (e.g. http, https, etc.).
	IdentityAttributeScheme = "scheme"
	// IdentityAttributePath is the key for the path attribute in an identity.
	// It is used to identity any potential sub-path of a target system (e.g. /v1/),
	// which is used to identity the API version of a target system.
	// Alternatively, for local systems it can be interpreted as a local path.
	IdentityAttributePath = "path"
	// IdentityAttributePort is the key for the port attribute in an identity.
	// It is used to identity the port of a target system (e.g. 8080).
	IdentityAttributePort = "port"
)

Variables

This section is empty.

Functions

func DeepCopyJSON

func DeepCopyJSON(x map[string]interface{}) map[string]interface{}

DeepCopyJSON deep copies the passed value, assuming it is a valid JSON representation i.e. only contains types produced by json.Unmarshal() and also int64. bool, int64, float64, string, []interface{}, map[string]interface{}, json.Number and nil

func DeepCopyJSONValue

func DeepCopyJSONValue(x interface{}) interface{}

DeepCopyJSONValue deep copies the passed value, assuming it is a valid JSON representation i.e. only contains types produced by json.Unmarshal() and also int64. bool, int64, float64, string, []interface{}, map[string]interface{}, json.Number and nil

func GenerateJSONSchemaForType

func GenerateJSONSchemaForType(obj Typed) ([]byte, error)

GenerateJSONSchemaForType takes a Type and uses reflection to generate a JSON Schema representation for it. It will also use the correct type representation as we don't marshal the type in object format.

func Get

func Get[T any](u *Unstructured, key string) (T, bool)

func IdentityEqual

func IdentityEqual(a Identity, b Identity) bool

IdentityEqual is an equality IdentityMatchingChainFn. see Identity.Equal for more information

func IdentityMatchesPath

func IdentityMatchesPath(i, o Identity) bool

IdentityMatchesPath returns true if the identity a matches the subpath of the identity b. If the path attribute is not set in either identity, it returns true. If the path attribute is set in both identities, it returns true if the path attribute of b contains the path attribute of a. For more information, check path.Match. IdentityMatchesPath deletes the path attribute from both identities, because it is expected that it is used in a chain with Identity.Match and the authority decision of the path attribute.

see IdentityMatchingChainFn and Identity.Match for more information.

func IdentitySubset

func IdentitySubset(sub Identity, base Identity) bool

IdentitySubset is a ChainableIdentityMatcher that checks if the identity sub is a subset of the identity base. It is useful to check if an identity is a subset of another identity, and thus can be considered an IdentityEqual matcher on a subset of the identity.

Note that giving an empty subset will always return true, as an empty identity is a subset of any identity.

func IsTypeAlreadyRegisteredError added in v0.0.2

func IsTypeAlreadyRegisteredError(err error) bool

IsTypeAlreadyRegisteredError checks if the error is of type TypeAlreadyRegisteredError.

func ParseURLAndAllowNoScheme

func ParseURLAndAllowNoScheme(urlToParse string) (*url.URL, error)

ParseURLAndAllowNoScheme parses the provided URL string into a URL struct. it is a special case for url.Parse that allows URLs without a scheme by temporarily inserting a dummy scheme while parsing.

Types

type AndMatcher

type AndMatcher struct {
	Matchers []ChainableIdentityMatcher
}

AndMatcher is a matcher that matches if all provided matchers match.

func (*AndMatcher) Match

func (a *AndMatcher) Match(i, o Identity) bool

Match returns true if all matchers match.

type ChainableIdentityMatcher

type ChainableIdentityMatcher interface {
	Match(Identity, Identity) bool
}

func MatchAll

MatchAll is a convenience function that creates an AndMatcher that matches all provided matchers. In other words, it returns true if all given ChainableIdentityMatcher.Match return true.

type Identity

type Identity map[string]string

Identity is a map that represents a set of attributes that uniquely identity arbitrary resources. It is used in various places in Open Component Model to uniquely identity objects such as resources or components. +k8s:deepcopy-gen:interfaces=ocm.software/open-component-model/bindings/go/runtime.Typed +k8s:deepcopy-gen=true

func ParseIdentity

func ParseIdentity(s string) (Identity, error)

ParseIdentity parses a string into an Identity, using the format "key=value,key2=value2". ParseIdentity is able to parse all Identities returned from Identity.String.

func ParseURLToIdentity

func ParseURLToIdentity(url string) (Identity, error)

ParseURLToIdentity attempts parses the provided URL string into an Identity. Incorporated Attributes are - IdentityAttributeScheme - IdentityAttributePort - IdentityAttributeHostname - IdentityAttributePath

func (Identity) CanonicalHashV1

func (i Identity) CanonicalHashV1() uint64

CanonicalHashV1 is a canonicalization of an identity that can be used to uniquely identity it. it is backed by a FNV hash that is stabilized through the order of the keys in order as defined by slices.Sorted. The hash is not cryptographically secure and should not be used for security purposes. It is only used to identify the identity in a stable way.

func (Identity) Clone

func (i Identity) Clone() Identity

Clone creates a deep copy of the identity.

func (Identity) DeepCopy

func (in Identity) DeepCopy() Identity

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Identity.

func (Identity) DeepCopyInto

func (in Identity) DeepCopyInto(out *Identity)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (Identity) DeepCopyTyped

func (i Identity) DeepCopyTyped() Typed

func (Identity) Equal

func (i Identity) Equal(o Identity) bool

Equal is a function that checks if two identities are equal. It compares the keys and values of both identities. It does not use CanonicalHashV1 to compare the identities, because a plain map comparison is sufficient for equality of 2 identities.

func (Identity) GetType

func (i Identity) GetType() Type

GetType extracts the type or panics if failing. It should only be used if the type is known to be present and valid. For more information, check ParseType.

func (Identity) Match

func (i Identity) Match(o Identity, matchers ...ChainableIdentityMatcher) bool

Match returns true if the identity a matches the identity b. It uses the provided Matchers to determine the match. If no Matchers are provided, it uses IdentityMatchesPath and IdentityEqual in order. If any matcher returns false, it returns false.

func (Identity) ParseType

func (i Identity) ParseType() (Type, error)

ParseType attempts to parse the type from the identity. It returns an error if the type is not present or invalid.

func (Identity) SetType

func (i Identity) SetType(typ Type)

SetType sets the type of the identity.

func (Identity) String

func (i Identity) String() string

String returns a stable fmt.Stringer "native" format representation of the identity. It can be used for stable string comparison. For generation of unique identities as hashes use CanonicalHashV1 instead.

type IdentityMatchingChainFn

type IdentityMatchingChainFn func(Identity, Identity) bool

IdentityMatchingChainFn is a function that takes two identities and returns if they match. It is expected that the function can modify the identities in place. If a comparison is absolute, the function can choose to delete attributes. This has an effect of following ChainableIdentityMatcher's if used in a chain with Identity.Match.

func (IdentityMatchingChainFn) Match

func (f IdentityMatchingChainFn) Match(a, b Identity) bool

Match delegates to the IdentityMatchingChainFn.

type Raw

type Raw struct {
	Type `json:"type"`
	Data []byte `json:"-"`
}

Raw is used to hold extensions in external versions.

To use this, make a field which has RawExtension as its type in your external, versioned struct, and Typed in your internal struct. You also need to register your various plugin types.

+k8s:deepcopy-gen:interfaces=ocm.software/open-component-model/bindings/go/runtime.Typed +k8s:deepcopy-gen=true

func (*Raw) DeepCopy

func (in *Raw) DeepCopy() *Raw

DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Raw.

func (*Raw) DeepCopyInto

func (in *Raw) DeepCopyInto(out *Raw)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*Raw) DeepCopyTyped

func (in *Raw) DeepCopyTyped() Typed

DeepCopyTyped is an autogenerated deepcopy function, copying the receiver, creating a new Typed.

func (*Raw) GetType

func (u *Raw) GetType() Type

func (*Raw) MarshalJSON

func (u *Raw) MarshalJSON() ([]byte, error)

func (*Raw) SetType

func (u *Raw) SetType(v Type)

func (*Raw) String

func (u *Raw) String() string

func (*Raw) UnmarshalJSON

func (u *Raw) UnmarshalJSON(data []byte) error

type Scheme

type Scheme struct {
	// contains filtered or unexported fields
}

Scheme is a dynamic registry for Typed types.

func NewScheme

func NewScheme(opts ...SchemeOption) *Scheme

NewScheme creates a new registry.

func (*Scheme) Clone

func (r *Scheme) Clone() *Scheme

func (*Scheme) Convert

func (r *Scheme) Convert(from Typed, into Typed) error

Convert transforms one Typed object into another. Both 'from' and 'into' must be non-nil pointers.

Special Cases:

  • Raw → Raw: performs a deep copy of the underlying []byte data.
  • Raw → Typed: unmarshals Raw.Data JSON via json.Unmarshal into the Typed object (if Typed.GetType is registered).
  • Typed → Raw: marshals the Typed with json.Marshal, applies canonicalization, and stores the result in Raw.Data. (See Raw.UnmarshalJSON for equivalent behavior)
  • Typed → Typed: performs a deep copy using Typed.DeepCopyTyped, with reflection-based assignment.

Errors are returned if:

  • Either argument is nil.
  • A type is not registered in the Scheme (for Raw conversions).
  • A reflection-based assignment fails due to type mismatch.

func (*Scheme) Decode

func (r *Scheme) Decode(data io.Reader, into Typed) error

func (*Scheme) DefaultType

func (r *Scheme) DefaultType(typed Typed) (updated bool, err error)

DefaultType sets the type of the Typed object to its registered type. It returns true if the type was updated or an error in case an unknown type was found but unknown types are forbidden.

func (*Scheme) GetTypes added in v0.0.2

func (r *Scheme) GetTypes() map[Type][]Type

GetTypes returns a map of all registered types. The keys are the default types, and the values are slices containing all aliases for that type. If a type has no aliases, it will have an empty slice as its value. The slices of aliases are always sorted for consistent ordering.

func (*Scheme) IsRegistered

func (r *Scheme) IsRegistered(typ Type) bool

func (*Scheme) MustRegister

func (r *Scheme) MustRegister(prototype Typed, version string)

func (*Scheme) MustRegisterWithAlias

func (r *Scheme) MustRegisterWithAlias(prototype Typed, types ...Type)

func (*Scheme) MustTypeForPrototype

func (r *Scheme) MustTypeForPrototype(prototype Typed) Type

func (*Scheme) NewObject

func (r *Scheme) NewObject(typ Type) (Typed, error)

NewObject creates a new instance of runtime.Typed.

func (*Scheme) RegisterScheme added in v0.0.2

func (r *Scheme) RegisterScheme(scheme *Scheme) error

RegisterScheme adds all types from the given scheme to the given scheme, and fails if any of the types already exist.

func (*Scheme) RegisterSchemeType added in v0.0.2

func (r *Scheme) RegisterSchemeType(scheme *Scheme, typ Type) error

RegisterSchemeType adds a single type from the given scheme to the current scheme

func (*Scheme) RegisterSchemes added in v0.0.2

func (r *Scheme) RegisterSchemes(schemes ...*Scheme) error

RegisterSchemes calls RegisterScheme for each scheme in the list, registering all types from each scheme. Conflicts between Scheme's passed will result in an error on the first conflict found. Registration might still have occurred for some types before the error is returned.

func (*Scheme) RegisterWithAlias

func (r *Scheme) RegisterWithAlias(prototype Typed, types ...Type) error

RegisterWithAlias registers a new type with the registry. The first type is the default type and all other types are aliases. Note that if Scheme.RegisterWithAlias or Scheme.MustRegister were called before, even the first type will be counted as an alias.

func (*Scheme) TypeForPrototype

func (r *Scheme) TypeForPrototype(prototype any) (Type, error)

type SchemeOption

type SchemeOption func(*Scheme)

func WithAllowUnknown

func WithAllowUnknown() SchemeOption

WithAllowUnknown allows unknown types to be created.

type Type

type Type struct {
	Version string
	Name    string
}

Type represents a structured type with an optional version and a name. It is used to identify the type of an object in a versioned API. A Version is a specific iteration of the type, and Name is the name of the type.

func NewUnversionedType

func NewUnversionedType(name string) Type

NewUnversionedType creates a new Type instance without a version.

func NewVersionedType

func NewVersionedType(name, version string) Type

NewVersionedType creates a new Type instance with a version.

func TypeFromString

func TypeFromString(typ string) (Type, error)

TypeFromString parses a type string in the formats: - "name" (unversioned) - "name/version" (versioned)

func (Type) Equal

func (t Type) Equal(other Type) bool

Equal checks if two Types are the same.

func (Type) GetName

func (t Type) GetName() string

GetName returns the name of the type.

func (Type) GetVersion

func (t Type) GetVersion() string

GetVersion returns the version of the type.

func (Type) HasVersion

func (t Type) HasVersion() bool

HasVersion checks if the type has a version associated with it.

func (Type) IsEmpty

func (t Type) IsEmpty() bool

IsEmpty checks if the Type is empty (no version or name).

func (Type) MarshalJSON

func (t Type) MarshalJSON() ([]byte, error)

MarshalJSON converts Type to a JSON string.

func (Type) String

func (t Type) String() string

String returns the formatted Type string. - Unversioned: "name" - Versioned: "name/version"

func (*Type) UnmarshalJSON

func (t *Type) UnmarshalJSON(data []byte) error

UnmarshalJSON parses a JSON string into Type.

type TypeAlreadyRegisteredError added in v0.0.2

type TypeAlreadyRegisteredError Type

TypeAlreadyRegisteredError is returned when a type is already registered in the scheme. It contains the type that was attempted to be registered.

Use IsTypeAlreadyRegisteredError to check for this error type.

func (TypeAlreadyRegisteredError) Error added in v0.0.2

type Typed

type Typed interface {
	// GetType returns the object's type
	GetType() Type
	SetType(Type)
	DeepCopyTyped() Typed
}

Typed is any object that is defined by a type that is versioned.

type Unstructured

type Unstructured struct {
	Data map[string]interface{}
}

+k8s:deepcopy-gen:interfaces=ocm.software/open-component-model/bindings/go/runtime.Typed +k8s:deepcopy-gen=true

func NewUnstructured

func NewUnstructured() Unstructured

func (*Unstructured) DeepCopy

func (u *Unstructured) DeepCopy() *Unstructured

func (*Unstructured) DeepCopyInto

func (in *Unstructured) DeepCopyInto(out *Unstructured)

DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.

func (*Unstructured) DeepCopyTyped

func (in *Unstructured) DeepCopyTyped() Typed

DeepCopyTyped is an autogenerated deepcopy function, copying the receiver, creating a new Typed.

func (*Unstructured) GetType

func (u *Unstructured) GetType() Type

func (*Unstructured) MarshalJSON

func (u *Unstructured) MarshalJSON() ([]byte, error)

func (*Unstructured) SetType

func (u *Unstructured) SetType(v Type)

func (*Unstructured) UnmarshalJSON

func (u *Unstructured) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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