Skip to content

Commit

Permalink
Merge pull request #19 from lixiaojun629/develop
Browse files Browse the repository at this point in the history
add udb mysql
  • Loading branch information
lixiaojun629 authored Mar 6, 2019
2 parents 8e98d5e + 1b06408 commit 1241e33
Show file tree
Hide file tree
Showing 263 changed files with 8,229 additions and 2,073 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export VERSION=0.1.9
export VERSION=0.1.10

.PHONY : build
build:
Expand Down
15 changes: 10 additions & 5 deletions base/client.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package base

import (
pudisk "github.com/ucloud/ucloud-sdk-go/private/services/udisk"
pudb "github.com/ucloud/ucloud-sdk-go/private/services/udb"
puhost "github.com/ucloud/ucloud-sdk-go/private/services/uhost"
"github.com/ucloud/ucloud-sdk-go/services/pathx"
"github.com/ucloud/ucloud-sdk-go/services/uaccount"
"github.com/ucloud/ucloud-sdk-go/services/udb"
"github.com/ucloud/ucloud-sdk-go/services/udisk"
"github.com/ucloud/ucloud-sdk-go/services/udpn"
"github.com/ucloud/ucloud-sdk-go/services/uhost"
Expand All @@ -15,12 +16,12 @@ import (
"github.com/ucloud/ucloud-sdk-go/ucloud/auth"
)

//PrivateUDiskClient 私有模块的udisk client 即未在官网开放的接口
type PrivateUDiskClient = pudisk.UDiskClient

//PrivateUHostClient 私有模块的udisk client 即未在官网开放的接口
//PrivateUHostClient 私有模块的uhost client 即未在官网开放的接口
type PrivateUHostClient = puhost.UHostClient

//PrivateUDBClient 私有模块的udb client 即未在官网开放的接口
type PrivateUDBClient = pudb.UDBClient

//Client aggregate client for business
type Client struct {
uaccount.UAccountClient
Expand All @@ -31,7 +32,9 @@ type Client struct {
pathx.PathXClient
udisk.UDiskClient
ulb.ULBClient
udb.UDBClient
PrivateUHostClient
PrivateUDBClient
}

// NewClient will return a aggregate client
Expand All @@ -45,6 +48,8 @@ func NewClient(config *ucloud.Config, credential *auth.Credential) *Client {
*pathx.NewClient(config, credential),
*udisk.NewClient(config, credential),
*ulb.NewClient(config, credential),
*udb.NewClient(config, credential),
*puhost.NewClient(config, credential),
*pudb.NewClient(config, credential),
}
}
36 changes: 25 additions & 11 deletions base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/ucloud/ucloud-sdk-go/services/uaccount"
sdk "github.com/ucloud/ucloud-sdk-go/ucloud"
"github.com/ucloud/ucloud-sdk-go/ucloud/auth"
"github.com/ucloud/ucloud-sdk-go/ucloud/log"
)

//ConfigFile filename
Expand All @@ -29,7 +30,7 @@ const DefaultBaseURL = "https://api.ucloud.cn/"
const DefaultProfile = "default"

//Version 版本号
const Version = "0.1.9"
const Version = "0.1.10"

//ConfigIns 配置实例, 程序加载时生成
var ConfigIns = &AggConfig{}
Expand All @@ -40,6 +41,19 @@ var ClientConfig *sdk.Config
//AuthCredential 创建sdk client参数
var AuthCredential *auth.Credential

//Global 全局flag
var Global GlobalFlag

//GlobalFlag 几乎所有接口都需要的参数,例如 region zone projectID
type GlobalFlag struct {
Debug bool
JSON bool
Version bool
Completion bool
Config bool
Signup bool
}

