common

package
v1.81.98 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// DefaultSearchLogStartTimestamp sync logs start time 2023-11-07 16:41:00
	DefaultSearchLogStartTimestamp int64 = 1699346460000

	DefaultTopicId = "aef50d54-b17d-4782-8618-a7873203ec29"

	QueryGrammarRule = " AND "
)
View Source
const (
	PROVIDER_READ_RETRY_TIMEOUT  = "TENCENTCLOUD_READ_RETRY_TIMEOUT"
	PROVIDER_WRITE_RETRY_TIMEOUT = "TENCENTCLOUD_WRITE_RETRY_TIMEOUT"
	PROVIDER_WAIT_READ_TIMEOUT   = "TENCENTCLOUD_WAIT_READ_TIMEOUT"

	SWEEPER_NEED_PROTECT            = "SWEEPER_NEED_PROTECT"
	TENCENTCLOUD_COMMON_TIME_LAYOUT = "2006-01-02 15:04:05"
)
View Source
const (
	SweeperResourceScanDir        = "../../../tmp/resource_scan/"
	SweeperNonKeepResourceScanDir = "../../../tmp/non_keep_resource_scan/"
)
View Source
const (
	KeepResource    = "keep"
	NonKeepResource = "non-keep"

	SystemUserName = "system"
)
View Source
const COMMA_SP = ","
View Source
const FILED_SP = "#"
View Source
const InternalError = "InternalError"

InternalError common internalError, do not add in retryableErrorCode, because when some product return this error, retry won't fix anything.

View Source
const LogIdKey = contextLogId("logId")

Variables

View Source
var ContextNil context.Context = nil
View Source
var NeedProtect = getEnvDefault(SWEEPER_NEED_PROTECT, 0)

NeedProtect ... const writeRetryTimeout = 5 * time.Minute

View Source
var NonKeepResourceScanHeader = []string{"ResourceType", "ResourceName", "InstanceId", "InstanceName", "PrincipalId", "UserName"}
View Source
var ReadRetryTimeout = time.Duration(readRetry) * time.Minute
View Source
var ResourceScanHeader = []string{"资源类型", "资源名称", "实例ID", "实例名称", "分类", "创建时长(天)", "创建者用户ID", "创建者用户名"}
View Source
var TimeFormats = []string{
	time.RFC3339,
	"2006-01-02 15:04:05",
}

TimeFormats add all possible time formats

View Source
var WaitReadTimeout = time.Duration(waitRead) * time.Second
View Source
var WriteRetryTimeout = time.Duration(writeRetry) * time.Minute

Functions

func Base64ToString

func Base64ToString(config string) (string, error)

func BuildStateChangeConf

func BuildStateChangeConf(pending, target []string, timeout, delay time.Duration, refresh resource.StateRefreshFunc) *resource.StateChangeConf

func BuildTagResourceName

func BuildTagResourceName(serviceType, resourceType, region, id string) string

BuildTagResourceName builds the Tencent Cloud specific name of a resource description. The format is `qcs:project_id:service_type:region:account:resource`. For more information, go to https://cloud.tencent.com/document/product/598/10606.

func CheckNil

func CheckNil(object interface{}, fields map[string]string) (nilFields []string)

func CheckResourceNameKeep added in v1.81.72

func CheckResourceNameKeep(name string) string

CheckResourceNameKeep check whether to keep resource name

func CheckResourcePersist added in v1.81.72

func CheckResourcePersist(name, createTime string) bool

CheckResourcePersist check whether to persist resource

func CurrentTimeMillisecond added in v1.81.73

func CurrentTimeMillisecond() int64

CurrentTimeMillisecond get the current millisecond timestamp

func DaysSinceCreation added in v1.81.72

func DaysSinceCreation(createTime string) (string, error)

DaysSinceCreation compute resource creation duration

func FindIntListIndex

func FindIntListIndex(list []int, elem int) int

func GenerateCsvFile added in v1.81.72

func GenerateCsvFile(filePath string, header []string) error

GenerateCsvFile generate when csv file does not exist

