From a13dfe1f42cfb6e7d9a8d73bb02ef96e568087ff Mon Sep 17 00:00:00 2001 From: PacoDw <__pm@outlook.com> Date: Fri, 21 Aug 2020 13:29:27 -0500 Subject: [PATCH] chore: added GetRegion() and NewOSCClientByRegion functions --- builder/osc/common/access_config.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/builder/osc/common/access_config.go b/builder/osc/common/access_config.go index cac169232..3288f39dc 100644 --- a/builder/osc/common/access_config.go +++ b/builder/osc/common/access_config.go @@ -91,6 +91,16 @@ func (c *AccessConfig) NewOSCClient() *osc.APIClient { c.CustomEndpointOAPI = "outscale.com/oapi/latest" } + return c.NewOSCClientByRegion(c.RawRegion) +} + +// GetRegion retrieves the Outscale OSC-SDK Region set +func (c *AccessConfig) GetRegion() string { + return c.RawRegion +} + +// NewOSCClientByRegion returns the connection depdending of the region given +func (c *AccessConfig) NewOSCClientByRegion(region string) *osc.APIClient { skipClient := &http.Client{ Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, @@ -100,7 +110,7 @@ func (c *AccessConfig) NewOSCClient() *osc.APIClient { skipClient.Transport = NewTransport(c.AccessKey, c.SecretKey, c.RawRegion, skipClient.Transport) return osc.NewAPIClient(&osc.Configuration{ - BasePath: fmt.Sprintf("https://api.%s.%s", c.RawRegion, c.CustomEndpointOAPI), + BasePath: fmt.Sprintf("https://api.%s.%s", region, c.CustomEndpointOAPI), DefaultHeader: make(map[string]string), UserAgent: "packer-osc", HTTPClient: skipClient,