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..0e8d867 100644 --- a/cmd/host.go +++ b/cmd/host.go @@ -5,14 +5,10 @@ import ( "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" - "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{ @@ -73,64 +69,30 @@ var keyListCmd = &cobra.Command{ }, } -func host() { - getLightHouse(regions.Singapore) - getHostByRegion(regions.Shanghai) - getHostByRegion(regions.Singapore) - getHostByRegion(regions.Nanjing) +func listPubKeys() { + hostAdmins := strings.Split(adblib.ConfigNew.HostUsers, ",") + adblib.GetGithubKeys(hostAdmins) } -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 +func host() { + client, err := aliyunConfigInit() + if err != nil { + panic(err) } - 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], - ) - } -} + request := alidns.CreateDescribeDomainRecordsRequest() + request.DomainName = HostDomain -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 + output, err := client.DescribeDomainRecords(request) + if err != nil { + fmt.Println(err) } - 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], - ) + 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) + } } } - -func listPubKeys() { - hostAdmins := strings.Split(adblib.ConfigNew.HostUsers, ",") - adblib.GetGithubKeys(hostAdmins) -} 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) } }