Skip to content

Commit 5dc27e7

Browse files
committed
Merge 'feature/yg/meego-6781455548-auto-addressing' into 'master'
feat(endpoint): cli endpoint support auto-addressing See merge request: !57
2 parents 4f1b23b + e4f5f40 commit 5dc27e7

9 files changed

Lines changed: 117 additions & 9 deletions

File tree

README.EN.MD

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ To invoke the service, you must provide AK, SK, and region. These parameters can
6565
region: Geographic area, such as cn-beijing
6666
session-token: Required if role-playing is used.
6767
disable-ssl: Specifies whether to disable SSL. The default value is false.
68-
endpoint: Optional; the default value is open.volcengineapi.com.
68+
endpoint: Optional; the default value is open.volcengineapi.com. Ignored when endpoint-resolver is standard.
69+
endpoint-resolver: Optional; set to standard (case-insensitive) to use the standard resolver. Otherwise, the CLI uses endpoint when provided.
70+
use-dual-stack: Optional; enable dual-stack endpoints when true. The default value is false.
6971
```
7072
7173
2. If no configuration is specified in the configuration file, an attempt will be made to read the configuration from environment variables set via export.
@@ -77,6 +79,15 @@ To invoke the service, you must provide AK, SK, and region. These parameters can
7779
# Whether to disable SSL; if not set, the default is false.
7880
export VOLCENGINE_DISABLE_SSL=false
7981
82+
# Optional: custom endpoint. Ignored when VOLCENGINE_ENDPOINT_RESOLVER is standard.
83+
export VOLCENGINE_ENDPOINT=open.volcengineapi.com
84+
85+
# Optional: endpoint resolver; set to standard (case-insensitive) to use the standard resolver.
86+
export VOLCENGINE_ENDPOINT_RESOLVER=standard
87+
88+
# Optional: enable dual-stack endpoints; accepts true/false.
89+
export VOLCENGINE_USE_DUALSTACK=false
90+
8091
# If role-playing is employed, the following must be provided
8192
export VOLCENGINE_SESSION_TOKEN=sessionToken
8293
```
@@ -130,6 +141,9 @@ Other fields that can be specified:
130141
- region
131142
- session-token
132143
- disable-ssl
144+
- endpoint
145+
- endpoint-resolver
146+
- use-dual-stack
133147
134148
For information on the function of each field, please refer to the 'Supported Parameters and Related Descriptions' section in the previous section.
135149
@@ -210,6 +224,16 @@ The ve disable-color command can be used to disable the color display feature.
210224
ve ecs [-h|--help]
211225
```
212226
227+
#### Show CLI version
228+
229+
```shell
230+
ve version
231+
```
232+
233+
```shell
234+
ve -v
235+
```
236+
213237
#### Call the API
214238
215239
When using the VolcEngine CLI to invoke an API, the basic command structure is as follows:

README.MD

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,25 @@
6464
region: 地域,如 cn-beijing
6565
session-token: 如果使用角色扮演,需要提供
6666
disable-ssl: 是否禁用 ssl,默认为 false
67-
endpoint: 可以不填,默认值为 open.volcengineapi.com
67+
endpoint: 可以不填,默认值为 open.volcengineapi.com;当 endpoint-resolver 为 standard 时该值会被忽略
68+
endpoint-resolver: 可选;指定 endpoint 解析器。设置为 standard(不区分大小写)时使用标准解析器;否则当 endpoint 非空时使用 endpoint
69+
use-dual-stack: 可选;是否启用双栈,默认为 false
6870
```
6971

7072
2. 若配置文件中无配置,则会尝试从 export 的环境变量中读取配置
7173
```shell
7274
export VOLCENGINE_ACCESS_KEY=AK
7375
export VOLCENGINE_SECRET_KEY=SK
7476
export VOLCENGINE_REGION=cn-bejing
77+
78+
# 可选:自定义 endpoint;当 VOLCENGINE_ENDPOINT_RESOLVER=standard 时会忽略
79+
export VOLCENGINE_ENDPOINT=open.volcengineapi.com
80+
81+
# 可选:endpoint 解析器;设置为 standard(不区分大小写)使用标准解析器
82+
export VOLCENGINE_ENDPOINT_RESOLVER=standard
83+
84+
# 可选:是否启用双栈,true/false
85+
export VOLCENGINE_USE_DUALSTACK=false
7586
7687
# 是否禁用SSL, 不设置的话默认为false
7788
export VOLCENGINE_DISABLE_SSL=false
@@ -134,6 +145,9 @@ ve configure set --profile [配置名] --region [地区] --access-key [用户的
134145
- region
135146
- session-token
136147
- disable-ssl
148+
- endpoint
149+
- endpoint-resolver
150+
- use-dual-stack
137151

138152
各个字段的作用您可以参考上节中 "支持参数及相关说明" 部分
139153

@@ -228,6 +242,16 @@ ve configure delete --profile [配置名]
228242
ve ecs [-h|--help]
229243
```
230244

