Skip to content

Commit

Permalink
Merge pull request #34 from airdb/dev
Browse files Browse the repository at this point in the history
dev
  • Loading branch information
deancn authored Sep 9, 2020
2 parents 858de41 + 80f19fe commit c480d51
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 12 deletions.
13 changes: 12 additions & 1 deletion cmd/bbhj.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"github.com/airdb/adb/internal/adblib"

"github.com/spf13/cobra"
)
Expand All @@ -12,6 +13,16 @@ var bbhjCommand = &cobra.Command{
Long: "bbhj operation",
DisableFlagParsing: true,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("bbhj operation")
bbhj()
},
}

func bbhj() {
client, err := adblib.NewCLBClient()
if err != nil {
fmt.Println(err)
return
}

client.ListCLB()
}
4 changes: 2 additions & 2 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ var loginWithToken bool
func initLogin() {
rootCmd.AddCommand(loginCommand)

// hostSSHCmd.PersistentFlags().StringVarP(&sshFlags.IdentityFile,
// "identity_file", "i", "~/.adb/id_rsa", "identity file")
loginCommand.PersistentFlags().BoolVarP(&loginWithToken, "token", "t", false, "login with token")

// hostSSHCmd.PersistentFlags().StringVarP(&sshFlags.IdentityFile, "identity_file", "i", "~/.adb/id_rsa", "identity file")
}

