frameworkfilter

package
v2.20.1 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: MPL-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EXACT     = "exact"
	SUBSTRING = "substring"
	REGEX     = "regex"
)

Variables

This section is empty.

Functions

func FilterTypeBool

func FilterTypeBool(value string) (any, error)

func FilterTypeInt

func FilterTypeInt(value string) (any, error)

func FilterTypeString

func FilterTypeString(value string) (any, error)

Types

type Config

type Config map[string]FilterAttribute

Config is the root configuration type for filter data sources.

func (Config) GenerateID

func (f Config) GenerateID(filters []FilterModel) (types.String, diag.Diagnostic)

GenerateID will generate a unique ID from the given filters.

func (Config) GetAndFilter

func (f Config) GetAndFilter(
	ctx context.Context,
	client *linodego.Client,
	filters []FilterModel,
	listFunc ListFunc,
	order types.String,
	orderBy types.String,
) ([]any, diag.Diagnostic)

GetAndFilter will run all filter operations given the parameters and return a list of API response objects.

func (Config) GetLatestCreated

func (f Config) GetLatestCreated(elems []any, structField string) ([]any, diag.Diagnostic)

GetLatestCreated is a helper function that returns the latest create entry in the input slice.

func (Config) GetLatestVersion

func (f Config) GetLatestVersion(elems []any, structField string) (any, diag.Diagnostic)

GetLatestVersion gets the latest version of the given struct

func (Config) OrderBySchema

func (f Config) OrderBySchema() schema.StringAttribute

OrderBySchema returns the schema for the top-level `order_by` field.

func (Config) OrderSchema

func (f Config) OrderSchema() schema.StringAttribute

OrderSchema returns the schema for the top-level `order` field.

func (Config) Schema

func (f Config) Schema() schema.SetNestedBlock

Schema returns the schema that should be used for the `filter` attribute in list data sources.

type FilterAttribute

type FilterAttribute struct {
	// Whether this field can be filtered on at an API level.
	// If false, this filter will be handled on the client.
	APIFilterable bool

	// Converts the filter string to the correct type.
	TypeFunc FilterTypeFunc

	// (Optional) Allows this attribute during validation
	// for the order and order_by fields.
	// This is useful for edge cases where we want order
	// through the API but filter on the client.
	AllowOrderOverride bool
}

FilterAttribute is used to configure filtering for an individual response field.

type FilterModel

type FilterModel struct {
	Name    types.String   `tfsdk:"name" json:"name"`
	Values  []types.String `tfsdk:"values" json:"values"`
	MatchBy types.String   `tfsdk:"match_by" json:"match_by"`
}

FilterModel describes the Terraform resource data model to match the resource schema.

type FilterTypeFunc

type FilterTypeFunc func(value string) (any, error)

FilterTypeFunc is a function that takes in a filter name and value, and returns the value converted to the correct filter type.

type FiltersModelType

type FiltersModelType []FilterModel

FiltersModelType should be used for the `filter` attribute in list data sources.

type ListFunc

type ListFunc func(ctx context.Context, client *linodego.Client, filter string) ([]any, error)

ListFunc is a wrapper for functions that will list and return values from the API.

Jump to

Keyboard shortcuts

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