utils

package
v0.2.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const REPLACE_REG = "(?i)internal"
View Source
const SysTagKeyEnterpriseProjectId = "_sys_enterprise_project_id"

Variables

View Source
var PackageName string
View Source
var ValidateSubnetV2IPv6Mode = validation.StringInSlice([]string{
	"slaac", "dhcpv6-stateful", "dhcpv6-stateless",
}, false)

Functions

func Base64EncodeString

func Base64EncodeString(str string) string

Base64EncodeString is used to encode a string by base64.

func Bool

func Bool(v bool) *bool

returns a pointer to the bool value

func BuildNewFormatByConfig

func BuildNewFormatByConfig(format string) string

func BuildSysTags

func BuildSysTags(enterpriseProjectID string) (enterpriseProjectTags []tags.ResourceTag)

func CompareJsonTemplateAreEquivalent

func CompareJsonTemplateAreEquivalent(tem1, tem2 string) (bool, error)

func ConvertStructToMap

func ConvertStructToMap(obj interface{}, nameMap map[string]string) (map[string]interface{}, error)

ConvertStructToMap converts an instance of struct to a map object, and changes each key of fileds to the value of 'nameMap' if the key in it or to its corresponding lowercase.

func CreateResourceTags

func CreateResourceTags(client *golangsdk.ServiceClient, d *schema.ResourceData, resourceType, id string) error

CreateResourceTags is a helper to create the tags for a resource. It expects the schema name must be "tags"

func DecodeHashAndHexEncode

func DecodeHashAndHexEncode(v interface{}) string

DecodeHashAndHexEncode is one of the implementations of SchemaStateFunc. The function tries to decode v if it is in base64 format, then gets the hash of decode string and returns the hexadecimal encoding string. If the type of v is not string, just returns an empty string.

func DeleteResourceTagsWithKeys

func DeleteResourceTagsWithKeys(client *golangsdk.ServiceClient, tagKeys []string, resourceType, id string) error

DeleteResourceTagsWithKeys is a helper to delete the tags with tagKeys for a resource.

func ExpandResourceTags

func ExpandResourceTags(tagmap map[string]interface{}) []tags.ResourceTag

ExpandResourceTags returns the tags for the given map of data.

func ExpandResourceTagsMap

func ExpandResourceTagsMap(tagmap map[string]interface{}) []map[string]interface{}

ExpandResourceTagsMap returns the tags in format of list of maps for the given map of data.

func ExpandToInt32List

func ExpandToInt32List(v []interface{}) []int32

ExpandToInt32List takes the result for an array of intgers and returns a []int32

func ExpandToInt32ListPointer

func ExpandToInt32ListPointer(v []interface{}) *[]int32

ExpandToInt32ListPointer takes the result for an array of in32 and returns a pointer of the array

func ExpandToIntList

func ExpandToIntList(v []interface{}) []int

ExpandToIntList takes the result for an array of intgers and returns a []int

func ExpandToStringList

func ExpandToStringList(v []interface{}) []string

ExpandToStringList takes the result for an array of strings and returns a []string

func ExpandToStringListBySet

func ExpandToStringListBySet(v *schema.Set) []string

ExpandToStringListBySet takes the result for a set of strings and returns a []string

func ExpandToStringListPointer

func ExpandToStringListPointer(v []interface{}) *[]string

ExpandToStringListPointer takes the result for an array of strings and returns a pointer of the array

func ExpandToStringMap

func ExpandToStringMap(v map[string]interface{}) map[string]string

ExpandToStringMap takes the result for a map of string and returns a map[string]string

func FilterSliceWithField

func FilterSliceWithField(all interface{}, filter map[string]interface{}) ([]interface{}, error)

FilterSliceWithField can filter the slice all through a map filter. If the field is a nested value, using dot(.) to split them, e.g. "SubBlock.SubField". If value in the map is zero, it will be ignored.

func FilterSliceWithZeroField

func FilterSliceWithZeroField(all interface{}, filter map[string]interface{}) ([]interface{}, error)