func GetListDiffs

func GetListDiffs(o []int, n []int) (adds []int, lacks []int)

func GetListIncrement

func GetListIncrement(o []int, n []int) (result []int, err error)

func GetLogId

func GetLogId(ctx context.Context) string

GetLogId get logId for trace, return a new logId if ctx is nil

func GetResourceCreatorAccountInfo added in v1.81.73

func GetResourceCreatorAccountInfo(client *connectivity.TencentCloudClient, resourceCreateAction string, resources []*ResourceInstance) map[string]*ResourceAccountInfo

GetResourceCreatorAccountInfo get resource creator user info

func GetSubAccountUserName added in v1.81.73

func GetSubAccountUserName(client *connectivity.TencentCloudClient, uin string) string

GetSubAccountUserName get sub account user name

func InconsistentCheck

func InconsistentCheck(d *schema.ResourceData, meta interface{}) func()

InconsistentCheck for Provider produced inconsistent result after apply

func IsContains

func IsContains(array interface{}, value interface{}) bool

IsContains returns whether value is within array

func IsDefaultSearchLogStartTimestampAfter added in v1.81.92

func IsDefaultSearchLogStartTimestampAfter(parsedTime time.Time) bool

IsDefaultSearchLogStartTimestampAfter check whether the resource creation time is after the default search log start time

func IsExpectError

func IsExpectError(err error, expectError []string) bool

IsExpectError returns whether error is expected error

func IsNil

func IsNil(v interface{}) bool

IsNil Determine whether i is empty

func IsString

func IsString(data interface{}) bool

IsString Determine whether data is a string

func LogElapsed

func LogElapsed(mark ...string) func()

LogElapsed log func elapsed time, using in defer

func MatchAny

func MatchAny(value interface{}, matches ...interface{}) bool

func MonthBetweenTwoDates

func MonthBetweenTwoDates(start, end string) int

func NewResourceLifeCycleHandleFuncContext added in v1.81.93

func NewResourceLifeCycleHandleFuncContext(
	parent context.Context,
	logID string,
	d *schema.ResourceData,
	meta interface{},
) context.Context

NewResourceLifeCycleHandleFuncContext 创建一个资源生命周期处理方法上下文

func ParseTimeFromCommonLayout

func ParseTimeFromCommonLayout(t *string) time.Time

func ParsedTime added in v1.81.72

func ParsedTime(createTime string) (*time.Time, error)

ParsedTime parse time

func ProcessNonKeepResources added in v1.81.72

func ProcessNonKeepResources(client *connectivity.TencentCloudClient, nonKeepResources []*ResourceInstance, resourceCreateAction string)

ProcessNonKeepResources Processing scanned non-keep cloud resources

func ProcessResources added in v1.81.72

func ProcessResources(client *connectivity.TencentCloudClient, resources []*ResourceInstance, resourceCreateAction string)

ProcessResources Process all scanned cloud resources

func ProcessScanCloudResources added in v1.81.72

func ProcessScanCloudResources(client *connectivity.TencentCloudClient, resources, nonKeepResources []*ResourceInstance, resourceCreateAction string)

func ProviderMetaFromContext added in v1.81.93

func ProviderMetaFromContext(ctx context.Context) interface{}

ProviderMetaFromContext 从上下文获取 provider meta

func ReadFromFile

func ReadFromFile(file string) ([]byte, error)

ReadFromFile return file content

func ResourceDataFromContext added in v1.81.93

func ResourceDataFromContext(ctx context.Context) *schema.ResourceData

ResourceDataFromContext 从上下文获取资源数据

func RetryError

func RetryError(err error, additionRetryableError ...string) *resource.RetryError

RetryError returns retry error

func RetryWithContext

func RetryWithContext(
	ctx context.Context,
	timeout time.Duration,
	f func(context.Context) (interface{}, error),
	additionRetryableError ...string) (interface{}, error)

RetryWithContext retries the function `f` when the error it returns satisfies `predicate`. `f` is retried until `timeout` expires.

