Skip to content

Commit 5ad7201

Browse files
committed
add lg
1 parent c7f9e73 commit 5ad7201

File tree

4 files changed

+89
-4
lines changed

4 files changed

+89
-4
lines changed

cmd/host.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/airdb/adb/internal/adblib"
78
"github.com/airdb/sailor"
89
"github.com/airdb/sailor/osutil"
910
"github.com/aliyun/alibaba-cloud-sdk-go/services/alidns"
1011
"github.com/spf13/cobra"
12+
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common"
13+
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors"
14+
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"
15+
"github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/regions"
16+
cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312"
17+
lh "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse/v20200324"
1118
)
1219

1320
var hostCmd = &cobra.Command{
@@ -60,10 +67,68 @@ var hostListCmd = &cobra.Command{
6067
DisableFlagParsing: true,
6168
Run: func(cmd *cobra.Command, args []string) {
6269
host()
70+
hostDNS()
6371
},
6472
}
6573

6674
func host() {
75+
getLightHouse(regions.Singapore)
76+
getHostByRegion(regions.Shanghai)
77+
getHostByRegion(regions.Singapore)
78+
getHostByRegion(regions.Nanjing)
79+
}
80+
81+
func getHostByRegion(region string) {
82+
credential := common.NewCredential(adblib.AdbConfig.TencentyunAccessKeyID, adblib.AdbConfig.TencentyunAccessKeySecret)
83+
client, _ := cvm.NewClient(credential, region, profile.NewClientProfile())
84+
85+
request := cvm.NewDescribeInstancesRequest()
86+
output, err := client.DescribeInstances(request)
87+
88+
if _, ok := err.(*errors.TencentCloudSDKError); ok {
89+
fmt.Printf("An API error has returned: %s", err)
90+
91+
return
92+
}
93+
94+
for _, instance := range output.Response.InstanceSet {
95+
fmt.Printf("%s\t%s\t%s\t%s\t%s\t%s\n",
96+
*instance.InstanceId,
97+
*instance.ExpiredTime,
98+
region,
99+
*instance.InstanceName,
100+
*instance.PublicIpAddresses[0],
101+
*instance.PrivateIpAddresses[0],
102+
)
103+
}
104+
}
105+
106+
func getLightHouse(region string) {
107+
credential := common.NewCredential(adblib.AdbConfig.TencentyunAccessKeyID, adblib.AdbConfig.TencentyunAccessKeySecret)
108+
client, _ := lh.NewClient(credential, region, profile.NewClientProfile())
109+
110+
request := lh.NewDescribeInstancesRequest()
111+
output, err := client.DescribeInstances(request)
112+
113+
if _, ok := err.(*errors.TencentCloudSDKError); ok {
114+
fmt.Printf("An API error has returned: %s", err)
115+
116+
return
117+
}
118+
119+
for _, instance := range output.Response.InstanceSet {
120+
fmt.Printf("%s\t%s\t%s\t%s\t%s\t%s\n",
121+
*instance.InstanceId,
122+
*instance.ExpiredTime,
123+
region,
124+
*instance.InstanceName,
125+
*instance.PublicAddresses[0],
126+
*instance.PrivateAddresses[0],
127+
)
128+
}
129+
}
130+
131+
func hostDNS() {
67132
client, err := aliyunConfigInit()
68133
if err != nil {
69134
panic(err)

go.mod

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ require (
1717
github.com/slack-go/slack v0.6.5
1818
github.com/spf13/cobra v1.1.1
1919
github.com/spf13/viper v1.7.0
20-
github.com/tencentcloud/tencentcloud-sdk-go v1.0.12
20+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.248
21+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.248
22+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.248
23+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.248
24+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.248
2125
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect
2226
)
2327

go.sum

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,16 @@ github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05
350350
github.com/swaggo/swag v1.5.1/go.mod h1:1Bl9F/ZBpVWh22nY0zmYyASPO1lI/zIwRDrpZU+tv8Y=
351351
github.com/syndtr/goleveldb v0.0.0-20160425020131-cfa635847112/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
352352
github.com/syndtr/goleveldb v0.0.0-20181127023241-353a9fca669c/go.mod h1:Z4AUp2Km+PwemOoO/VB5AOx9XSsIItzFjoJlOSiYmn0=
353-
github.com/tencentcloud/tencentcloud-sdk-go v1.0.12 h1:ABgTcYxBePz5rlueSYpwFHImNq2NCnrjmx21jIXLbyM=
354-
github.com/tencentcloud/tencentcloud-sdk-go v1.0.12/go.mod h1:asUz5BPXxgoPGaRgZaVm1iGcUAuHyYUo1nXqKa83cvI=
353+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.248 h1:PKaRMwdCx526FFmZMz9lQx6WUSja0s/x6kvmv29FDzY=
354+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/apigateway v1.0.248/go.mod h1:ynirFavajqWLAcgEp9ZiMd9xn5JnKTJhQisArjMxNtk=
355+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.248 h1:ifD7EkvPj8syx5lRPvJxXfkRn4SkkPqweN3zM1WIuiA=
356+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.248/go.mod h1:zgARzAnsLzpLhdpAHrHTUilOXytH9aEJy5ssCdizVV0=
357+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.248 h1:o7TaorFpZ4gCUCUlgGgbeSjv7tODqdympDDRP4w9z1o=
358+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.248/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
359+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.248 h1:woET0ix+B4g/0kargmAfLkp1y2vVA8dFE1zHeTfIt+4=
360+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.248/go.mod h1:AqyM/ZZMD7q5mHBqNY9YImbSpEpoEe7E/vrTbUWX+po=
361+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.248 h1:rrHp0C26Qv1rpW0c+RaaeGY8HTuMSRFU/guQHK2Jn4A=
362+
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.248/go.mod h1:r8txjlw4DjLDZFOpnPC/hOFHr1VckZc0jjBK6XIFLP0=
355363
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
356364
github.com/ugorji/go v0.0.0-20171122102828-84cb69a8af83/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
357365
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=

internal/adblib/config.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,5 +224,13 @@ func InitDotEnv() {
224224
log.Fatal("Error loading .env file ", EnvFile, err)
225225
}
226226

227-
AdbConfig.AliyunAccessKeyID = os.Getenv("AliyunAccessKeyID")
227+
AdbConfig = CFG{
228+
TencentyunAccessKeyID: os.Getenv("TencentyunAccessKeyID"),
229+
TencentyunAccessKeySecret: os.Getenv("TencentyunAccessKeySecret"),
230+
TencentyunRegionID: os.Getenv("TencentyunRegionID"),
231+
AliyunAccessKeyID: os.Getenv("AliyunAccessKeyID"),
232+
AliyunAccessKeySecret: os.Getenv("AliyunAccessKeySecret"),
233+
AliyunRegionID: os.Getenv("AliyunRegionID"),
234+
}
235+
// AdbConfig.AliyunAccessKeyID = os.Getenv("AliyunAccessKeyID")
228236
}

0 commit comments

Comments
 (0)