FilterSliceWithZeroField can filter the slice all through a map filter.

func FlattenResponse

func FlattenResponse(resp *http.Response) (interface{}, error)

FlattenResponse returns the api response body if it's not empty

func FlattenTagsToMap

func FlattenTagsToMap(tags interface{}) map[string]interface{}

FlattenTagsToMap returns the list of tags into a map.

func Float64

func Float64(v float64) *float64

Float64 returns a pointer to the float64 value

func FormatTimeStampRFC3339

func FormatTimeStampRFC3339(timestamp int64, isUTC bool, customFormat ...string) string

FormatTimeStampRFC3339 is used to unify the time format to RFC-3339 and return a time string. We can use "isUTC" parameter to reset the timezone. If omitted, the method will return local time. Parameter "customFormat" allows you to use a custom RFC3339 format, such as: "2006-01-02T15:04:05.000Z", this parameter can be omitted.

func FormatTimeStampUTC

func FormatTimeStampUTC(timestamp int64) string

FormatTimeStampUTC is used to unify the unix second time to UTC time string, format: YYYY-MM-DD HH:MM:SS.

func FormatUTCTimeStamp

func FormatUTCTimeStamp(utcTime string) (int64, error)

FormatTimeStampUTC is used to unify the unix second time to UTC time string, format: YYYY-MM-DD HH:MM:SS.

func GetDNSRecordSetTagType

func GetDNSRecordSetTagType(zoneType string) (string, error)

GetDNSRecordSetTagType returns resource tag type of DNS record set by zoneType

func GetDNSZoneTagType

func GetDNSZoneTagType(zoneType string) (string, error)

GetDNSZoneTagType returns resource tag type of DNS zone by zoneType

func GetTimezoneCode

func GetTimezoneCode() int

GetTimezoneCode calculates the time zone code and returns a signed number. For example, the time zone code for 'Asia/Shanghai' is 8, and the time zone code for 'America/Alaska' is -4.

func HasMapContains

func HasMapContains(rawMap map[string]string, filterMap map[string]interface{}) bool

This function compares whether there is a containment relationship between two maps, that is, whether map A (rawMap) contains map B (filterMap).

Map A is {'foo': 'bar'} and filter map B is {'foo': 'bar'} or {'foo': 'bar,dor'} will return true.
Map A is {'foo': 'bar'} and filter map B is {'foo': 'dor'} or {'foo1': 'bar'} will return false.
Map A is {'foo': 'bar'} and filter map B is {'foo': ''} will return true.
Map A is {'foo': 'bar'} and filter map B is {'': 'bar'} or {'': ''} will return false.

The value of filter map 'bar,for' means that the object value can be either 'bar' or 'dor'. Note: There is no spaces before and after the delimiter (,).

func HashAndHexEncode

func HashAndHexEncode(v interface{}) string

HashAndHexEncode is one of the implementations of SchemaStateFunc. The function gets the hash of v then returns the hexadecimal encoding string. If the type of v is not string, just returns an empty string.

func Int

func Int(v int) *int

Int returns a pointer to the int value

func Int32

func Int32(v int32) *int32

Int32 returns a pointer to the int32 value

func Int32IgnoreEmpty

func Int32IgnoreEmpty(v int32) *int32

Int32 returns a pointer to the int32 value. if v is empty, return nil

func Int64IgnoreEmpty

func Int64IgnoreEmpty(v int64) *int64

Int32 returns a pointer to the int32 value

func IntIgnoreEmpty

func IntIgnoreEmpty(v int) *int

Int returns a pointer to the int value. if v is empty, return nil

func IsDebugOrHigher

func IsDebugOrHigher() bool

func IsIPv4Address

func IsIPv4Address(addr string) bool

IsIPv4Address is used to check whether the addr string is IPv4 format

func IsResourceNotFound

func IsResourceNotFound(err error) bool

func IsStrContainsSliceElement

