Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.

Commit 224c148

Browse files
committed
use default region if the region is null
1 parent e125e40 commit 224c148

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

api/client/cli.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, clientFlags *cli.ClientF
136136
}
137137
cli.configFile = configFile
138138

139-
host, err := cli.getServerHost(clientFlags.Common.Region, clientFlags.Common.TLSOptions)
139+
host, dft, err := cli.getServerHost(clientFlags.Common.Region, clientFlags.Common.TLSOptions)
140140
if err != nil {
141141
return err
142142
}
@@ -158,11 +158,11 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, clientFlags *cli.ClientF
158158
}
159159
var cloudConfig cliconfig.CloudConfig
160160
cc, ok := configFile.CloudConfig[host]
161-
if ok {
161+
if ok && !dft {
162162
cloudConfig.AccessKey = cc.AccessKey
163163
cloudConfig.SecretKey = cc.SecretKey
164164
} else {
165-
cc, ok := configFile.CloudConfig[cliconfig.DefaultHyperFormat]
165+
cc, ok = configFile.CloudConfig[cliconfig.DefaultHyperFormat]
166166
if ok {
167167
cloudConfig.AccessKey = cc.AccessKey
168168
cloudConfig.SecretKey = cc.SecretKey
@@ -182,6 +182,11 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, clientFlags *cli.ClientF
182182
cli.client = client
183183
cli.host = host
184184
cli.region = clientFlags.Common.Region
185+
if cli.region == "" {
186+
if cli.region = cc.Region; cli.region == "" {
187+
cli.region = cli.getDefaultRegion()
188+
}
189+
}
185190

186191
if cli.in != nil {
187192
cli.inFd, cli.isTerminalIn = term.GetFdInfo(cli.in)
@@ -196,14 +201,16 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, clientFlags *cli.ClientF
196201
return cli
197202
}
198203

199-
func (cli *DockerCli) getServerHost(region string, tlsOptions *tlsconfig.Options) (host string, err error) {
204+
func (cli *DockerCli) getServerHost(region string, tlsOptions *tlsconfig.Options) (host string, dft bool, err error) {
205+
dft = false
200206
host = region
201207
if host == "" {
202208
host = os.Getenv("HYPER_DEFAULT_REGION")
203209
region = cli.getDefaultRegion()
204210
}
205211
if _, err := url.ParseRequestURI(host); err != nil {
206212
host = "tcp://" + region + "." + cliconfig.DefaultHyperEndpoint
213+
dft = true
207214
}
208215

209216
host, err = opts.ParseHost(tlsOptions != nil, host)

0 commit comments

Comments
 (0)