utils

package
v0.0.0-...-953a1d4 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: MPL-2.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClaimDeviceConfig

func ClaimDeviceConfig(serial string) string

ClaimDeviceConfig returns a configuration string to claim a device by serial

func ClaimDeviceTestChecks

func ClaimDeviceTestChecks(serial string) resource.TestCheckFunc

ClaimDeviceTestChecks returns the test check functions for claiming a device by serial

func ClaimLicenseConfig

func ClaimLicenseConfig(license string) string

ClaimLicenseConfig returns a configuration string to claim a license

func ClaimLicenseTestChecks

func ClaimLicenseTestChecks(license string) resource.TestCheckFunc

ClaimLicenseTestChecks returns the test check functions for claiming a license

func ClaimOrderConfig

func ClaimOrderConfig(order string) string

ClaimOrderConfig returns a configuration string to claim an order

func ClaimOrderTestChecks

func ClaimOrderTestChecks(order string) resource.TestCheckFunc

ClaimOrderTestChecks returns the test check functions for claiming an order

func ConvertResourceSchemaToDataSourceSchema

func ConvertResourceSchemaToDataSourceSchema(resourceAttrs map[string]schema.Attribute) map[string]datasourceSchema.Attribute

ConvertResourceSchemaToDataSourceSchema converts a resource schema to a data source schema while carrying over all settings.

func CreateNetworkConfig

func CreateNetworkConfig(orgName, networkName string) string

CreateNetworkConfig returns a configuration string to create a network resource with the necessary test checks

func CreateNetworkOrgIdConfig

func CreateNetworkOrgIdConfig(orgId, networkName string) string

CreateNetworkOrgIdConfig returns a configuration string to create a network in an existing organization with the necessary test checks

func CreateOrganizationConfig

func CreateOrganizationConfig(organizationName string) string

CreateOrganizationConfig returns a configuration string to create an organization resource

func CreateResourceConfig

func CreateResourceConfig(resourceType string, attributes map[string]string) string

CreateResourceConfig returns a configuration string to create any resource

func CustomHttpRequestRetry

func CustomHttpRequestRetry[T any](ctx context.Context, maxRetries int, initialRetryDelay time.Duration, apiCall func() (T, *http.Response, error)) (T, *http.Response, error)

CustomHttpRequestRetry Helper function for retrying API calls. This is to recover from backend congestion errors which manifest as 4XX response codes

func CustomHttpRequestRetryStronglyTyped

func CustomHttpRequestRetryStronglyTyped[T any](ctx context.Context, maxRetries int, retryDelay time.Duration, apiCall func() (T, *http.Response, error, diag.Diagnostics)) (T, *http.Response, error, diag.Diagnostics)

CustomHttpRequestRetryStronglyTyped is a generic function that leverages CustomHttpRequestRetry

func Decrypt

func Decrypt(key, cryptoText string) (string, error)

Decrypt decrypts the given ciphertext with the provided key.

func Encrypt

func Encrypt(key, text string) (string, error)

Encrypt encrypts the given plaintext with the provided key.

func ExtractBoolAttr

func ExtractBoolAttr(hashMap map[string]interface{}, key string) (types.Bool, diag.Diagnostics)

ExtractBoolAttr Extracts a bool attribute from a hashmap

func ExtractFloat32Attr

func ExtractFloat32Attr(hashMap map[string]interface{}, key string) (types.Float64, diag.Diagnostics)

ExtractFloat32Attr Extracts a float attribute from a hashmap

func ExtractFloat64Attr

func ExtractFloat64Attr(hashMap map[string]interface{}, key string) (types.Float64, diag.Diagnostics)

ExtractFloat64Attr Extracts a float attribute from a hashmap

func ExtractInt32Attr

func ExtractInt32Attr(hashMap map[string]interface{}, key string) (types.Int64, diag.Diagnostics)

ExtractInt32Attr Extracts an int64 attribute from a hashmap

func ExtractInt64Attr

func ExtractInt64Attr(hashMap map[string]interface{}, key string) (types.Int64, diag.Diagnostics)

ExtractInt64Attr Extracts an int64 attribute from a hashmap

func ExtractInt64FromFloat

func ExtractInt64FromFloat(hashMap map[string]interface{}, key string) (types.Int64, diag.Diagnostics)

func ExtractListAttr

func ExtractListAttr(hashMap map[string]interface{}, key string, elemType attr.Type) (types.List, diag.Diagnostics)

ExtractListAttr extracts a list attribute from a hashmap

func ExtractListStringAttr

func ExtractListStringAttr(hashMap map[string]interface{}, key string) (types.List, diag.Diagnostics)

ExtractListStringAttr extracts a slice of string attributes from a hashmap

func ExtractObjectAttr

func ExtractObjectAttr(hashMap map[string]interface{}, key string, attrTypes map[string]attr.Type) (types.Object, diag.Diagnostics)

ExtractObjectAttr extracts an object attribute from a hashmap

func ExtractResponseToMap

func ExtractResponseToMap(resp *http.Response) (map[string]interface{}, error)

ExtractResponseToMap reads an HTTP response body and unmarshals the JSON content into a map[string]interface{}. It returns the map along with any error that occurs during the read or unmarshal process.

func ExtractStringAttr

func ExtractStringAttr(hashMap map[string]interface{}, key string) (types.String, diag.Diagnostics)

ExtractStringAttr Extracts a string attribute from a hashmap

func ExtractStringsFromList

