Skip to content

Commit

Permalink
Merge pull request #5 from wgpsec/dev
Browse files Browse the repository at this point in the history
feat: support lists aliyun rds services
  • Loading branch information
teamssix authored Apr 20, 2024
2 parents 544c274 + a956caf commit a30c359
Show file tree
Hide file tree
Showing 17 changed files with 375 additions and 54 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Change Log

## [v1.0.0](https://github.com/wgpsec/lc/releases/tag/v1.0.0)

* 支持列出阿里云 RDS 数据库服务
* 增加详细日志输出

## [v0.0.1](https://github.com/wgpsec/lc/releases/tag/v0.0.1) 2024.4.6

* 首次提交代码
46 changes: 24 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,18 @@ LC(List Cloud)是一个多云攻击面资产梳理的工具,使用 LC 可

### 支持列出的云服务

| 序号 | 云服务商 | 服务名称 |
| :--: | :------: | :---------------: |
| 1 | 阿里云 | ECS 云服务器 |
| 2 | 阿里云 | OSS 对象存储桶 |
| 3 | 腾讯云 | CVM 云服务器 |
| 4 | 腾讯云 | LH 轻量应用服务器 |
| 5 | 华为云 | OBS 对象存储 |
| 6 | 天翼云 | OOS 对象存储 |
| 7 | 百度云 | BOS 对象存储 |
| 8 | 百度云 | BCC 云服务器 |
| 9 | 联通云 | OSS 对象存储 |
| 序号 | 云服务商 | 服务名称 |
|:--:| :------: |:----------:|
| 1 | 阿里云 | ECS 云服务器 |
| 2 | 阿里云 | OSS 对象存储桶 |
| 3 | 阿里云 | RDS 数据库 |
| 4 | 腾讯云 | CVM 云服务器 |
| 5 | 腾讯云 | LH 轻量应用服务器 |
| 6 | 华为云 | OBS 对象存储 |
| 7 | 天翼云 | OOS 对象存储 |
| 8 | 百度云 | BOS 对象存储 |
| 9 | 百度云 | BCC 云服务器 |
| 10 | 联通云 | OSS 对象存储 |

## 使用手册

Expand Down Expand Up @@ -80,39 +81,40 @@ Usage:

Flags:
配置:
-c, -config string 指定配置文件路径 (default "$HOME/.config/lc/config.yaml")
-t, -threads int 指定扫描的线程数量 (default 3)
-c, -config string 指定配置文件路径 (default "$HOME/.config/lc/config.yaml")
-t, -threads int 指定扫描的线程数量 (default 3)

过滤:
-i, -id string[] 指定要使用的配置(以逗号分隔)
-p, -provider string[] 指定要使用的云服务商(以逗号分隔)
-ep, -exclude-private 从输出的结果中排除私有 IP
-i, -id string[] 指定要使用的配置(以逗号分隔)
-p, -provider string[] 指定要使用的云服务商(以逗号分隔)
-ep, -exclude-private 从输出的结果中排除私有 IP

输出:
-o, -output string 将结果输出到指定的文件中
-s, -silent 只输出结果
-v, -version 输出工具的版本
-o, -output string 将结果输出到指定的文件中
-s, -silent 只输出结果
-v, -version 输出工具的版本
-debug 输出调试日志信息
```

## 简单上手

在第一次使用时,LC 会在 `$HOME/.config/lc` 目录下创建一个 `config.yaml`,因此在第一次执行 `lc` 命令后,将您的云访问凭证填写到 `$HOME/.config/lc/config.yaml` 文件中后,就可以开始正式使用 LC 了。

直接运行 `lc` 命令来列举您的云上资产
直接运行 `lc` 命令来列举您的云上资产

```sh
lc
```

如果没有列举出结果,那么可能是因为本身云上没有资产,或者访问凭证的权限不足,这里我们建议为访问凭证赋予全局可读权限即可。

如果要排除结果中的内网 IP,只需要加上 `-ep` 参数
如果要排除结果中的内网 IP,只需要加上 `-ep` 参数

```sh
lc -ep
```

如果想把 LC 和其他工具结合使用,例如使用 httpx 检测资产是否能从公网访问,那么可以使用下面的命令
如果想把 LC 和其他工具结合使用,例如使用 httpx 检测资产是否能从公网访问,那么可以使用下面的命令

```sh
lc -ep -s | httpx -sc -title -silent
Expand Down
4 changes: 2 additions & 2 deletions cmd/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const banner = `
/_____/_/____/\__/ \____/_/\____/\__,_/\__,_/
`

