44 "fmt"
55 "log"
66 "sync"
7- "time"
87
98 cleanhttp "github.com/hashicorp/go-cleanhttp"
109 "github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
@@ -14,6 +13,8 @@ import (
1413var providerVersion , providerCommit string
1514
1615type Config struct {
16+ Account string
17+ Plate string
1718 Endpoint string
1819 ApplicationKey string
1920 ApplicationSecret string
@@ -24,17 +25,6 @@ type Config struct {
2425 lockAuth * sync.Mutex
2526}
2627
27- type OvhAuthCurrentCredential struct {
28- OvhSupport bool `json:"ovhSupport"`
29- Status string `json:"status"`
30- ApplicationId int64 `json:"applicationId"`
31- CredentialId int64 `json:"credentialId"`
32- Rules []ovh.AccessRule `json:"rules"`
33- Expiration time.Time `json:"expiration"`
34- LastUse time.Time `json:"lastUse"`
35- Creation time.Time `json:"creation"`
36- }
37-
3828func clientDefault (c * Config ) (* ovh.Client , error ) {
3929 client , err := ovh .NewClient (
4030 c .Endpoint ,
@@ -63,15 +53,21 @@ func (c *Config) loadAndValidate() error {
6353 }
6454
6555 if ! c .authenticated {
66- var cred OvhAuthCurrentCredential
67- if err := c .OVHClient .Get ("/auth/currentCredential " , & cred ); err != nil {
56+ var details OvhAuthDetails
57+ if err := c .OVHClient .Get ("/auth/details " , & details ); err != nil {
6858 c .authFailed = fmt .Errorf ("OVH client seems to be misconfigured: %q\n " , err )
6959 return c .authFailed
7060 }
7161
7262 log .Printf ("[DEBUG] Logged in on OVH API" )
63+ c .Account = details .Account
7364 c .authenticated = true
7465 }
66+
67+ if c .Plate == "" {
68+ c .Plate = plateFromEndpoint (c .Endpoint )
69+ }
70+
7571 return nil
7672}
7773
@@ -106,3 +102,17 @@ func (c *Config) load() error {
106102
107103 return nil
108104}
105+
106+ var plateMapping map [string ]string = map [string ]string {
107+ "ovh-eu" : "eu" ,
108+ "ovh-ca" : "ca" ,
109+ "ovh-us" : "us" ,
110+ "kimsufi-eu" : "eu" ,
111+ "kimsufi-ca" : "ca" ,
112+ "soyoustart-eu" : "eu" ,
113+ "soyoustart-ca" : "ca" ,
114+ }
115+
116+ func plateFromEndpoint (endpoint string ) string {
117+ return plateMapping [endpoint ]
118+ }
0 commit comments