//CLIConfig cli_config element
type CLIConfig struct {
ProjectID string `json:"project_id"`
Expand Down Expand Up @@ -75,26 +89,26 @@ type AggConfig struct {
func (p *AggConfig) ConfigPublicKey() error {
Cxt.Print("Your public-key:")
_, err := fmt.Scanf("%s\n", &p.PublicKey)
p.PublicKey = strings.TrimSpace(p.PublicKey)
AuthCredential.PublicKey = p.PublicKey
p.Save()
if err != nil {
Cxt.Println(err)
return err
}
return err
p.PublicKey = strings.TrimSpace(p.PublicKey)
AuthCredential.PublicKey = p.PublicKey
return nil
}

//ConfigPrivateKey 输入私钥
func (p *AggConfig) ConfigPrivateKey() error {
Cxt.Print("Your private-key:")
_, err := fmt.Scanf("%s\n", &p.PrivateKey)
p.PrivateKey = strings.TrimSpace(p.PrivateKey)
AuthCredential.PrivateKey = p.PrivateKey
p.Save()
if err != nil {
Cxt.Println(err)
return err
}
return err
p.PrivateKey = strings.TrimSpace(p.PrivateKey)
AuthCredential.PrivateKey = p.PrivateKey
return nil
}

//GetClientConfig 用来生成sdkClient
Expand Down Expand Up @@ -491,8 +505,8 @@ func init() {
ClientConfig = &sdk.Config{
BaseUrl: ConfigIns.BaseURL,
Timeout: timeout,
UserAgent: fmt.Sprintf("UCloud CLI v%s", Version),
LogLevel: 1,
UserAgent: fmt.Sprintf("UCloud-CLI/%s", Version),
LogLevel: log.FatalLevel,
}

AuthCredential = &auth.Credential{
Expand Down
29 changes: 20 additions & 9 deletions base/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ func PrintTableS(dataSet interface{}) {
}

//PrintList 打印表格或者JSON
func PrintList(dataSet interface{}, json bool) {
if json {
func PrintList(dataSet interface{}) {
if Global.JSON {
PrintJSON(dataSet)
} else {
PrintTableS(dataSet)
Expand Down Expand Up @@ -280,6 +280,9 @@ func FormatDate(seconds int) string {
return time.Unix(int64(seconds), 0).Format("2006-01-02")
}

//DateTimeLayout 时间格式
const DateTimeLayout = "2006-01-02/15:04:05"

//FormatDateTime 格式化时间,把以秒为单位的时间戳格式化未年月日/时分秒
func FormatDateTime(seconds int) string {
return time.Unix(int64(seconds), 0).Format("2006-01-02/15:04:05")
Expand Down Expand Up @@ -362,14 +365,12 @@ func (p *Poller) Spoll(resourceID, pollText string, targetStates []string) {

done := make(chan bool)
go func() {
if resp, err := w.Wait(); err != nil {
if _, err := w.Wait(); err != nil {
log.Error(err)
if _, ok := err.(*waiter.TimeoutError); ok {
done <- false
return
}
} else {
log.Infof("%#v", resp)
}
done <- true
}()
Expand Down Expand Up @@ -427,14 +428,12 @@ func (p *Poller) Poll(resourceID, projectID, region, zone, pollText string, targ

done := make(chan bool)
go func() {
if resp, err := w.Wait(); err != nil {
if _, err := w.Wait(); err != nil {
log.Error(err)
if _, ok := err.(*waiter.TimeoutError); ok {
done <- false
return
}
} else {
log.Infof("%#v", resp)
}
done <- true
}()
Expand Down Expand Up @@ -509,7 +508,6 @@ func GetFileList(suffix string) []string {
}
files, err := ioutil.ReadDir(pathPrefix)
if err != nil {
log.Fatal(err)
return nil
}
names := []string{}
Expand All @@ -529,3 +527,16 @@ func GetFileList(suffix string) []string {
}
return names
}

//Confirm 二次确认
func Confirm(yes bool, text string) bool {
if yes {
return true
}
sure, err := ux.Prompt(text)
if err != nil {
Cxt.Println(err)
return false
}
return sure
}
Loading

0 comments on commit 1241e33

Please sign in to comment.