operations

package
v0.32.0-rc1 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FlattenProperties

func FlattenProperties(state map[string]any) map[string]any

FlattenProperties takes a string-keyed map, which may contain nested objects, and recursively flattens it into a single-level map. For example:

"NumShards": 1
"ClusterEndpoint": {
  "Address": "test-address"
  "Port": 3000
}

Gets transformed to:

"NumShards": 1
"ClusterEndpoint/Address": "test-address"
"ClusterEndpoint/Port": 3000

func GeneratePatch

func GeneratePatch(currentState []byte, desiredState []byte, schema []byte) (jsondiff.Patch, error)

GeneratePatch takes in the current state, desired state and type schema of a resource and returns a JSON patch to update the current state to the desired state, taking into account read-only, create-only and conditional-create-only properties.

func ParsePropertyName

func ParsePropertyName(propertyIdentifier string) (string, error)

ParsePropertyName transforms a propertyIdentifer of the form /properties/<propertyName> to <propertyName>. It returns an error if the property identifier is not in the expected format.

func UnflattenProperties

func UnflattenProperties(state map[string]any) map[string]any

UnflattenProperties takes in a map of strings to any type and returns an object with the nested properties unflattened. For example:

"NumShards": 1
"ClusterEndpoint/Address": "test-address"
"ClusterEndpoint/Port": 3000

Gets transformed to:

"NumShards": 1
"ClusterEndpoint": {
  "Address": "test-address"
  "Port": 3000
}

Types

type ResourceTypeSchema

type ResourceTypeSchema struct {
	Properties                      map[string]any `json:"properties,omitempty"`
	ReadOnlyProperties              []string       `json:"readOnlyProperties,omitempty"`
	CreateOnlyProperties            []string       `json:"createOnlyProperties,omitempty"`
	ConditionalCreateOnlyProperties []string       `json:"conditionalCreateOnlyProperties,omitempty"`
	WriteOnlyProperties             []string       `json:"writeOnlyProperties,omitempty"`
}

Jump to

Keyboard shortcuts

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