Merge pull request #8095 from lonegunmanb/f-ucloud-client-base-url

make ucloud builder's base url configurable
This commit is contained in:
Adrien Delorme 2019-09-12 10:12:40 +02:00 committed by GitHub
commit 3175b72cf3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 0 deletions

View File

@ -18,6 +18,7 @@ type AccessConfig struct {
PrivateKey string `mapstructure:"private_key"`
Region string `mapstructure:"region"`
ProjectId string `mapstructure:"project_id"`
BaseUrl string `mapstructure:"base_url"`
client *UCloudClient
}
@ -30,6 +31,9 @@ func (c *AccessConfig) Client() (*UCloudClient, error) {
cfg := ucloud.NewConfig()
cfg.Region = c.Region
cfg.ProjectId = c.ProjectId
if c.BaseUrl != "" {
cfg.BaseUrl = c.BaseUrl
}
cfg.UserAgent = fmt.Sprintf("Packer-UCloud/%s", version.FormattedVersion())
cred := auth.NewCredential()

View File

@ -3,6 +3,7 @@ package uhost
import (
"fmt"
"github.com/hashicorp/packer/packer"
"github.com/stretchr/testify/assert"
"os"
"testing"
@ -193,6 +194,17 @@ func testAccPreCheck(t *testing.T) {
}
}
func TestUCloudClientBaseUrlConfigurable(t *testing.T) {
const url = "baseUrl"
access := &AccessConfig{BaseUrl: url}
client, err := access.Client()
assert.Nil(t, err)
assert.Equal(t, url, client.uaccountconn.Client.GetConfig().BaseUrl, "account conn's base url not configurable")
assert.Equal(t, url, client.uhostconn.Client.GetConfig().BaseUrl, "host conn's base url not configurable")
assert.Equal(t, url, client.unetconn.Client.GetConfig().BaseUrl, "net conn's base url not configurable")
assert.Equal(t, url, client.vpcconn.Client.GetConfig().BaseUrl, "vpc conn's base url not configurable")
}
func testUCloudClient() (*UCloudClient, error) {
access := &AccessConfig{Region: "cn-bj2"}
err := access.Config()