chore: added GetRegion() and NewOSCClientByRegion functions

This commit is contained in:
PacoDw 2020-08-21 13:29:27 -05:00
parent d9a7626249
commit a13dfe1f42
1 changed files with 11 additions and 1 deletions

View File

@ -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,