privatestate

package
v1.3.4 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2023 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package privatestate contains the type used for handling private resource state data.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustMarshalToJson

func MustMarshalToJson(input map[string][]byte) []byte

MustMarshalToJson is for use in tests and panics if input cannot be marshalled to JSON.

func ValidateProviderDataKey

func ValidateProviderDataKey(ctx context.Context, key string) diag.Diagnostics

ValidateProviderDataKey determines whether the key supplied is allowed on the basis of any restrictions that are in place, such as key prefixes that are reserved for use with framework private state data.

Types

type Data

type Data struct {
	// Potential future usage:
	// Framework contains private state data for framework usage.
	Framework map[string][]byte

	// Provider contains private state data for provider usage.
	Provider *ProviderData
}

Data contains private state data for the framework and providers.

func EmptyData

func EmptyData(ctx context.Context) *Data

EmptyData creates an initialised but empty Data.

func NewData

func NewData(ctx context.Context, data []byte) (*Data, diag.Diagnostics)

NewData creates a new Data based on the given slice of bytes. It must be a JSON encoded slice of bytes, that is map[string][]byte.

func (*Data) Bytes

func (d *Data) Bytes(ctx context.Context) ([]byte, diag.Diagnostics)

Bytes returns a JSON encoded slice of bytes containing the merged framework and provider private state data.

type ProviderData

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

ProviderData contains private state data for provider usage.

func EmptyProviderData

func EmptyProviderData(ctx context.Context) *ProviderData

EmptyProviderData creates a ProviderData containing initialised but empty data.

func MustProviderData

func MustProviderData(ctx context.Context, data []byte) *ProviderData

MustProviderData is for use in tests and panics if the underlying call to NewProviderData returns diag.Diagnostics that contains any errors.

func NewProviderData

func NewProviderData(ctx context.Context, data []byte) (*ProviderData, diag.Diagnostics)

NewProviderData creates a new ProviderData based on the given slice of bytes. It must be a JSON encoded slice of bytes, that is map[string][]byte.

func (*ProviderData) Equal added in v0.17.0

func (d *ProviderData) Equal(o *ProviderData) bool

Equal returns true if the given ProviderData is exactly equivalent. The internal data is compared byte-for-byte, not accounting for semantic equivalency such as JSON whitespace or property reordering.

func (*ProviderData) GetKey

func (d *ProviderData) GetKey(ctx context.Context, key string) ([]byte, diag.Diagnostics)

GetKey returns the private state data associated with the given key.

If the key is reserved for framework usage, an error diagnostic is returned. If the key is valid, but private state data is not found, nil is returned.

The naming of keys only matters in context of a single resource, however care should be taken that any historical keys are not reused without accounting for older resource instances that may still have older data at the key.

func (*ProviderData) SetKey

func (d *ProviderData) SetKey(ctx context.Context, key string, value []byte) diag.Diagnostics

SetKey sets the private state data at the given key.

If the key is reserved for framework usage, an error diagnostic is returned. The data must be valid JSON and UTF-8 safe or an error diagnostic is returned.

The naming of keys only matters in context of a single resource, however care should be taken that any historical keys are not reused without accounting for older resource instances that may still have older data at the key.

Jump to

Keyboard shortcuts

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