func ExtractStringsFromList(array types.List) ([]string, diag.Diagnostics)

func FlattenList

func FlattenList(input types.List) []string

FlattenList converts a Terraform types.List into a slice of strings.

func Float32Pointer

func Float32Pointer(input float64) (*float32, diag.Diagnostics)

Float32Pointer Convert float64 to *float32 with error handling

func Float64Pointer

func Float64Pointer(input float32) (*float64, diag.Diagnostics)

Float64Pointer Convert float32 to *float64 with error handling

func GenerateTimestamp

func GenerateTimestamp() string

GenerateTimestamp returns the current timestamp in the format YYYYMMDDHHMMSS

func HandleAPIError

func HandleAPIError(ctx context.Context, resp *http.Response, err error, diags *diag.Diagnostics) error

HandleAPIError processes API errors and maps them to Terraform diagnostics.

func HttpDiagnostics

func HttpDiagnostics(httpResp *http.Response) string

HttpDiagnostics - responsible for gathering and logging HTTP driven events

func Int32Pointer

func Int32Pointer(input int64) (*int32, diag.Diagnostics)

Int32Pointer Convert int64 to *int32 with error handling

func ListInt64TypeToInt32Array

func ListInt64TypeToInt32Array(data types.List) ([]int32, diag.Diagnostics)

func LogCurrentState

func LogCurrentState(t *testing.T) resource.TestCheckFunc

LogCurrentState LogCurrentStat Custom test check function to log the current state

func LogPayload

func LogPayload(ctx context.Context, payload interface{})

LogPayload logs the request payload before making an API call.

func LogResponseBody

func LogResponseBody(ctx context.Context, httpResp *http.Response)

LogResponseBody logs the raw response body from the API.

func NetworkOrgIdTestChecks

func NetworkOrgIdTestChecks(networkName string) resource.TestCheckFunc

NetworkOrgIdTestChecks returns the aggregated test check functions for a network resource that is in an existing org

func NetworkTestChecks

func NetworkTestChecks(networkName string) resource.TestCheckFunc

NetworkTestChecks returns the aggregated test check functions for a network resource

func NewBoolDefault

func NewBoolDefault(defaultValue bool) defaults.Bool

NewBoolDefault returns a struct that implements the defaults.Bool interface for a resource Schema

func NewFloat64Default

func NewFloat64Default(defaultValue float64) defaults.Float64

NewFloat64Default returns a struct that implements the defaults.Float64 interface for a resource Schema

func NewHttpDiagnostics

func NewHttpDiagnostics(httpResp *http.Response, bodyContent string) string

NewHttpDiagnostics - responsible for gathering and logging HTTP driven events

func NewInt64Default

func NewInt64Default(defaultValue int64) defaults.Int64

NewInt64Default returns a struct that implements the defaults.Int64 interface for a resource Schema

func NewSensitivePlanModifier

func NewSensitivePlanModifier(encryptionKey string) planmodifier.String

func NewStringDefault

func NewStringDefault(defaultValue string) defaults.String

NewStringDefault returns a struct that implements the defaults.String interface for a resource Schema

func OrganizationTestChecks

func OrganizationTestChecks(organizationName string) resource.TestCheckFunc

OrganizationTestChecks returns the aggregated test check functions for an Organization resource

func ReadAndCloseBody

func ReadAndCloseBody(httpResp *http.Response) (string, error)

ReadAndCloseBody Define a helper function to read and close the HTTP response body

func ResourceTestCheck

func ResourceTestCheck(resourceName string, expectedAttrs map[string]string) resource.TestCheckFunc

ResourceTestCheck is a generic function to test any resource's attributes

func SafeBoolAttr

func SafeBoolAttr(data map[string]interface{}, key string) attr.Value

SafeBoolAttr safely maps a boolean field

func SafeFormatRFC3339

func SafeFormatRFC3339(ctx context.Context, t *time.Time, layout string) string

SafeFormatRFC3339 safely formats a *time.Time to a string using the provided layout. Returns an empty string if the time pointer is nil.

func SafeInt64Attr

func SafeInt64Attr(data map[string]interface{}, key string) attr.Value

SafeInt64Attr safely maps an integer field

func SafeListStringAttr

func SafeListStringAttr(data map[string]interface{}, key string) attr.Value

SafeListStringAttr safely maps a list of strings

func SafeStringAttr

func SafeStringAttr(data map[string]interface{}, key string) attr.Value

SafeStringAttr safely maps a string field

func ValidateRFC3339

func ValidateRFC3339(value string) error

ValidateRFC3339 validates whether a given string conforms to the RFC3339 format. Returns an error if the format is invalid.

Types

type RequiresReplaceIfSensitive

type RequiresReplaceIfSensitive struct{}

RequiresReplaceIfSensitive Custom plan modifier to require replacement if the sensitive attribute changes

func (RequiresReplaceIfSensitive) Description

func (RequiresReplaceIfSensitive) MarkdownDescription

func (r RequiresReplaceIfSensitive) MarkdownDescription(context.Context) string

func (RequiresReplaceIfSensitive) PlanModifyString

type SensitivePlanModifier

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

func (SensitivePlanModifier) Description

func (m SensitivePlanModifier) Description(ctx context.Context) string

func (SensitivePlanModifier) MarkdownDescription

func (m SensitivePlanModifier) MarkdownDescription(ctx context.Context) string

func (SensitivePlanModifier) PlanModifyString

Jump to

Keyboard shortcuts

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