func IsStrContainsSliceElement(str string, sl []string, ignoreCase, isExcat bool) bool

IsStrContainsSliceElement returns true if the string exists in given slice or contains in one of slice elements when open exact flag. Also you can ignore case for this check.

func JSONStringsEqual

func JSONStringsEqual(s1, s2 string) bool

JSONStringsEqual is the function for comparing the contents of two json strings regardless of their formatting. Tabs (\r \n \t) and the order of elements are not included in the comparison. These json strings are same: + "{\n\"key1\":\"value1\",\n\"key2\":\"value2\"\n}" + "{\"key1\":\"value1\",\"key2\":\"value2\"}" + "{\"key2\":\"value2\",\"key1\":\"value1\"}"

func JsonMarshal

func JsonMarshal(t interface{}) ([]byte, error)

func MarshalValue

func MarshalValue(i interface{}) string

MarshalValue is used to marshal the value of struct in internal-sdk-go-v3, like this: type Xxxx struct { value string }

func NormalizeJsonString

func NormalizeJsonString(jsonString interface{}) (string, error)

Takes a value containing JSON string and passes it through the JSON parser to normalize it, returns either a parsing error or normalized JSON string.

func ParseEnterpriseProjectIdFromSysTags

func ParseEnterpriseProjectIdFromSysTags(value []tags.ResourceTag) (enterpriseProjectId string)

func PasswordEncrypt

func PasswordEncrypt(password string) (string, error)

PasswordEncrypt encrypts given password with sha512

func PathSearch

func PathSearch(expression string, obj interface{}, defaultValue interface{}) interface{}

PathSearch evaluates a JMESPath expression against input data and returns the result.

func RandomString

func RandomString(n int, allowedChars ...[]rune) (result string)

RandomString returns a random string with a fixed length. You can also define a custom random character set. Note: make sure the number is not a negative integer or a big integer.

func RemoveDuplicateElem

func RemoveDuplicateElem(s []string) []string

RemoveDuplicateElem removes duplicate elements from slice

func RemoveNil

func RemoveNil(data map[string]interface{}) map[string]interface{}

func Reverse

func Reverse(s string) string

Reverse is a function that used to reverse the order of the characters in the given string.

func Salt

func Salt(size int) ([]byte, error)

Salt generates a random salt according to given size

func SchemaDesc

func SchemaDesc(description string, schemaDescInput SchemaDescInput) string

func SetResourceTagsToState

func SetResourceTagsToState(d *schema.ResourceData, client *golangsdk.ServiceClient, resourceType, id string) error

SetResourceTagsToState is a helper to query tags of resource, then set to state. The schema argument name must be: tags

func StrSliceContains

func StrSliceContains(haystack []string, needle string) bool

StrSliceContains checks if a given string is contained in a slice When anybody asks why Go needs generics, here you go.

func StrSliceContainsAnother

func StrSliceContainsAnother(b []string, s []string) bool

StrSliceContainsAnother checks whether a string slice (b) contains another string slice (s).

func String

func String(v string) *string

returns a pointer to the string value

func StringIgnoreEmpty

func StringIgnoreEmpty(v string) *string

returns a pointer to the string value. if v is empty, return nil

func StringToBool

func StringToBool(v interface{}) *bool

StringToBool convert the string to boolean, and return the pointer of boolean value

func StringToInt

func StringToInt(i *string) *int

StringToInt convert the string to int, and return the pointer of int value

func StringValue

func StringValue(v *string) string

StringValue returns the string value

func SuppressCaseDiffs

func SuppressCaseDiffs(k, old, new string, d *schema.ResourceData) bool

Suppress changes if we get a string with or without cases

func SuppressDiffAll

func SuppressDiffAll(k, old, new string, d *schema.ResourceData) bool

Suppress all changes

func SuppressEquivalentAwsPolicyDiffs

func SuppressEquivalentAwsPolicyDiffs(k, old, new string, d *schema.ResourceData) bool

func SuppressEquivilentTimeDiffs

