4
4
"fmt"
5
5
"log"
6
6
"sync"
7
- "time"
8
7
9
8
cleanhttp "github.com/hashicorp/go-cleanhttp"
10
9
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/logging"
@@ -14,6 +13,8 @@ import (
14
13
var providerVersion , providerCommit string
15
14
16
15
type Config struct {
16
+ Account string
17
+ Plate string
17
18
Endpoint string
18
19
ApplicationKey string
19
20
ApplicationSecret string
@@ -24,17 +25,6 @@ type Config struct {
24
25
lockAuth * sync.Mutex
25
26
}
26
27
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
-
38
28
func clientDefault (c * Config ) (* ovh.Client , error ) {
39
29
client , err := ovh .NewClient (
40
30
c .Endpoint ,
@@ -63,15 +53,21 @@ func (c *Config) loadAndValidate() error {
63
53
}
64
54
65
55
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 {
68
58
c .authFailed = fmt .Errorf ("OVH client seems to be misconfigured: %q\n " , err )
69
59
return c .authFailed
70
60
}
71
61
72
62
log .Printf ("[DEBUG] Logged in on OVH API" )
63
+ c .Account = details .Account
73
64
c .authenticated = true
74
65
}
66
+
67
+ if c .Plate == "" {
68
+ c .Plate = plateFromEndpoint (c .Endpoint )
69
+ }
70
+
75
71
return nil
76
72
}
77
73
@@ -106,3 +102,17 @@ func (c *Config) load() error {
106
102
107
103
return nil
108
104
}
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