Skip to content

Commit

Permalink
Merge pull request #203 from teamssix/beta
Browse files Browse the repository at this point in the history
fix: fix a bug of the cache function
  • Loading branch information
teamssix authored Dec 29, 2022
2 parents b9f266d + 1929c52 commit c1d9a80
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
12 changes: 8 additions & 4 deletions pkg/util/cmdutil/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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{
Expand All @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/util/database/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.)")
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/util/pubutil/pubutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit c1d9a80

Please sign in to comment.