Skip to content

Commit 869c8e7

Browse files
committed
perf(code):detail optimization
1 parent 0a727a6 commit 869c8e7

File tree

13 files changed

+27
-23
lines changed

13 files changed

+27
-23
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022-2023 404tk
3+
Copyright (c) 2022-2025 404tk
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ Reference [Wiki](https://github.com/404tk/cloudtoolkit/wiki)
88

99
| Provider | Payload | Supported |
1010
| :-------------------------: | :-----------------------------------------: | :----------------------------------------------------------: |
11-
| Alibaba Cloud | cloudlist<br/>backdoor-user<br/>bucket-dump<br/>event-dump<br/>exec-command<br/>database-account | ECS (Elastic Compute Service)<br/>OSS (Object Storage Service)<br/>RAM (Resource Access Management)<br/>RDS (Relational Database Service)<br/>SMS (Short Message Service)<br/>AliDNS<br/>SLS (Simple Log Service) |
12-
| Tencent Cloud | cloudlist<br/>backdoor-user<br/>exec-command | CVM (Cloud Virtual Machine)<br/>Lighthouse<br/>COS (Cloud Object Storage)<br/>CAM (Cloud Access Management)<br/>CDB (Cloud DataBase)<br/>DNSPod |
13-
| Huawei Cloud | cloudlist<br/>backdoor-user | ECS (Elastic Cloud Server)<br/>OBS (Object Storage Service)<br/>IAM (Identity and Access Management)<br/>RDS (Relational Database Service) |
11+
| Alibaba Cloud | cloudlist<br/>backdoor-user<br/>bucket-dump<br/>event-dump<br/>exec-command<br/>database-account | ECS <br/>OSS<br/>RAM <br/>RDS <br/>SMS <br/>AliDNS<br/>SLS |
12+
| Tencent Cloud | cloudlist<br/>backdoor-user<br/>exec-command | CVM <br/>Lighthouse<br/>COS<br/>CAM <br/>CDB <br/>DNSPod |
13+
| Huawei Cloud | cloudlist<br/>backdoor-user | ECS <br/>OBS <br/>IAM <br/>RDS |
1414
| Microsoft Azure | cloudlist | Virtual Machines<br/>Blob Storage |
15-
| AWS (Amazon web services) | cloudlist<br/>backdoor-user<br/>bucket-dump | EC2 (Elastic Compute Cloud)<br/>S3 (Simple Storage Service)<br/>IAM (Identity and Access Management) |
16-
| GCP (Google Cloud Platform) | cloudlist | Compute Engine<br/>Cloud DNS<br/>Identity and Access Management |
15+
| AWS | cloudlist<br/>backdoor-user<br/>bucket-dump | EC2<br/>S3 <br/>IAM |
16+
| GCP | cloudlist | Compute Engine<br/>Cloud DNS<br/>IAM |
1717
| Volcengine | cloudlist | ECS<br/>IAM |
18+
| JDCloud | cloudlist | VM<br/>IAM<br/>OSS |
1819

1920
## Thanks
2021
- [c-bata/go-prompt](https://github.com/c-bata/go-prompt)

pkg/providers/alibaba/sls/signature.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func (client *Client) signRequest(req *request, payload []byte) {
4242
func canonicalizeResource(req *request) string {
4343
canonicalizedResource := req.path
4444
var paramNames []string
45-
if req.params != nil && len(req.params) > 0 {
45+
if len(req.params) > 0 {
4646
for k := range req.params {
4747
paramNames = append(paramNames, k)
4848
}

pkg/providers/alibaba/sms/list.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ func (d *Driver) GetResource(ctx context.Context) (schema.Sms, error) {
3636
logger.Error("List SMS failed.")
3737
return res, err
3838
}
39-
res.Templates, err = listSmsTemplate(client)
40-
res.DailySize, err = querySendStatistics(client)
39+
res.Templates, _ = listSmsTemplate(client)
40+
res.DailySize, _ = querySendStatistics(client)
4141

4242
return res, err
4343
}
@@ -76,7 +76,10 @@ func listSmsTemplate(client *dysmsapi.Client) ([]schema.SmsTemplate, error) {
7676
return temps, err
7777
}
7878
for _, temp := range response.SmsTemplateList {
79-
s, _ := status[temp.AuditStatus]
79+
s, ok := status[temp.AuditStatus]
80+
if !ok {
81+
continue
82+
}
8083
temps = append(temps, schema.SmsTemplate{
8184
Name: temp.TemplateName,
8285
Status: s,

pkg/providers/alibaba/sms/query.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package sms
22

33
import (
4-
"fmt"
54
"time"
65

7-
"github.com/404tk/cloudtoolkit/utils/logger"
86
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
97
"github.com/aliyun/alibaba-cloud-sdk-go/services/dysmsapi"
108
)
@@ -25,6 +23,7 @@ func querySendStatistics(client *dysmsapi.Client) (int64, error) {
2523
return response.Data.TotalSize, nil
2624
}
2725

26+
/*
2827
func querySendDetails(client *dysmsapi.Client, phone string) {
2928
request := dysmsapi.CreateQuerySendDetailsRequest()
3029
request.Scheme = "https"
@@ -43,3 +42,4 @@ func querySendDetails(client *dysmsapi.Client, phone string) {
4342
fmt.Printf("%-10s\t%-90s\n\n", detail.SendDate, detail.Content)
4443
}
4544
}
45+
*/

pkg/providers/jdcloud/jdcloud.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func New(options schema.Options) (*Provider, error) {
3737
if payload == "cloudlist" {
3838
d := &iam.Driver{Cred: cred, Token: token}
3939
if !d.Validator(accessKey) {
40-
return nil, fmt.Errorf("Invalid Accesskey")
40+
return nil, fmt.Errorf("invalid accesskey")
4141
}
4242
cache.Cfg.CredInsert("default", options)
4343
}

pkg/providers/tencent/cam/roleadd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (d *Driver) AddRole() {
1717
logger.Error("Create role failed:", err.Error())
1818
return
1919
}
20-
err = attachPolicyToRole(client, d.RoleName)
20+
_ = attachPolicyToRole(client, d.RoleName)
2121
OwnerID := getOwnerUin(client)
2222
logger.Warning(fmt.Sprintf(
2323
"Switch URL: https://cloud.tencent.com/cam/switchrole?ownerUin=%s&roleName=%s\n",

pkg/providers/tencent/cam/useradd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func (d *Driver) AddUser() {
1717
logger.Error("Create user failed:", err.Error())
1818
return
1919
}
20-
err = attachPolicyToUser(client, d.UserName)
20+
_ = attachPolicyToUser(client, d.UserName)
2121
OwnerID := getOwnerUin(client)
2222
fmt.Printf("\n%-10s\t%-10s\t%-60s\n", "Username", "Password", "Login URL")
2323
fmt.Printf("%-10s\t%-10s\t%-60s\n", "--------", "--------", "---------")

runner/banner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@ const Version = `0.1.6`
1616

1717
// showBanner is used to show the banner to the user
1818
func ShowBanner() {
19-
fmt.Print(fmt.Sprintf(banner, Version))
19+
fmt.Printf(banner, Version)
2020
}

runner/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var filename = "config.yaml"
1414
func InitConfig() {
1515
_, err := os.Stat(filename)
1616
if os.IsNotExist(err) || err != nil {
17-
err = os.WriteFile(filename, []byte(defaultConfigFile), os.ModePerm)
17+
_ = os.WriteFile(filename, []byte(defaultConfigFile), os.ModePerm)
1818
}
1919
viper.AddConfigPath(".")
2020
viper.SetConfigFile(filename)

0 commit comments

Comments
 (0)