Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build/util.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
78 changes: 20 additions & 58 deletions cmd/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 6 additions & 1 deletion internal/adblib/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bufio"
"fmt"
"net/http"
"strings"
)

func GetGithubKeysByID(id string) {
Expand All @@ -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)
}
}

Expand Down
Loading