diff --git a/pkg/util/cmdutil/cache.go b/pkg/util/cmdutil/cache.go index ed29515..7c8327f 100644 --- a/pkg/util/cmdutil/cache.go +++ b/pkg/util/cmdutil/cache.go @@ -18,11 +18,15 @@ func ReturnCacheDict() string { func WriteCacheFile(td cloud.TableData, provider string, serviceType string, region string, id string) { AccessKeyId := GetConfig(provider).AccessKeyId - if serviceType == "lh" { + ecsArray := []string{"ec2", "lh", "cvm"} + ossArray := []string{"s3", "obs"} + if pubutil.IN(serviceType, ecsArray) { serviceType = "ecs" + } else if pubutil.IN(serviceType, ossArray) { + serviceType = "oss" } if len(td.Body) == 0 { - if serviceType == "oss" || serviceType == "s3" { + if serviceType == "oss" { database.DeleteOSSCache(AccessKeyId) } else if serviceType == "ecs" { database.DeleteECSCache(AccessKeyId) @@ -32,7 +36,7 @@ func WriteCacheFile(td cloud.TableData, provider string, serviceType string, reg } else if region == "all" && id == "all" { log.Debugln("写入数据到缓存数据库 (Write data to a cache database)") switch { - case serviceType == "oss" || serviceType == "s3": + case serviceType == "oss": var OSSCacheList []pubutil.OSSCache for _, v := range td.Body { OSSCache := pubutil.OSSCache{ @@ -48,7 +52,7 @@ func WriteCacheFile(td cloud.TableData, provider string, serviceType string, reg OSSCacheList = append(OSSCacheList, OSSCache) } database.InsertOSSCache(OSSCacheList) - case serviceType == "ecs" || serviceType == "ec2": + case serviceType == "ecs": var ECSCacheList []pubutil.ECSCache for _, v := range td.Body { ECSCache := pubutil.ECSCache{ diff --git a/pkg/util/database/config.go b/pkg/util/database/config.go index 940a4d1..0a37f94 100644 --- a/pkg/util/database/config.go +++ b/pkg/util/database/config.go @@ -80,7 +80,7 @@ func DeleteConfig() { if isTrue { accessKeyId := strings.Split(config, "\t")[2] CacheDb.Where("access_key_id = ?", accessKeyId).Delete(&configList) - log.Infof("%s 访问密钥已删除 (%s Access Key deleted)", accessKeyId, accessKeyId) + log.Infof("%s 访问密钥已删除 (%s Access Key deleted)", pubutil.MaskAK(accessKeyId), pubutil.MaskAK(accessKeyId)) } else { log.Infoln("已取消删除选中的访问密钥 (Canceled delete the selected access key.)") } diff --git a/pkg/util/pubutil/pubutil.go b/pkg/util/pubutil/pubutil.go index cdb0e43..31e1373 100644 --- a/pkg/util/pubutil/pubutil.go +++ b/pkg/util/pubutil/pubutil.go @@ -139,3 +139,12 @@ func MaskAK(ak string) string { return ak } } + +func IN(target string, str_array []string) bool { + for _, element := range str_array { + if target == element { + return true + } + } + return false +}