make ucloud builder's base url configurable

pull/8095/head
lonegunman 7 years ago
parent 86c4c164d6
commit 0de807cce0

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

@ -3,6 +3,7 @@ package uhost
import ( import (
"fmt" "fmt"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
"github.com/stretchr/testify/assert"
"os" "os"
"testing" "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) { func testUCloudClient() (*UCloudClient, error) {
access := &AccessConfig{Region: "cn-bj2"} access := &AccessConfig{Region: "cn-bj2"}
err := access.Config() err := access.Config()

Loading…
Cancel
Save