utils

package
v0.0.20 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildTreeStructure

func BuildTreeStructure(nodes []*model.TreeNode) []*model.TreeNode

BuildTreeStructure 构建树形结构

func DecryptPassword

func DecryptPassword(encryptedPassword string) (string, error)

DecryptPassword 解密密码

func EncryptPassword

func EncryptPassword(password string) (string, error)

EncryptPassword 加密密码

func ExportAsCSV added in v0.0.20

func ExportAsCSV(accounts []*model.CloudAccount) [][]string

ExportAsCSV 导出为 CSV 格式

func ExportAsJSON added in v0.0.20

func ExportAsJSON(accounts []*model.CloudAccount) interface{}

ExportAsJSON 导出为 JSON 格式

func GetAvailableRegionsByProvider added in v0.0.17

func GetAvailableRegionsByProvider(ctx context.Context, provider model.CloudProvider, accessKey, secretKey string, logger *zap.Logger) ([]model.AvailableRegion, error)

GetAvailableRegionsByProvider 根据云厂商获取可用区域列表(通过API动态获取)

func GetAvailableRegionsByProviderWithoutCredentials added in v0.0.17

func GetAvailableRegionsByProviderWithoutCredentials(provider model.CloudProvider) []model.AvailableRegion

GetAvailableRegionsByProviderWithoutCredentials 获取云厂商可用区域列表(无需凭证,返回常用区域作为降级方案)

func GetDefaultRegion added in v0.0.20

func GetDefaultRegion(regions []*model.CloudAccountRegion) (string, error)

GetDefaultRegion 从云账户的区域列表中获取默认区域 返回默认区域的Region字符串,如果没有找到默认区域则返回第一个区域 如果区域列表为空,返回空字符串和错误

func GetProviderName added in v0.0.20

func GetProviderName(provider model.CloudProvider) string

GetProviderName 获取云厂商名称

func SanitizeCloudAccount added in v0.0.20

func SanitizeCloudAccount(account *model.CloudAccount)

SanitizeCloudAccount 清理云账户敏感信息(双重保险) 虽然AccessKey和SecretKey已经设置了json:"-"标签,但这个方法提供额外的安全保障

func SanitizeCloudAccounts added in v0.0.20

func SanitizeCloudAccounts(accounts []*model.CloudAccount)

SanitizeCloudAccounts 批量清理云账户敏感信息

func SetSSHDefaults

func SetSSHDefaults(port *int, username *string)

SetSSHDefaults 设置SSH连接的默认值

func SyncAWSResources

func SyncAWSResources(ctx context.Context, req *model.SyncTreeCloudResourceReq, logger *zap.Logger) error

SyncAWSResources 同步AWS资源

func SyncAliyunResources

func SyncAliyunResources(ctx context.Context, config *AliyunSyncConfig, logger *zap.Logger) ([]*model.TreeCloudResource, error)

SyncAliyunResources 同步阿里云资源

func SyncAzureResources

func SyncAzureResources(ctx context.Context, req *model.SyncTreeCloudResourceReq, logger *zap.Logger) error

SyncAzureResources 同步Azure资源

func SyncGCPResources

func SyncGCPResources(ctx context.Context, req *model.SyncTreeCloudResourceReq, logger *zap.Logger) error

SyncGCPResources 同步GCP资源

func SyncHuaweiResources

func SyncHuaweiResources(ctx context.Context, req *model.SyncTreeCloudResourceReq, logger *zap.Logger) error

SyncHuaweiResources 同步华为云资源

func SyncTencentResources

func SyncTencentResources(ctx context.Context, req *model.SyncTreeCloudResourceReq, logger *zap.Logger) error

SyncTencentResources 同步腾讯云资源

func ValidateAndNormalizeRegions added in v0.0.20

func ValidateAndNormalizeRegions(regions []model.CreateCloudAccountRegionItem) ([]model.CreateCloudAccountRegionItem, error)