245+
#### 查看版本
246+
247+
```shell
248+
ve version
249+
```
250+
251+
```shell
252+
ve -v
253+
```
254+
231255

232256

233257
#### 调用API

cmd/cmd_configure.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,11 @@ func newConfigureSetCmd() *cobra.Command {
7777
cmd.Flags().StringVar(&profileFlags.SecretKey, "secret-key", "", "your secret key(SK)")
7878
cmd.Flags().StringVar(&profileFlags.Region, "region", "", "your region")
7979
cmd.Flags().StringVar(&profileFlags.Endpoint, "endpoint", "", "endpoint bind with region")
80+
cmd.Flags().StringVar(&profileFlags.EndpointResolver, "endpoint-resolver", "", "endpoint resolver (auto-addressing)")
8081
cmd.Flags().StringVar(&profileFlags.SessionToken, "session-token", "", "your session token")
8182

8283
profileFlags.DisableSSL = cmd.Flags().Bool("disable-ssl", false, "disable ssl")
84+
profileFlags.UseDualStack = cmd.Flags().Bool("use-dual-stack", false, "use dual-stack endpoints")
8385
cmd.Flags().BoolP("help", "h", false, "")
8486

8587
cmd.MarkFlagRequired("profile")

cmd/cmd_root.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,27 @@ func initRootCmd() {
2626

2727
rootCmd.Flags().BoolP("help", "h", false, "")
2828

29+
rootCmd.Flags().BoolP("version", "v", false, "Show CLI version")
30+
31+
rootCmd.PreRunE = func(cmd *cobra.Command, args []string) error {
32+
showVersion, _ := cmd.Flags().GetBool("version")
33+
if showVersion {
34+
fmt.Fprintln(cmd.OutOrStdout(), clientVersion)
35+
os.Exit(0)
36+
}
37+
return nil
38+
}
39+
2940
// todo enable color?
3041
rootCmd.SetUsageTemplate(rootUsageTemplate())
3142

3243
rootCmd.AddCommand(&cobra.Command{
44+
Use: "version",
45+
Short: "Show CLI version",
46+
Run: func(cmd *cobra.Command, args []string) {
47+
fmt.Fprintln(cmd.OutOrStdout(), clientVersion)
48+
},
49+
}, &cobra.Command{
3350
Use: "enable-color",
3451
Run: func(cmd *cobra.Command, args []string) {
3552
config.EnableColor = true

cmd/configure.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type Profile struct {
2626
SecretKey string `json:"secret-key"`
2727
Region string `json:"region"`
2828
Endpoint string `json:"endpoint"`
29+
EndpointResolver string `json:"endpoint-resolver,omitempty"`
30+
UseDualStack *bool `json:"use-dual-stack,omitempty"`
2931
SessionToken string `json:"session-token"`
3032
DisableSSL *bool `json:"disable-ssl"`
3133
}
@@ -125,11 +127,13 @@ func setConfigProfile(profile *Profile) error {
125127
// otherwise create a new profileFlags
126128
if currentProfile, exist = cfg.Profiles[profile.Name]; !exist {
127129
currentProfile = &Profile{
128-
Name: profile.Name,
129-
Mode: "AK",
130-
DisableSSL: new(bool),
130+
Name: profile.Name,
131+
Mode: "AK",
132+
DisableSSL: new(bool),
133+
UseDualStack: new(bool),
131134
}
132135
*currentProfile.DisableSSL = false
136+
*currentProfile.UseDualStack = false
133137
}
134138

135139
if profile.AccessKey != "" {
@@ -144,12 +148,21 @@ func setConfigProfile(profile *Profile) error {
144148
if profile.Endpoint != "" {
145149
currentProfile.Endpoint = profile.Endpoint
146150
}
151+
if profile.EndpointResolver != "" {
152+
currentProfile.EndpointResolver = profile.EndpointResolver
153+
}
147154
if profile.SessionToken != "" {
148155
currentProfile.SessionToken = profile.SessionToken
149156
}
150157
if profile.DisableSSL != nil {
151158
*currentProfile.DisableSSL = *profile.DisableSSL
152159
}
160+
if profile.UseDualStack != nil {
161+
if currentProfile.UseDualStack == nil {
162+
currentProfile.UseDualStack = new(bool)
163+
}
164+
*currentProfile.UseDualStack = *profile.UseDualStack
165+
}
153166

154167
cfg.Profiles[currentProfile.Name] = currentProfile
155168
cfg.Current = currentProfile.Name

cmd/sdk_client.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package cmd
22

33
import (
44
"fmt"
5+
"github.com/volcengine/volcengine-go-sdk/volcengine/endpoints"
56
"os"
67
"strconv"
78
"strings"
@@ -32,7 +33,9 @@ type SdkClientInfo struct {
3233
func NewSimpleClient(ctx *Context) (*SdkClient, error) {
3334
var (
3435
ak, sk, sessionToken, region, endpoint string
36+
endpointResolver string
3537
disableSSl bool
38+
useDualStack bool
3639
)
3740

3841
// first try to get ak/sk/region from config file
@@ -43,8 +46,12 @@ func NewSimpleClient(ctx *Context) (*SdkClient, error) {
4346
sk = currentProfile.SecretKey
4447
region = currentProfile.Region
4548
endpoint = currentProfile.Endpoint
49+
endpointResolver = currentProfile.EndpointResolver
4650
sessionToken = currentProfile.SessionToken
4751
disableSSl = *currentProfile.DisableSSL
52+
if currentProfile.UseDualStack != nil {
53+
useDualStack = *currentProfile.UseDualStack
54+
}
4855

4956
if ak == "" {
5057
return nil, fmt.Errorf("profile AccessKey not set")
@@ -64,11 +71,16 @@ func NewSimpleClient(ctx *Context) (*SdkClient, error) {
6471
sk = os.Getenv("VOLCENGINE_SECRET_KEY")
6572
region = os.Getenv("VOLCENGINE_REGION")
6673
endpoint = os.Getenv("VOLCENGINE_ENDPOINT")
74+
endpointResolver = os.Getenv("VOLCENGINE_ENDPOINT_RESOLVER")
6775
sessionToken = os.Getenv("VOLCENGINE_SESSION_TOKEN")
6876
ssl := os.Getenv("VOLCENGINE_DISABLE_SSL")
6977
if ssl == "true" || ssl == "false" {
7078
disableSSl, _ = strconv.ParseBool(ssl)
7179
}
80+
dualStack := os.Getenv("VOLCENGINE_USE_DUALSTACK")
81+
if dualStack == "true" || dualStack == "false" {
82+
useDualStack, _ = strconv.ParseBool(dualStack)
83+
}
7284

7385
if ak == "" {
7486
return nil, fmt.Errorf("VOLCENGINE_ACCESS_KEY not set")
@@ -86,8 +98,18 @@ func NewSimpleClient(ctx *Context) (*SdkClient, error) {
8698
WithCredentials(credentials.NewStaticCredentials(ak, sk, sessionToken)).
8799
WithDisableSSL(disableSSl)
88100

89-
if endpoint != "" {
90-
config.WithEndpoint(endpoint)
101+
resolverValue := strings.ToLower(strings.TrimSpace(endpointResolver))
102+
switch resolverValue {
103+
case "standard":
104+
config.WithEndpointResolver(endpoints.NewStandardEndpointResolver())
105+
default:
106+
if endpoint != "" {
107+
config.WithEndpoint(endpoint)
108+
}
109+
}
110+
111+
if useDualStack {
112+
config.WithUseDualStack(true)
91113
}
92114

93115
sess, _ := session.NewSession(config)

cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ var clientVersionAndUserAgentHandler = request.NamedHandler{
1212
}
1313

1414
const clientName = "volcengine-cli"
15-
const clientVersion = "1.0.37"
15+
const clientVersion = "1.0.38"

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ go 1.12
55
require (
66
github.com/inconshreveable/mousetrap v1.1.0 // indirect
77
github.com/spf13/cobra v1.6.1
8-
github.com/volcengine/volcengine-go-sdk v1.1.7
8+
github.com/volcengine/volcengine-go-sdk v1.1.54
99
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
2020
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
2121
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
2222
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
23+
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
2324
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
2425
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
2526
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
2627
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
2728
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
29+
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
2830
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
2931
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
3032
github.com/inconshreveable/mousetrap v1.0.1/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
@@ -54,6 +56,8 @@ github.com/volcengine/volc-sdk-golang v1.0.23 h1:anOslb2Qp6ywnsbyq9jqR0ljuO63kg9
5456
github.com/volcengine/volc-sdk-golang v1.0.23/go.mod h1:AfG/PZRUkHJ9inETvbjNifTDgut25Wbkm2QoYBTbvyU=
5557
github.com/volcengine/volcengine-go-sdk v1.1.7 h1:5ElF1inqX1QUKX8/XGk+HGpG+F01W+m73cLQH+0x50s=
5658
github.com/volcengine/volcengine-go-sdk v1.1.7/go.mod h1:EyKoi6t6eZxoPNGr2GdFCZti2Skd7MO3eUzx7TtSvNo=
59+
github.com/volcengine/volcengine-go-sdk v1.1.54 h1:5gHiDux021kxrhEpCPPGuFmDyp0LL/xO3lJT27ZGldE=
60+
github.com/volcengine/volcengine-go-sdk v1.1.54/go.mod h1:oxoVo+A17kvkwPkIeIHPVLjSw7EQAm+l/Vau1YGHN+A=
5761
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
5862
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
5963
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
@@ -92,6 +96,8 @@ google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2
9296
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
9397
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
9498
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
99+
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
100+
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
95101
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
96102
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
97103
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

0 commit comments

Comments
 (0)