func login() {
Expand Down
3 changes: 3 additions & 0 deletions cmd/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"github.com/airdb/adb/internal/adblib"
"strings"

"github.com/airdb/sailor"
Expand All @@ -15,6 +16,7 @@ var mysqlCmd = &cobra.Command{
Long: "Airdb mysql client",
DisableFlagParsing: false,
Args: cobra.MinimumNArgs(1),
Example: adblib.SqlDoc,
Aliases: []string{"sql"},
Run: func(cmd *cobra.Command, args []string) {
mysql(args)
Expand Down Expand Up @@ -49,6 +51,7 @@ func mysql(args []string) {
request.DomainName = ServiceDomain
request.RRKeyWord = args[0]

fmt.Println(request.RRKeyWord)
output, err := client.DescribeDomainRecords(request)
if err != nil {
fmt.Println(err)
Expand Down
11 changes: 7 additions & 4 deletions cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ package cmd
import (
"fmt"

"github.com/airdb/adb/internal/adblib"

"github.com/airdb/sailor"
"github.com/aliyun/alibaba-cloud-sdk-go/services/alidns"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -74,10 +76,11 @@ func service() {
var servicesAddCmdMinArgs = 2

var servicesAddCmd = &cobra.Command{
Use: "add [service] [SRV record value]",
Short: "Add service",
Long: "Add service",
Args: cobra.MinimumNArgs(servicesAddCmdMinArgs),
Use: "add [service] [SRV record value]",
Short: "Add service",
Long: "Add service",
Example: adblib.DNSSrvDoc,
Args: cobra.MinimumNArgs(servicesAddCmdMinArgs),
Run: func(cmd *cobra.Command, args []string) {
addService(args)
},
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ require (
github.com/slack-go/slack v0.6.5
github.com/spf13/cobra v1.0.0
github.com/spf13/viper v1.4.0
github.com/tencentcloud/tencentcloud-sdk-go v1.0.12
golang.org/x/sys v0.0.0-20200523222454-059865788121 // indirect
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWX
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/airdb/sailor v1.1.2-0.20200802151610-a033b3f2a246 h1:5URmvEzDlQ5RoyiyUvrX5Ao5F7nlycdbUKoGuiVecjA=
github.com/airdb/sailor v1.1.2-0.20200802151610-a033b3f2a246/go.mod h1:Txr7LHYpg61npbaDGkfud/lRaOFEaAB1f0anzuglOmI=
github.com/airdb/sailor v1.4.0-85dfa77 h1:ieXE0OhZKknCUZU3vi2bcYoWLt3BAiFDKosBTHH35pI=
github.com/airdb/sailor v1.4.0-85dfa77/go.mod h1:Txr7LHYpg61npbaDGkfud/lRaOFEaAB1f0anzuglOmI=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/aliyun/alibaba-cloud-sdk-go v1.61.279 h1:y/fx2Tc2JCJ92exFGxtytxUOJfInHCNLuk/7Bbmbgz0=
Expand Down Expand Up @@ -235,6 +233,8 @@ github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJy
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05Nn6vPhc7OI=
github.com/swaggo/swag v1.5.1/go.mod h1:1Bl9F/ZBpVWh22nY0zmYyASPO1lI/zIwRDrpZU+tv8Y=
github.com/tencentcloud/tencentcloud-sdk-go v1.0.12 h1:ABgTcYxBePz5rlueSYpwFHImNq2NCnrjmx21jIXLbyM=
github.com/tencentcloud/tencentcloud-sdk-go v1.0.12/go.mod h1:asUz5BPXxgoPGaRgZaVm1iGcUAuHyYUo1nXqKa83cvI=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/ugorji/go v1.1.5-pre/go.mod h1:FwP/aQVg39TXzItUBMwnWp9T9gPQnXw4Poh4/oBQZ/0=
Expand Down
16 changes: 16 additions & 0 deletions internal/adblib/dns.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package adblib

import (
"github.com/MakeNowJust/heredoc"
)

var (
DNSSrvDoc = heredoc.Doc(`
$ adb srv add _sip._tcp "10 60 443 bigbox.airdb.red"
$ adb srv add _sip._tcp "10 20 443 smallbox1.airdb.blue"
$ adb srv add _sip._tcp "10 20 443 smallbox2.airdb.green"
$ adb srv add _sip._tcp "20 0 443 backup.airdb.black"
> Refer: https://zh.wikipedia.org/wiki/SRV记录
`)
)
11 changes: 11 additions & 0 deletions internal/adblib/example.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package adblib

import (
"github.com/MakeNowJust/heredoc"
)

var (
SqlDoc = heredoc.Doc(`
adb mysql mina-api -uroot -ppasswd --db test
`)
)
4 changes: 3 additions & 1 deletion internal/adblib/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ func LoginWithToken() {

bar.NewOption(0, 100)

var sleepInterval time.Duration = 100

for i := 0; i <= 100; i++ {
time.Sleep(100 * time.Millisecond)
time.Sleep(sleepInterval * time.Millisecond)
bar.Play(int64(i))
}

Expand Down
8 changes: 8 additions & 0 deletions internal/adblib/man.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,14 @@ $ Github or Git Command:
brew install github/gh/gh
gh --repo bbhj/lbs issue status
gh --repo bbhj/lbs issue view 1
5. Delete branch or tag
git branch -D dev
git push origin --delete dev
git tag -d v1.0
git push --delete origin v1.0
`)

OpenSSLDoc = heredoc.Doc(`
Expand Down
91 changes: 91 additions & 0 deletions internal/adblib/tencentcloud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package adblib

import (
"fmt"
"os"

clb "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb/v20180317"
"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"
)

const CLBEndpoint = "clb.tencentcloudapi.com"

type Client struct {
*clb.Client
}

func NewCLBClient() (*Client, error) {
secretID := os.Getenv("TENCENTCLOUD_SECRET_ID")
secretKey := os.Getenv("TENCENTCLOUD_SECRET_KEY")
region := os.Getenv("TENCENTCLOUD_REGION")

credential := common.NewCredential(secretID, secretKey)

cpf := profile.NewClientProfile()
cpf.HttpProfile.Endpoint = CLBEndpoint

client, err := clb.NewClient(credential, region, cpf)

return &Client{
client,
}, err
}

func (client *Client) ListCLB() {
request := clb.NewDescribeLoadBalancersRequest()

params := "{}"
err := request.FromJsonString(params)
if err != nil {
panic(err)
}
response, err := client.DescribeLoadBalancers(request)
if _, ok := err.(*errors.TencentCloudSDKError); ok {
fmt.Printf("An API error has returned: %s", err)
return
}
if err != nil {
panic(err)
}

for _, lbSet := range response.Response.LoadBalancerSet {
// fmt.Println(*lbSet.LoadBalancerId)
client.ShowRS(*lbSet.LoadBalancerId)
}
}

func (client *Client) ShowRS(lbID string) {

request := clb.NewDescribeTargetsRequest()

params := fmt.Sprintf("{\"LoadBalancerId\":\"%s\"}", lbID)
err := request.FromJsonString(params)
if err != nil {
panic(err)
}
response, err := client.DescribeTargets(request)
if _, ok := err.(*errors.TencentCloudSDKError); ok {
fmt.Printf("An API error has returned: %s", err)
return
}
if err != nil {
panic(err)
}

// fmt.Printf("%s", response.ToJsonString())
for _, listener := range response.Response.Listeners {
for _, rule := range listener.Rules {
for _, target := range rule.Targets {
fmt.Printf("%s%s\t%d\t%s\t%s\n",
*rule.Domain,
*rule.Url,
*target.Weight,
*target.InstanceId,
*target.InstanceName,
)
}
}
}
}
3 changes: 1 addition & 2 deletions internal/adblib/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
)

var TokenRequest = heredoc.Doc(`
https://sfc.baobeihuijia.com/release/oauth2/token?request_id=f572d396fae9206628714fb2ce00f72e94f2258f
https://scf.baobeihuijia.com/release/oauth2/token?request_id=f572d396fae9206628714fb2ce00f72e94f2258f
please login with Github, and wait for 30s after you login.
`)

0 comments on commit c480d51

Please sign in to comment.