ValidateAndNormalizeRegions 验证和规范化区域列表 检查区域是否为空、是否重复、默认区域是否唯一 如果没有指定默认区域,会将第一个区域设置为默认 返回规范化后的区域列表(新切片),不修改传入的切片

func ValidateAndSetPaginationDefaults

func ValidateAndSetPaginationDefaults(page, size *int)

ValidateAndSetPaginationDefaults 验证并设置分页参数的默认值

func ValidateID

func ValidateID(id int) error

ValidateID 验证ID是否有效

func ValidateMemberType

func ValidateMemberType(memberType string) error

ValidateMemberType 验证成员类型

func ValidateNodeMove

func ValidateNodeMove(nodeID, newParentID int) error

ValidateNodeMove 验证节点移动操作

func ValidateParentID

func ValidateParentID(parentID int) error

ValidateParentID 验证父节点ID是否有效

func ValidateResourceIDs

func ValidateResourceIDs(resourceIDs []int) error

ValidateResourceIDs 验证资源ID列表

func ValidateTreeNodeIDs

func ValidateTreeNodeIDs(treeNodeIDs []int) bool

ValidateTreeNodeIDs 验证树节点ID列表

func VerifyAWSCredentials

func VerifyAWSCredentials(ctx context.Context, req *model.VerifyCloudCredentialsReq, logger *zap.Logger) error

VerifyAWSCredentials 验证AWS凭证

func VerifyAliyunCredentials

func VerifyAliyunCredentials(ctx context.Context, req *model.VerifyCloudCredentialsReq, logger *zap.Logger) error

VerifyAliyunCredentials 验证阿里云凭证

func VerifyAzureCredentials

func VerifyAzureCredentials(ctx context.Context, req *model.VerifyCloudCredentialsReq, logger *zap.Logger) error

VerifyAzureCredentials 验证Azure凭证

func VerifyGCPCredentials

func VerifyGCPCredentials(ctx context.Context, req *model.VerifyCloudCredentialsReq, logger *zap.Logger) error

VerifyGCPCredentials 验证GCP凭证

func VerifyHuaweiCredentials

func VerifyHuaweiCredentials(ctx context.Context, req *model.VerifyCloudCredentialsReq, logger *zap.Logger) error

VerifyHuaweiCredentials 验证华为云凭证

func VerifyTencentCredentials

func VerifyTencentCredentials(ctx context.Context, req *model.VerifyCloudCredentialsReq, logger *zap.Logger) error

VerifyTencentCredentials 验证腾讯云凭证

Types

type AliyunClient

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

AliyunClient 阿里云客户端封装

func NewAliyunClient

func NewAliyunClient(accessKey, secretKey, region string, logger *zap.Logger) (*AliyunClient, error)

NewAliyunClient 创建阿里云客户端

func (*AliyunClient) GetAvailableRegions added in v0.0.17

func (c *AliyunClient) GetAvailableRegions(ctx context.Context) ([]model.AvailableRegion, error)

GetAvailableRegions 获取阿里云所有可用区域列表

func (*AliyunClient) GetECSInstanceByID

func (c *AliyunClient) GetECSInstanceByID(ctx context.Context, instanceID string) (*model.TreeCloudResource, error)

GetECSInstanceByID 根据实例ID获取单个ECS实例

func (*AliyunClient) ListECSInstances

func (c *AliyunClient) ListECSInstances(ctx context.Context, instanceIDs []string) ([]*model.TreeCloudResource, error)

ListECSInstances 获取ECS实例列表

func (*AliyunClient) VerifyCredentials

func (c *AliyunClient) VerifyCredentials(ctx context.Context) error

VerifyCredentials 验证阿里云凭证

type AliyunSyncConfig

type AliyunSyncConfig struct {
	AccessKey      string
	SecretKey      string
	Region         string
	CloudAccountID int
	ResourceType   model.CloudResourceType
	InstanceIDs    []string
	SyncMode       model.SyncMode
}

AliyunSyncConfig 阿里云同步配置

Jump to

Keyboard shortcuts

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