func ShortRegionNameParse added in v1.81.60

func ShortRegionNameParse(shortRegion string) string

func StringToBase64

func StringToBase64(config string) string

func StringToTime

func StringToTime(t string) time.Time

StringToTime string to time.Time

func ValidateAllowedIntValue

func ValidateAllowedIntValue(ints []int) schema.SchemaValidateFunc

func ValidateAllowedStringValue

func ValidateAllowedStringValue(ss []string) schema.SchemaValidateFunc

func ValidateAllowedStringValueIgnoreCase

func ValidateAllowedStringValueIgnoreCase(ss []string) schema.SchemaValidateFunc

func ValidateAsConfigPassword

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

func ValidateAsScheduleTimestamp

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

func ValidateCIDRNetworkAddress

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

validateCIDRNetworkAddress ensures that the string value is a valid CIDR that represents a network address - it adds an error otherwise

func ValidateCidrIp

func ValidateCidrIp(v interface{}, k string) (ws []string, errs []error)

func ValidateCosBucketLifecycleTimestamp

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

func ValidateCosBucketName

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

Only support lowercase letters, numbers and "-". It cannot be longer than 60 characters. specification: https://cloud.tencent.com/document/product/436/13312

func ValidateImageID

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

func ValidateInstanceType

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

func ValidateIntegerInRange

func ValidateIntegerInRange(min, max int64) schema.SchemaValidateFunc

NOTE not exactly strict, but ok for now

func ValidateIntegerMin

func ValidateIntegerMin(min int) schema.SchemaValidateFunc

func ValidateIp

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

func ValidateKeyPairName

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

func ValidateLowCase

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

func ValidateMysqlPassword

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

func ValidateNameRegex

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

func ValidateNotEmpty

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

func ValidatePort

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

func ValidatePortRange

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

func ValidateStringLengthInRange

func ValidateStringLengthInRange(min, max int) schema.SchemaValidateFunc

func ValidateStringNumber

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

func ValidateStringPrefix

func ValidateStringPrefix(prefix ...string) schema.SchemaValidateFunc

check if string has given prefix, if no one prefix matches, errors will have error

func ValidateStringSuffix

func ValidateStringSuffix(suffix ...string) schema.SchemaValidateFunc

check if string has given suffix, if no one suffix matches, errors will have error

func ValidateTime

func ValidateTime(layout string) schema.SchemaValidateFunc

func ValidateTkeGpuDriverVersion

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

func ValidateYaml

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

func WriteCsvFileData added in v1.81.72

func WriteCsvFileData(dirPath string, header []string, data [][]string) error

WriteCsvFileData write data to csv file

func WriteToFile

func WriteToFile(filePath string, data interface{}) error

WriteToFile write data to file

func YamlParser

func YamlParser(config string) (map[interface{}]interface{}, error)

YamlParser yaml syntax Parser

Types

type GoRoutineLimit

type GoRoutineLimit struct {
	Count int
	Chan  chan struct{}
}

GoRoutineLimit ...

func NewGoRoutine

func NewGoRoutine(num int) *GoRoutineLimit

func (*GoRoutineLimit) Run

func (g *GoRoutineLimit) Run(f func())

type ProviderMeta

type ProviderMeta interface {
	// GetAPIV3Conn 返回访问云 API 的客户端连接对象
	GetAPIV3Conn() *connectivity.TencentCloudClient
}

ProviderMeta Provider 元信息

type ResourceAccountInfo added in v1.81.73

type ResourceAccountInfo struct {
	ResourceType string // 资源类型
	ResourceName string // 资源名称
	AccountId    string // 主账号ID
	PrincipalId  string // 用户ID
	UserName     string // 用户名
}

ResourceAccountInfo 资源账户信息

func ParseLogJsonData added in v1.81.73

func ParseLogJsonData(jsonData string) *ResourceAccountInfo

type ResourceInstance added in v1.81.72

type ResourceInstance struct {
	Id          string
	Name        string
	CreateTime  string
	DefaultKeep bool
}

Jump to

Keyboard shortcuts

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