Skip to content

Commit d59f3fd

Browse files
committed
feat: support list alibaba cloud domain services
1 parent bb0bf12 commit d59f3fd

File tree

6 files changed

+76
-10
lines changed

6 files changed

+76
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [v1.1.0](https://github.com/wgpsec/lc/releases/tag/v1.1.0) 2024.10.6
44

55
* 支持列出阿里云 FC 函数计算服务
6+
* 支持列出阿里云域名服务
67
* 支持在列出时指定要列出的云服务类型
78
* 修复阿里云 ECS 在绑定 EIP 时无法列出 IP 的 Bug
89

cmd/configFile.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const defaultConfigFile = `# # lc (list cloud) 的云服务商配置文件
1919
# # 访问凭证获取地址:https://ram.console.aliyun.com
2020
# - provider: aliyun
2121
# id: aliyun_default
22-
# cloud_services: ecs,oss,rds,fc
22+
# cloud_services: ecs,oss,rds,fc,domain
2323
# access_key:
2424
# secret_key:
2525
# session_token:

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ go 1.22.1
44

55
require (
66
github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.9
7+
github.com/alibabacloud-go/domain-20180129/v4 v4.2.0
78
github.com/alibabacloud-go/fc-20230330/v4 v4.1.3
89
github.com/alibabacloud-go/fc-open-20210406/v2 v2.0.12
10+
github.com/alibabacloud-go/tea-utils/v2 v2.0.6
911
github.com/aliyun/alibaba-cloud-sdk-go v1.62.712
1012
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
1113
github.com/aws/aws-sdk-go v1.51.16
@@ -31,7 +33,6 @@ require (
3133
github.com/alibabacloud-go/openapi-util v0.1.0 // indirect
3234
github.com/alibabacloud-go/tea v1.2.2 // indirect
3335
github.com/alibabacloud-go/tea-utils v1.3.1 // indirect
34-
github.com/alibabacloud-go/tea-utils/v2 v2.0.6 // indirect
3536
github.com/alibabacloud-go/tea-xml v1.1.3 // indirect
3637
github.com/aliyun/credentials-go v1.3.1 // indirect
3738
github.com/andybalholm/brotli v1.0.6 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ github.com/alibabacloud-go/darabonba-openapi/v2 v2.0.9/go.mod h1:bb+Io8Sn2RuM3/R
1313
github.com/alibabacloud-go/debug v0.0.0-20190504072949-9472017b5c68/go.mod h1:6pb/Qy8c+lqua8cFpEy7g39NRRqOWc3rOwAy8m5Y2BY=
1414
github.com/alibabacloud-go/debug v1.0.0 h1:3eIEQWfay1fB24PQIEzXAswlVJtdQok8f3EVN5VrBnA=
1515
github.com/alibabacloud-go/debug v1.0.0/go.mod h1:8gfgZCCAC3+SCzjWtY053FrOcd4/qlH6IHTI4QyICOc=
16+
github.com/alibabacloud-go/domain-20180129/v4 v4.2.0 h1:PAEt76VDoXbQODWeN9PTwYhA5NoEbJSK/yzGX2DZXrQ=
17+
github.com/alibabacloud-go/domain-20180129/v4 v4.2.0/go.mod h1:q0n3wgGRndhuZsAXFVCFtiSR8+W0so85qYtKLzR2b18=
1618
github.com/alibabacloud-go/endpoint-util v1.1.0 h1:r/4D3VSw888XGaeNpP994zDUaxdgTSHBbVfZlzf6b5Q=
1719
github.com/alibabacloud-go/endpoint-util v1.1.0/go.mod h1:O5FuCALmCKs2Ff7JFJMudHs0I5EBgecXXxZRyswlEjE=
1820
github.com/alibabacloud-go/fc-20230330/v4 v4.1.3 h1:/4/A8pD6WBoy3LdDASyrQ36cBF7KhN6nIHGKPpcdsBE=

pkg/providers/aliyun/aliyun.go

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package aliyun
33
import (
44
"context"
55
"fmt"
6+
openapi "github.com/alibabacloud-go/darabonba-openapi/v2/client"
7+
domain "github.com/alibabacloud-go/domain-20180129/v4/client"
8+
"github.com/alibabacloud-go/tea/tea"
69
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
710
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
811
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
@@ -21,6 +24,7 @@ type Provider struct {
2124
provider string
2225
config providerConfig
2326
ossClient *oss.Client
27+
domainClient *domain.Client
2428
ecsRegions *ecs.DescribeRegionsResponse
2529
rdsRegions *rds.DescribeRegionsResponse
2630
fcRegions []FcRegion
@@ -37,12 +41,13 @@ type providerConfig struct {
3741

3842
func New(options schema.OptionBlock, cs goflags.StringSlice) (*Provider, error) {
3943
var (
40-
region = "cn-beijing"
41-
ossClient *oss.Client
42-
ecsClient *ecs.Client
43-
rdsClient *rds.Client
44-
stsClient *sts.Client
45-
err error
44+
region = "cn-beijing"
45+
ossClient *oss.Client
46+
ecsClient *ecs.Client
47+
rdsClient *rds.Client
48+
stsClient *sts.Client
49+
domainClient *domain.Client
50+
err error
4651

4752
identity *sts.GetCallerIdentityResponse
4853
ecsRegions *ecs.DescribeRegionsResponse
@@ -167,12 +172,22 @@ func New(options schema.OptionBlock, cs goflags.StringSlice) (*Provider, error)
167172
}
168173

169174
gologger.Debug().Msgf("阿里云 FC 区域信息获取成功, 共 %d 个\n", len(fcRegions))
175+
176+
case "domain":
177+
// domain client
178+
credential := &openapi.Config{AccessKeyId: tea.String(accessKeyID), AccessKeySecret: tea.String(accessKeySecret),
179+
SecurityToken: tea.String(sessionToken)}
180+
domainClient, err = domain.NewClient(credential)
181+
if err != nil {
182+
return nil, err
183+
gologger.Debug().Msg("阿里云 Domain 客户端创建成功")
184+
}
170185
}
171186
}
172-
173187
return &Provider{
174188
provider: utils.Aliyun, id: id, config: config, identity: identity,
175189
ossClient: ossClient, ecsRegions: ecsRegions, rdsRegions: rdsRegions, fcRegions: fcRegions, cloudServices: cloudServices,
190+
domainClient: domainClient,
176191
}, nil
177192
}
178193

@@ -228,9 +243,17 @@ func (p *Provider) Resources(ctx context.Context, cs goflags.StringSlice) (*sche
228243
if err != nil {
229244
return nil, err
230245
}
231-
232246
gologger.Info().Msgf("获取到 %d 条阿里云 FC 信息", len(fcList.GetItems())+len(fc3List.GetItems()))
233247
finalList.Merge(fc3List)
248+
case "domain":
249+
// domain
250+
domainProvider := &domainProvider{id: p.id, provider: p.provider, domainClient: p.domainClient}
251+
domainList, err := domainProvider.GetResource(ctx)
252+
if err != nil {
253+
return nil, err
254+
}
255+
gologger.Info().Msgf("获取到 %d 条阿里云 Domain 信息", len(domainList.GetItems()))
256+
finalList.Merge(domainList)
234257
}
235258
}
236259
return finalList, nil

pkg/providers/aliyun/domain.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package aliyun
2+
3+
import (
4+
"context"
5+
domain "github.com/alibabacloud-go/domain-20180129/v4/client"
6+
util "github.com/alibabacloud-go/tea-utils/v2/service"
7+
"github.com/alibabacloud-go/tea/tea"
8+
"github.com/projectdiscovery/gologger"
9+
"github.com/wgpsec/lc/pkg/schema"
10+
)
11+
12+
type domainProvider struct {
13+
id string
14+
provider string
15+
domainClient *domain.Client
16+
}
17+
18+
func (d *domainProvider) GetResource(ctx context.Context) (*schema.Resources, error) {
19+
domainList := schema.NewResources()
20+
gologger.Debug().Msg("正在获取阿里云 Domain 资源信息")
21+
queryDomainListRequest := &domain.QueryDomainListRequest{
22+
PageNum: tea.Int32(1),
23+
PageSize: tea.Int32(10),
24+
}
25+
runtime := &util.RuntimeOptions{}
26+
response, err := d.domainClient.QueryDomainListWithOptions(queryDomainListRequest, runtime)
27+
if err != nil {
28+
return nil, err
29+
}
30+
for _, domainResult := range response.Body.Data.Domain {
31+
domainList.Append(&schema.Resource{
32+
ID: d.id,
33+
Public: true,
34+
DNSName: *domainResult.DomainName,
35+
Provider: d.provider,
36+
})
37+
}
38+
return domainList, nil
39+
}

0 commit comments

Comments
 (0)