func SuppressEquivilentTimeDiffs(k, old, new string, d *schema.ResourceData) bool

func SuppressLBWhitelistDiffs

func SuppressLBWhitelistDiffs(k, old, new string, d *schema.ResourceData) bool

func SuppressMinDisk

func SuppressMinDisk(k, old, new string, d *schema.ResourceData) bool

Suppress changes if we get a computed min_disk_gb if value is unspecified (default 0)

func SuppressNewLineDiffs

func SuppressNewLineDiffs(k, old, new string, d *schema.ResourceData) bool

Suppress changes if we get a string with or without new line

func SuppressSnatFiplistDiffs

func SuppressSnatFiplistDiffs(k, old, new string, d *schema.ResourceData) bool

func SuppressUserData

func SuppressUserData(k, old, new string, d *schema.ResourceData) bool

Suppress changes if we get a base64 format or plaint text user_data

func SuppressVersionDiffs

func SuppressVersionDiffs(k, old, new string, d *schema.ResourceData) bool

func TagsToMap

func TagsToMap(tags []tags.ResourceTag) map[string]string

TagsToMap returns the list of tags into a map.

func TryBase64EncodeString

func TryBase64EncodeString(str string) string

TryBase64EncodeString will encode a string with base64. If the string is already base64 encoded, returns it directly.

func TryPasswordEncrypt

func TryPasswordEncrypt(password string) (string, error)

TryPasswordEncrypt tries to encrypt given password if it's not encrypted

func UpdateResourceTags

func UpdateResourceTags(conn *golangsdk.ServiceClient, d *schema.ResourceData, resourceType, id string) error

UpdateResourceTags is a helper to update the tags for a resource. It expects the tags field to be named "tags"

func ValidateCIDR

func ValidateCIDR(v interface{}, k string) (ws []string, errors []error)

func ValidateIP

func ValidateIP(v interface{}, k string) (ws []string, errors []error)

func ValidateIPRange

func ValidateIPRange(v interface{}, k string) (ws []string, errors []error)

func ValidateJsonString

func ValidateJsonString(v interface{}, k string) (ws []string, errors []error)

func ValidateName

func ValidateName(v interface{}, k string) (ws []string, errors []error)

lintignore:V001

func ValidateString64WithChinese

func ValidateString64WithChinese(v interface{}, k string) (ws []string, errors []error)

lintignore:V001

func ValidateTrueOnly

func ValidateTrueOnly(v interface{}, k string) (ws []string, errors []error)

func ValidateVBSBackupDescription

func ValidateVBSBackupDescription(v interface{}, k string) (ws []string, errors []error)

lintignore:V001

func ValidateVBSBackupName

func ValidateVBSBackupName(v interface{}, k string) (ws []string, errors []error)

lintignore:V001

func ValidateVBSPolicyName

func ValidateVBSPolicyName(v interface{}, k string) (ws []string, errors []error)

lintignore:V001

func ValidateVBSTagKey

func ValidateVBSTagKey(v interface{}, k string) (ws []string, errors []error)

lintignore:V001

func ValidateVBSTagValue

func ValidateVBSTagValue(v interface{}, k string) (ws []string, errors []error)

lintignore:V001

func ValueIngoreEmpty

func ValueIngoreEmpty(v interface{}) interface{}

ValueIngoreEmpty returns to the string value. if v is empty, return nil

func WriteToPemFile

func WriteToPemFile(path, privateKey string) (err error)

WriteToPemFile is used to write the keypair to Pem file.

Types

type SchemaDescInput

type SchemaDescInput struct {
	Internal   bool     `json:"Internal,omitempty"`
	Deprecated bool     `json:"Deprecated,omitempty"`
	Required   bool     `json:"Required,omitempty"`
	Computed   bool     `json:"Computed,omitempty"`
	ForceNew   bool     `json:"ForceNew,omitempty"`
	Unscope    []string `json:"Unscope,omitempty"`
	UsedBy     []string `json:"UsedBy,omitempty"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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