Skip to content

Commit

Permalink
feat: upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
deancn committed Dec 1, 2024
1 parent 7c0e24a commit b16e8a3
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 747 deletions.
3 changes: 1 addition & 2 deletions cmd/cert.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.
package cmd

import (
"github.com/airdb/adb/internal/adblib"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -51,5 +50,5 @@ func initCert() {
}

func opCert(args []string) {
adblib.HandlerCert(certFlag.PrivateKeyFile, certFlag.PublicKeyFile)
// adblib.HandlerCert(certFlag.PrivateKeyFile, certFlag.PublicKeyFile)
}
78 changes: 0 additions & 78 deletions cmd/config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package cmd

import (
"fmt"
"io"
"os"
"path"

"github.com/MakeNowJust/heredoc"
"github.com/airdb/adb/internal/adblib"
"github.com/mitchellh/go-homedir"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -70,78 +67,3 @@ Current respected settings:
- editor: if unset, defaults to environment variables.
`,
}

var configGetCmd = &cobra.Command{
Use: "get <key>",
Short: "Print the value of a given configuration key",
Example: heredoc.Doc(`
$ adb config get aliyun
access_key_id: xxxxxxxxxxxx_id
access_key_secret: xxxxxxxxxxxx_secret
region_id: cn-hangzhou
`),
Args: cobra.ExactArgs(1),
RunE: configGet,
}

var configSetCmd = &cobra.Command{
Use: "set <key> <value>",
Short: "Update configuration with a value for the given key",
Example: heredoc.Doc(`
$ adb config set aliyun
[aliyun]
? access_key_id: xxxxxxxxxxxx_id
? access_key_secret: xxxxxxxxxxxx_secret
? region_id: (cn-hangzhou)
`),
Args: cobra.ExactArgs(1),
RunE: configSet,
}

func initConfigCmd() {
rootCmd.AddCommand(configCmd)
configCmd.AddCommand(configGetCmd)
configCmd.AddCommand(configSetCmd)
}

func configSet(cmd *cobra.Command, args []string) error {
service := args[0]

switch service {
case adblib.ServiceAliyun:
err := adblib.SetAliyunConfig()
if err != nil {
fmt.Println("configure failed, error: ", err)

return err
}
case adblib.ServiceSlack:
err := adblib.SetSlackConfig()
if err != nil {
fmt.Println("configure failed, error: ", err)

return err
}
}

fmt.Println("configure successfully.")

return nil
}

func configGet(cmd *cobra.Command, args []string) error {
service := args[0]

switch service {
case "aliyun":
fmt.Printf("access_key_id: %s\naccess_key_secret: %s\nregion_id: %s\n",
adblib.AdbConfig.AliyunAccessKeyID,
adblib.AdbConfig.AliyunAccessKeySecret,
adblib.AdbConfig.AliyunRegionID,
)
default:
fmt.Println(adblib.AdbConfig)
}

return nil
}
2 changes: 1 addition & 1 deletion cmd/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"strings"
"time"

"github.com/airdb/sailor/osutil"
"github.com/airdb/toolbox/osutil"
"github.com/aliyun/alibaba-cloud-sdk-go/services/alidns"
"github.com/go-sql-driver/mysql"
"github.com/miekg/dns"
Expand Down
3 changes: 1 addition & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ func Execute() {
rootCmd.AddCommand(weatherCommand)
rootCmd.AddCommand(wikiCommand)
wikiCommand.AddCommand(interviewWikiCommand)
wikiCommand.AddCommand(listWikiCommand)

mysqlCmdInit()
serviceCmdInit()
hostCmdInit()

initConfigCmd()
// initConfigCmd()
initCert()
initSlack()
initManCommand()
Expand Down
4 changes: 2 additions & 2 deletions cmd/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
"fmt"

"github.com/airdb/adb/internal/adblib"
"github.com/airdb/sailor"
"github.com/airdb/toolbox/typeutil"
"github.com/aliyun/alibaba-cloud-sdk-go/services/alidns"
"github.com/miekg/dns"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -79,7 +79,7 @@ func service() {
}

for _, rr := range output.DomainRecords.Record {
if rr.RR == sailor.DelimiterStar || rr.RR == sailor.DelimiterAt {
if rr.RR == typeutil.DelimiterStar || rr.RR == typeutil.DelimiterAt {
continue
}

Expand Down
45 changes: 0 additions & 45 deletions cmd/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ package cmd

import (
"bytes"
"encoding/json"
"fmt"
"log"
"os/exec"
"sort"
"strings"

"github.com/imroc/req"
"github.com/spf13/cobra"
)

Expand All @@ -26,7 +22,6 @@ func Usage() {
fmt.Println("Usage:")
fmt.Println(" adb wiki [project_name]")
fmt.Println()
listRepos()
fmt.Println()
fmt.Printf("Airdb Wiki: %s.\n", AirdbWiki)
}
Expand All @@ -37,37 +32,6 @@ type Repo struct {
Name string `json:"name"`
}

func listRepos() {
apiurl := "https://api.github.com/orgs/airdb-wiki/repos"

resp, err := req.Get(apiurl)
if err != nil {
log.Println("Query Github failed. https://github.com/airdb/airdb-wiki")

return
}

repos := make([]Repo, 0)

err = json.Unmarshal(resp.Bytes(), &repos)
if err != nil {
log.Println("json unmarshall failed.")

return
}

sort.Slice(repos, func(i, j int) bool { return len(repos[i].Name) < len(repos[j].Name) })
fmt.Println("Projects:")

for _, repo := range repos {
switch repo.Name {
case strings.TrimPrefix(AirdbWiki, "https"):
default:
fmt.Printf("\t%s\t%30s\n", repo.Name, AirdbWiki+repo.Name)
}
}
}

func wiki(wikiName string) {
wikiArgs := getWikiArgs(wikiName)
cmd := exec.Command("open", wikiArgs...)
Expand Down Expand Up @@ -106,12 +70,3 @@ var interviewWikiCommand = &cobra.Command{
wiki(name)
},
}

var listWikiCommand = &cobra.Command{
Use: "list",
Short: "list wiki",
Long: "list wiki",
Run: func(cmd *cobra.Command, args []string) {
listRepos()
},
}
70 changes: 33 additions & 37 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,81 +2,77 @@ module github.com/airdb/adb

go 1.23

toolchain go1.23.3

require (
github.com/AlecAivazis/survey/v2 v2.3.6
github.com/AlecAivazis/survey/v2 v2.3.7
github.com/MakeNowJust/heredoc v1.0.0
github.com/airdb/sailor v0.0.12
github.com/aliyun/alibaba-cloud-sdk-go v1.62.326
github.com/go-chi/chi/v5 v5.1.0
github.com/go-redis/redis/v8 v8.11.5
github.com/go-sql-driver/mysql v1.7.1
github.com/airdb/toolbox v0.0.0-20241117194613-1155835d94bf
github.com/aliyun/alibaba-cloud-sdk-go v1.63.60
github.com/go-sql-driver/mysql v1.8.1
github.com/imroc/req v0.3.2
github.com/joho/godotenv v1.5.1
github.com/miekg/dns v1.1.54
github.com/miekg/dns v1.1.62
github.com/minio/selfupdate v0.6.0
github.com/mitchellh/go-homedir v1.1.0
github.com/slack-go/slack v0.12.2
github.com/spf13/cobra v1.7.0
github.com/spf13/viper v1.15.0
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.659
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.659
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.659
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.659
github.com/slack-go/slack v0.15.0
github.com/spf13/cobra v1.8.1
github.com/spf13/viper v1.19.0
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/clb v1.0.1051
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.1051
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/cvm v1.0.1051
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/lighthouse v1.0.1051
github.com/zitadel/oidc/v3 v3.33.1
)

require (
aead.dev/minisign v0.2.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-jose/go-jose/v4 v4.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/securecookie v1.1.2 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/muhlemmer/gu v0.3.1 // indirect
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect
github.com/opentracing/opentracing-go v1.2.1-0.20220228012449-10b1cf09e00b // indirect
github.com/pelletier/go-toml/v2 v2.0.8 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/zitadel/logging v0.6.1 // indirect
github.com/zitadel/schema v1.3.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/mod v0.17.0 // indirect
golang.org/x/net v0.26.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/crypto v0.29.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/mod v0.18.0 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.22.0 // indirect
golang.org/x/term v0.22.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect
golang.org/x/tools v0.22.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit b16e8a3

Please sign in to comment.