make ucloud builder's base url configurable

This commit is contained in:
lonegunman 2019-09-12 11:33:57 +08:00
parent 86c4c164d6
commit 0de807cce0
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()