@@ -25,8 +25,14 @@ import (
25
25
26
26
// ScalewayAPI is the interface used to communicate with the Scaleway API
27
27
type ScalewayAPI struct {
28
- // APIEndpoint is the endpoint to the Scaleway API
29
- APIEndPoint string
28
+ // ComputeAPI is the endpoint to the Scaleway API
29
+ ComputeAPI string
30
+
31
+ // AccountAPI is the endpoint to the Scaleway Account API
32
+ AccountAPI string
33
+
34
+ // APIEndPoint or ACCOUNTEndPoint
35
+ APIUrl string
30
36
31
37
// Organization is the identifier of the Scaleway organization
32
38
Organization string
@@ -500,13 +506,15 @@ var FuncMap = template.FuncMap{
500
506
}
501
507
502
508
// NewScalewayAPI creates a ready-to-use ScalewayAPI client
503
- func NewScalewayAPI (endpoint , organization , token string ) (* ScalewayAPI , error ) {
509
+ func NewScalewayAPI (apiEndPoint , accountEndPoint , organization , token string ) (* ScalewayAPI , error ) {
504
510
cache , err := NewScalewayCache ()
505
511
if err != nil {
506
512
return nil , err
507
513
}
508
514
s := & ScalewayAPI {
509
- APIEndPoint : endpoint ,
515
+ ComputeAPI : apiEndPoint ,
516
+ AccountAPI : accountEndPoint ,
517
+ APIUrl : apiEndPoint ,
510
518
Organization : organization ,
511
519
Token : token ,
512
520
Cache : cache ,
@@ -523,7 +531,7 @@ func (s *ScalewayAPI) Sync() {
523
531
524
532
// GetResponse returns an http.Response object for the requested resource
525
533
func (s * ScalewayAPI ) GetResponse (resource string ) (* http.Response , error ) {
526
- uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIEndPoint , "/" ), resource )
534
+ uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIUrl , "/" ), resource )
527
535
log .Debugf ("GET %s" , uri )
528
536
client := & http.Client {}
529
537
req , err := http .NewRequest ("GET" , uri , nil )
@@ -537,7 +545,7 @@ func (s *ScalewayAPI) GetResponse(resource string) (*http.Response, error) {
537
545
538
546
// PostResponse returns an http.Response object for the updated resource
539
547
func (s * ScalewayAPI ) PostResponse (resource string , data interface {}) (* http.Response , error ) {
540
- uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIEndPoint , "/" ), resource )
548
+ uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIUrl , "/" ), resource )
541
549
client := & http.Client {}
542
550
payload := new (bytes.Buffer )
543
551
encoder := json .NewEncoder (payload )
@@ -562,7 +570,7 @@ func (s *ScalewayAPI) PostResponse(resource string, data interface{}) (*http.Res
562
570
563
571
// PatchResponse returns an http.Response object for the updated resource
564
572
func (s * ScalewayAPI ) PatchResponse (resource string , data interface {}) (* http.Response , error ) {
565
- uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIEndPoint , "/" ), resource )
573
+ uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIUrl , "/" ), resource )
566
574
client := & http.Client {}
567
575
payload := new (bytes.Buffer )
568
576
encoder := json .NewEncoder (payload )
@@ -587,7 +595,7 @@ func (s *ScalewayAPI) PatchResponse(resource string, data interface{}) (*http.Re
587
595
588
596
// PutResponse returns an http.Response object for the updated resource
589
597
func (s * ScalewayAPI ) PutResponse (resource string , data interface {}) (* http.Response , error ) {
590
- uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIEndPoint , "/" ), resource )
598
+ uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIUrl , "/" ), resource )
591
599
client := & http.Client {}
592
600
payload := new (bytes.Buffer )
593
601
encoder := json .NewEncoder (payload )
@@ -612,7 +620,7 @@ func (s *ScalewayAPI) PutResponse(resource string, data interface{}) (*http.Resp
612
620
613
621
// DeleteResponse returns an http.Response object for the deleted resource
614
622
func (s * ScalewayAPI ) DeleteResponse (resource string ) (* http.Response , error ) {
615
- uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIEndPoint , "/" ), resource )
623
+ uri := fmt .Sprintf ("%s/%s" , strings .TrimRight (s .APIUrl , "/" ), resource )
616
624
client := & http.Client {}
617
625
log .Debugf ("DELETE %s" , uri )
618
626
req , err := http .NewRequest ("DELETE" , uri , nil )
@@ -1193,6 +1201,8 @@ func (s *ScalewayAPI) GetTasks() (*[]ScalewayTask, error) {
1193
1201
1194
1202
// CheckCredentials performs a dummy check to ensure we can contact the API
1195
1203
func (s * ScalewayAPI ) CheckCredentials () error {
1204
+ s .enableAccountApi ()
1205
+ defer s .disableAccountApi ()
1196
1206
query := url.Values {}
1197
1207
query .Set ("token_id" , s .Token )
1198
1208
resp , err := s .GetResponse ("tokens?" + query .Encode ())
@@ -1311,3 +1321,11 @@ func (s *ScalewayAPI) HideAPICredentials(input string) string {
1311
1321
output = strings .Replace (output , s .Organization , s .anonuuid .FakeUUID (s .Organization ), - 1 )
1312
1322
return output
1313
1323
}
1324
+
1325
+ func (s * ScalewayAPI ) enableAccountApi () {
1326
+ s .APIUrl = s .AccountAPI
1327
+ }
1328
+
1329
+ func (s * ScalewayAPI ) disableAccountApi () {
1330
+ s .APIUrl = s .ComputeAPI
1331
+ }
0 commit comments