const version = "0.0.1"
const versionDate = "2024-4-6"
const version = "1.0.0"
const versionDate = "2024-4-20"

func showBanner() {
gologger.Print().Msgf("%s\n", banner)
Expand Down
5 changes: 5 additions & 0 deletions cmd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
type Options struct {
Threads int // Threads 设置线程数量
Silent bool // Silent 只展示结果
Debug bool // Debug 显示详细的输出信息
Version bool // Version 返回工具版本
ExcludePrivate bool // ExcludePrivate 从结果中排除私有 IP
Config string // Config 指定配置文件路径
Expand Down Expand Up @@ -44,6 +45,7 @@ func ParseOptions() *Options {
flagSet.StringVarP(&options.Output, "output", "o", "", "将结果输出到指定的文件中"),
flagSet.BoolVarP(&options.Silent, "silent", "s", false, "只输出结果"),
flagSet.BoolVarP(&options.Version, "version", "v", false, "输出工具的版本"),
flagSet.BoolVar(&options.Debug, "debug", false, "输出调试日志信息"),
)
_ = flagSet.Parse()
options.configureOutput()
Expand All @@ -60,6 +62,9 @@ func (options *Options) configureOutput() {
if options.Silent {
gologger.DefaultLogger.SetMaxLevel(levels.LevelSilent)
}
if options.Debug {
gologger.DefaultLogger.SetMaxLevel(levels.LevelDebug)
}
}

func userHomeDir() string {
Expand Down
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/wgpsec/lc
go 1.22.1

require (
github.com/alibabacloud-go/tea v1.2.2
github.com/aliyun/alibaba-cloud-sdk-go v1.62.712
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible
github.com/aws/aws-sdk-go v1.51.16
Expand All @@ -19,6 +20,7 @@ require (
)

require (
github.com/alibabacloud-go/debug v1.0.0 // indirect
github.com/andybalholm/brotli v1.0.6 // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
Expand Down Expand Up @@ -49,7 +51,7 @@ require (
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
golang.org/x/mod v0.12.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/net v0.20.0 // indirect
golang.org/x/sys v0.17.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/time v0.5.0 // indirect
Expand Down
39 changes: 37 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo=
github.com/ajstarks/svgo v0.0.0-20180226025133-644b8db467af/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
github.com/alibabacloud-go/debug v1.0.0 h1:3eIEQWfay1fB24PQIEzXAswlVJtdQok8f3EVN5VrBnA=
github.com/alibabacloud-go/debug v1.0.0/go.mod h1:8gfgZCCAC3+SCzjWtY053FrOcd4/qlH6IHTI4QyICOc=
github.com/alibabacloud-go/tea v1.2.2 h1:aTsR6Rl3ANWPfqeQugPglfurloyBJY85eFy7Gc1+8oU=
github.com/alibabacloud-go/tea v1.2.2/go.mod h1:CF3vOzEMAG+bR4WOql8gc2G9H3EkH3ZLAQdpmpXMgwk=
github.com/aliyun/alibaba-cloud-sdk-go v1.62.712 h1:lM7JnA9dEdDFH9XOgRNQMDTQnOjlLkDTNA7c0aWTQ30=
github.com/aliyun/alibaba-cloud-sdk-go v1.62.712/go.mod h1:SOSDHfe1kX91v3W5QiBsWSLqeLxImobbMX1mxrFHsVQ=
github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible h1:8psS8a+wKfiLt1iVDX79F7Y6wUM49Lcha2FMXt4UM8g=
Expand Down Expand Up @@ -123,10 +127,13 @@ github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
go.uber.org/atomic v1.9.0 h1:ECmE8Bn/WFTYwEW/bpKD3M8VtR/zQVbavAoalC1PYyE=
go.uber.org/atomic v1.9.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/exp v0.0.0-20180321215751-8460e604b9de/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20180807140117-3d87b88a115f/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
Expand All @@ -139,28 +146,56 @@ golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMx
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
golang.org/x/tools v0.0.0-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/tools v0.13.0 h1:Iey4qkscZuv0VvIt8E0neZjtPVQFSc870HQ448QgEmQ=
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
69 changes: 58 additions & 11 deletions pkg/providers/aliyun/aliyun.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import (
"github.com/aliyun/alibaba-cloud-sdk-go/sdk"
"github.com/aliyun/alibaba-cloud-sdk-go/sdk/auth/credentials"
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
"github.com/aliyun/alibaba-cloud-sdk-go/services/rds"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
"github.com/projectdiscovery/gologger"
"github.com/wgpsec/lc/pkg/schema"
"github.com/wgpsec/lc/utils"
)

type Provider struct {
id string
provider string
config providerConfig
ossClient *oss.Client
regions *ecs.DescribeRegionsResponse
id string
provider string
config providerConfig
ossClient *oss.Client
ecsRegions *ecs.DescribeRegionsResponse
rdsRegions *rds.DescribeRegionsResponse
}

type providerConfig struct {
Expand All @@ -30,6 +33,7 @@ func New(options schema.OptionBlock) (*Provider, error) {
var (
region = "cn-beijing"
ecsClient *ecs.Client
rdsClient *rds.Client
err error
)
accessKeyID, ok := options.GetMetadata(utils.AccessKey)
Expand All @@ -49,6 +53,11 @@ func New(options schema.OptionBlock) (*Provider, error) {
sessionToken: sessionToken,
okST: okST,
}
if okST {
gologger.Debug().Msg("找到阿里云访问临时访问凭证")
} else {
gologger.Debug().Msg("找到阿里云访问永久访问凭证")
}

// oss client
ossClient, err := oss.New(fmt.Sprintf("oss-%s.aliyuncs.com", region), accessKeyID, accessKeySecret)
Expand All @@ -58,6 +67,7 @@ func New(options schema.OptionBlock) (*Provider, error) {
if okST {
ossClient.Config.SecurityToken = sessionToken
}
gologger.Debug().Msg("阿里云 OSS 客户端创建成功")

// ecs client
ecsConfig := sdk.NewConfig()
Expand All @@ -74,28 +84,65 @@ func New(options schema.OptionBlock) (*Provider, error) {
return nil, err
}
}
// regions
regions, err := ecsClient.DescribeRegions(ecs.CreateDescribeRegionsRequest())
gologger.Debug().Msg("阿里云 ECS 客户端创建成功")
// ecs regions
ecsRegions, err := ecsClient.DescribeRegions(ecs.CreateDescribeRegionsRequest())
if err != nil {
return nil, err
}
gologger.Debug().Msg("阿里云 ECS 区域信息获取成功")

// rds client
rdsConfig := sdk.NewConfig()
if okST {
credential := credentials.NewStsTokenCredential(accessKeyID, accessKeySecret, sessionToken)
rdsClient, err = rds.NewClientWithOptions(region, rdsConfig, credential)
if err != nil {
return nil, err
}
} else {
credential := credentials.NewAccessKeyCredential(accessKeyID, accessKeySecret)
rdsClient, err = rds.NewClientWithOptions(region, rdsConfig, credential)
if err != nil {
return nil, err
}
}
gologger.Debug().Msg("阿里云 RDS 客户端创建成功")

//rds regions
rdsRegions, err := rdsClient.DescribeRegions(rds.CreateDescribeRegionsRequest())
if err != nil {
return nil, err
}
return &Provider{provider: utils.Aliyun, id: id, ossClient: ossClient, regions: regions, config: config}, nil
gologger.Debug().Msg("阿里云 RDS 区域信息获取成功")

return &Provider{provider: utils.Aliyun, id: id, ossClient: ossClient, ecsRegions: ecsRegions, rdsRegions: rdsRegions, config: config}, nil
}

func (p *Provider) Resources(ctx context.Context) (*schema.Resources, error) {
var err error
ecsProvider := &instanceProvider{id: p.id, provider: p.provider, regions: p.regions, config: p.config}
list, err := ecsProvider.GetResource(ctx)
ecsProvider := &instanceProvider{id: p.id, provider: p.provider, ecsRegions: p.ecsRegions, config: p.config}
ecsList, err := ecsProvider.GetEcsResource(ctx)
gologger.Info().Msgf("获取到 %d 条阿里云 ECS 信息", len(ecsList.Items))
if err != nil {
return nil, err
}
rdsProvider := &dbInstanceProvider{id: p.id, provider: p.provider, rdsRegions: p.rdsRegions, config: p.config}
rdsList, err := rdsProvider.GetRdsResource(ctx)
if err != nil {
return nil, err
}
gologger.Info().Msgf("获取到 %d 条阿里云 RDS 信息", len(rdsList.Items))
ossProvider := &ossProvider{ossClient: p.ossClient, id: p.id, provider: p.provider}
buckets, err := ossProvider.GetResource(ctx)
if err != nil {
return nil, err
}
gologger.Info().Msgf("获取到 %d 条阿里云 OSS 信息", len(buckets.Items))

finalList := schema.NewResources()
finalList.Merge(list)
finalList.Merge(ecsList)
finalList.Merge(rdsList)
finalList.Merge(buckets)
return finalList, nil
}
Expand Down
Loading

0 comments on commit a30c359

Please sign in to comment.