From 99440a0cb26de8764382bd3bcb06540707fca0c0 Mon Sep 17 00:00:00 2001 From: dean Date: Sat, 16 Aug 2025 23:14:35 +0800 Subject: [PATCH 1/2] chore: remove qcloud --- build/util.sh | 3 +- cmd/host.go | 61 --------------------------------------- go.mod | 4 +-- internal/adblib/github.go | 7 ++++- 4 files changed, 9 insertions(+), 66 deletions(-) diff --git a/build/util.sh b/build/util.sh index a4cf82c..dee983a 100644 --- a/build/util.sh +++ b/build/util.sh @@ -11,7 +11,8 @@ LDFLAGS="-s -w \ -X=github.com/airdb/adb/internal/adblib.BuildTime=$BUILD_TS" function until::build() { - CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$LDFLAGS" -o ./output/adb main.go + #CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags "$LDFLAGS" -o ./output/adb main.go + CGO_ENABLED=0 GOOS=linux go build -ldflags "$LDFLAGS" -o ./output/adb main.go } $1 diff --git a/cmd/host.go b/cmd/host.go index aac7211..33577c8 100644 --- a/cmd/host.go +++ b/cmd/host.go @@ -1,18 +1,11 @@ package cmd import ( - "fmt" "strings" "github.com/airdb/adb/internal/adblib" _ "github.com/joho/godotenv/autoload" "github.com/spf13/cobra" - "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common" - "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors" - "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile" - "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/regions" - cvm "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm/v20170312" - lh "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse/v20200324" ) var hostCmd = &cobra.Command{ @@ -74,60 +67,6 @@ var keyListCmd = &cobra.Command{ } func host() { - getLightHouse(regions.Singapore) - getHostByRegion(regions.Shanghai) - getHostByRegion(regions.Singapore) - getHostByRegion(regions.Nanjing) -} - -func getHostByRegion(region string) { - credential := common.NewCredential(adblib.AdbConfig.TencentyunAccessKeyID, adblib.AdbConfig.TencentyunAccessKeySecret) - client, _ := cvm.NewClient(credential, region, profile.NewClientProfile()) - - request := cvm.NewDescribeInstancesRequest() - output, err := client.DescribeInstances(request) - - if _, ok := err.(*errors.TencentCloudSDKError); ok { - fmt.Printf("An API error has returned: %s", err) - - return - } - - for _, instance := range output.Response.InstanceSet { - fmt.Printf("%s\t%s\t%s\t%s\t%s\t%s\n", - *instance.InstanceId, - *instance.ExpiredTime, - region, - *instance.InstanceName, - *instance.PublicIpAddresses[0], - *instance.PrivateIpAddresses[0], - ) - } -} - -func getLightHouse(region string) { - credential := common.NewCredential(adblib.AdbConfig.TencentyunAccessKeyID, adblib.AdbConfig.TencentyunAccessKeySecret) - client, _ := lh.NewClient(credential, region, profile.NewClientProfile()) - - request := lh.NewDescribeInstancesRequest() - output, err := client.DescribeInstances(request) - - if _, ok := err.(*errors.TencentCloudSDKError); ok { - fmt.Printf("An API error has returned: %s", err) - - return - } - - for _, instance := range output.Response.InstanceSet { - fmt.Printf("%s\t%s\t%s\t%s\t%s\t%s\n", - *instance.InstanceId, - *instance.ExpiredTime, - region, - *instance.InstanceName, - *instance.PublicAddresses[0], - *instance.PrivateAddresses[0], - ) - } } func listPubKeys() { diff --git a/go.mod b/go.mod index 5d2067f..fc7a6c7 100644 --- a/go.mod +++ b/go.mod @@ -1,8 +1,6 @@ module github.com/airdb/adb -go 1.23.0 - -toolchain go1.24.1 +go 1.25 require ( github.com/AlecAivazis/survey/v2 v2.3.7 diff --git a/internal/adblib/github.go b/internal/adblib/github.go index ef7fc03..666fbef 100644 --- a/internal/adblib/github.go +++ b/internal/adblib/github.go @@ -4,6 +4,7 @@ import ( "bufio" "fmt" "net/http" + "strings" ) func GetGithubKeysByID(id string) { @@ -16,7 +17,11 @@ func GetGithubKeysByID(id string) { scanner := bufio.NewScanner(resp.Body) for i := 0; scanner.Scan() && i < 3; i++ { - fmt.Printf("%s https://github.com/%s\n", scanner.Text(), id) + if !strings.HasPrefix(scanner.Text(), "ssh-ed25519") { + continue + } + + fmt.Printf("%s https://github.com/%s.keys\n", scanner.Text(), id) } } From 122c393d7170cb3e2c1e6d068a63f9731942d5c5 Mon Sep 17 00:00:00 2001 From: dean Date: Sat, 16 Aug 2025 23:18:12 +0800 Subject: [PATCH 2/2] chore: remove qcloud --- cmd/host.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/cmd/host.go b/cmd/host.go index 33577c8..0e8d867 100644 --- a/cmd/host.go +++ b/cmd/host.go @@ -1,10 +1,13 @@ package cmd import ( + "fmt" "strings" "github.com/airdb/adb/internal/adblib" + "github.com/aliyun/alibaba-cloud-sdk-go/services/alidns" _ "github.com/joho/godotenv/autoload" + "github.com/miekg/dns" "github.com/spf13/cobra" ) @@ -66,10 +69,30 @@ var keyListCmd = &cobra.Command{ }, } -func host() { -} - func listPubKeys() { hostAdmins := strings.Split(adblib.ConfigNew.HostUsers, ",") adblib.GetGithubKeys(hostAdmins) } + +func host() { + client, err := aliyunConfigInit() + if err != nil { + panic(err) + } + + request := alidns.CreateDescribeDomainRecordsRequest() + request.DomainName = HostDomain + + output, err := client.DescribeDomainRecords(request) + if err != nil { + fmt.Println(err) + } + + for _, rr := range output.DomainRecords.Record { + // fmt.Printf("%-20s %-5s %-32s %-64s %s\n", rr.RecordId, rr.Type, rr.RR, rr.Value, rr.Remark) + if rr.Type == dns.TypeToString[dns.TypeA] { + // fmt.Printf("%-20s\t%-32s\t%s\n", rr.RecordId, rr.RR, rr.Value) + fmt.Printf("%-20s %-5s %-32s %-64s %s\n", rr.RecordId, rr.Type, rr.RR, rr.Value, rr.Remark) + } + } +}