Documentation
¶
Index ¶
- Constants
- func DeepCopyJSON(x map[string]interface{}) map[string]interface{}
- func DeepCopyJSONValue(x interface{}) interface{}
- func GenerateJSONSchemaForType(obj Typed) ([]byte, error)
- func Get[T any](u *Unstructured, key string) (T, bool)
- func IdentityEqual(a Identity, b Identity) bool
- func IdentityMatchesPath(i, o Identity) bool
- func IdentitySubset(sub Identity, base Identity) bool
- func IsTypeAlreadyRegisteredError(err error) bool
- func ParseURLAndAllowNoScheme(urlToParse string) (*url.URL, error)
- type AndMatcher
- type ChainableIdentityMatcher
- type Identity
- func (i Identity) CanonicalHashV1() uint64
- func (i Identity) Clone() Identity
- func (in Identity) DeepCopy() Identity
- func (in Identity) DeepCopyInto(out *Identity)
- func (i Identity) DeepCopyTyped() Typed
- func (i Identity) Equal(o Identity) bool
- func (i Identity) GetType() Type
- func (i Identity) Match(o Identity, matchers ...ChainableIdentityMatcher) bool
- func (i Identity) ParseType() (Type, error)
- func (i Identity) SetType(typ Type)
- func (i Identity) String() string
- type IdentityMatchingChainFn
- type Raw
- type Scheme
- func (r *Scheme) Clone() *Scheme
- func (r *Scheme) Convert(from Typed, into Typed) error
- func (r *Scheme) Decode(data io.Reader, into Typed) error
- func (r *Scheme) DefaultType(typed Typed) (updated bool, err error)
- func (r *Scheme) GetTypes() map[Type][]Type
- func (r *Scheme) IsRegistered(typ Type) bool
- func (r *Scheme) MustRegister(prototype Typed, version string)
- func (r *Scheme) MustRegisterWithAlias(prototype Typed, types ...Type)
- func (r *Scheme) MustTypeForPrototype(prototype Typed) Type
- func (r *Scheme) NewObject(typ Type) (Typed, error)
- func (r *Scheme) RegisterScheme(scheme *Scheme) error
- func (r *Scheme) RegisterSchemeType(scheme *Scheme, typ Type) error
- func (r *Scheme) RegisterSchemes(schemes ...*Scheme) error
- func (r *Scheme) RegisterWithAlias(prototype Typed, types ...Type) error
- func (r *Scheme) TypeForPrototype(prototype any) (Type, error)
- type SchemeOption
- type Type
- type TypeAlreadyRegisteredError
- type Typed
- type Unstructured
- func (u *Unstructured) DeepCopy() *Unstructured
- func (in *Unstructured) DeepCopyInto(out *Unstructured)
- func (in *Unstructured) DeepCopyTyped() Typed
- func (u *Unstructured) GetType() Type
- func (u *Unstructured) MarshalJSON() ([]byte, error)
- func (u *Unstructured) SetType(v Type)
- func (u *Unstructured) UnmarshalJSON(data []byte) error
Constants ¶
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 ¶
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 ¶
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 IdentityEqual ¶
IdentityEqual is an equality IdentityMatchingChainFn. see Identity.Equal for more information
func IdentityMatchesPath ¶
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 ¶
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
IsTypeAlreadyRegisteredError checks if the error is of type TypeAlreadyRegisteredError.
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 ¶
func MatchAll ¶
func MatchAll(matchers ...ChainableIdentityMatcher) ChainableIdentityMatcher
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 ¶
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 ¶
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 ¶
ParseURLToIdentity attempts parses the provided URL string into an Identity. Incorporated Attributes are - IdentityAttributeScheme - IdentityAttributePort - IdentityAttributeHostname - IdentityAttributePath
func (Identity) CanonicalHashV1 ¶
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) DeepCopy ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Identity.
func (Identity) DeepCopyInto ¶
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (Identity) DeepCopyTyped ¶
func (Identity) Equal ¶
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 ¶
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 ¶
ParseType attempts to parse the type from the identity. It returns an error if the type is not present or invalid.
type IdentityMatchingChainFn ¶
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 ¶
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 ¶
DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Raw.
func (*Raw) DeepCopyInto ¶
DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (*Raw) DeepCopyTyped ¶
DeepCopyTyped is an autogenerated deepcopy function, copying the receiver, creating a new Typed.
func (*Raw) MarshalJSON ¶
func (*Raw) UnmarshalJSON ¶
type Scheme ¶
type Scheme struct {
// contains filtered or unexported fields
}
Scheme is a dynamic registry for Typed types.
func (*Scheme) Convert ¶
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) DefaultType ¶
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
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 (*Scheme) MustRegister ¶
func (*Scheme) MustRegisterWithAlias ¶
func (*Scheme) MustTypeForPrototype ¶
func (*Scheme) RegisterScheme ¶ added in v0.0.2
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
RegisterSchemeType adds a single type from the given scheme to the current scheme
func (*Scheme) RegisterSchemes ¶ added in v0.0.2
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 ¶
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.
type SchemeOption ¶
type SchemeOption func(*Scheme)
func WithAllowUnknown ¶
func WithAllowUnknown() SchemeOption
WithAllowUnknown allows unknown types to be created.
type Type ¶
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 ¶
NewUnversionedType creates a new Type instance without a version.
func NewVersionedType ¶
NewVersionedType creates a new Type instance with a version.
func TypeFromString ¶
TypeFromString parses a type string in the formats: - "name" (unversioned) - "name/version" (versioned)
func (Type) GetVersion ¶
GetVersion returns the version of the type.
func (Type) HasVersion ¶
HasVersion checks if the type has a version associated with it.
func (Type) MarshalJSON ¶
MarshalJSON converts Type to a JSON string.
func (Type) String ¶
String returns the formatted Type string. - Unversioned: "name" - Versioned: "name/version"
func (*Type) UnmarshalJSON ¶
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
func (e TypeAlreadyRegisteredError) Error() string
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