Skip to content

Commit

Permalink
fix config servers while creating an osc client
Browse files Browse the repository at this point in the history
Signed-off-by: outscale_hmi <[email protected]>
  • Loading branch information
outscale-hmi committed Apr 6, 2023
1 parent 056e027 commit 7d96b23
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions builder/osc/common/access_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os"

"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
"github.com/outscale/osc-sdk-go/v2"
oscgo "github.com/outscale/osc-sdk-go/v2"
"github.com/outscale/packer-plugin-outscale/version"
)
Expand Down Expand Up @@ -133,13 +132,24 @@ func (c *AccessConfig) NewOSCClientByRegion(region string) *OscClient {
config := oscgo.NewConfiguration()
config.Debug = true
config.UserAgent = fmt.Sprintf("packer-plugin-outscale/%s", version.PluginVersion.String())
auth := context.WithValue(context.Background(), oscgo.ContextAWSv4, osc.AWSv4{
AccessKey: os.Getenv("OSC_ACCESS_KEY"),
SecretKey: os.Getenv("OSC_SECRET_KEY"),
auth := context.WithValue(context.Background(), oscgo.ContextAWSv4, oscgo.AWSv4{
AccessKey: c.AccessKey,
SecretKey: c.SecretKey,
})
config.HTTPClient = skipClient
auth = context.WithValue(auth, oscgo.ContextServerIndex, 0)
auth = context.WithValue(auth, oscgo.ContextServerVariables, map[string]string{"region": os.Getenv("OSC_REGION")})
config.Servers = oscgo.ServerConfigurations{
{
URL: fmt.Sprintf("https://api.%s.%s", region, c.CustomEndpointOAPI),
Description: "Loaded from profile",
Variables: map[string]oscgo.ServerVariable{
"region": {
Description: "Loaded from env variables",
DefaultValue: region,
EnumValues: []string{region},
},
},
},
}

oscClient := &OscClient{
Api: oscgo.NewAPIClient(config),
Expand Down

0 comments on commit 7d96b23

Please sign in to comment.