@@ -12,8 +12,9 @@ import (
1212)
1313
1414const (
15- JWT_API = "https://api.scaleway.com/account/v1/jwt"
16- ORGANIZATION_API = "https://api.scaleway.com/account/v2/users/"
15+ LOGIN_API = "https://api.scaleway.com/account/v2/login"
16+ ACCOUNT_USERS_API = "https://api.scaleway.com/account/v2/users/"
17+ IAM_USERS_API = "https://api.scaleway.com/iam/v1alpha1/users/"
1718 SWITCH_ORGANIZATION_API = "https://api.scaleway.com/iam-private/v1/jwts/%s/switch-organization"
1819 API_KEYS_API = "https://api.scaleway.com/iam/v1alpha1/api-keys"
1920 CONTENT_TYPE = "Content-Type"
@@ -40,10 +41,9 @@ type ApiKey struct {
4041}
4142
4243type PostBody struct {
43- Email string `json:"email"`
44- Password string `json:"password"`
45- Token string `json:"2FA_token"`
46- Renewable bool `json:"renewable"`
44+ Email string `json:"email"`
45+ Password string `json:"password"`
46+ Token string `json:"otp"`
4747}
4848
4949func NewScalewayClient (email , password , token string ) (* ScalewayClient , error ) {
@@ -53,39 +53,41 @@ func NewScalewayClient(email, password, token string) (*ScalewayClient, error) {
5353 }
5454
5555 postBody := PostBody {
56- Email : email ,
57- Password : password ,
58- Token : token ,
59- Renewable : true ,
56+ Email : email ,
57+ Password : password ,
58+ Token : token ,
6059 }
6160 jsonBody , err := json .Marshal (postBody )
6261 if err != nil {
6362 return nil , err
6463 }
6564
66- jsonResponse , err := client .sendRequest (JWT_API , jsonBody , "" , "POST" )
65+ jsonResponse , err := client .sendRequest (LOGIN_API , jsonBody , "" , "POST" )
6766 if err != nil {
6867 return nil , err
6968 }
7069
71- client .defaultOrganizationId = jsonResponse ["jwt" ].(map [string ]interface {})["organization_id" ].(string )
7270 client .jti = jsonResponse ["jwt" ].(map [string ]interface {})["jti" ].(string )
73- client .issuer = jsonResponse ["jwt" ].(map [string ]interface {})["issuer " ].(string )
71+ client .issuer = jsonResponse ["jwt" ].(map [string ]interface {})["issuer_id " ].(string )
7472
7573 client .organizationToProfile [client .defaultOrganizationId ] = OrganizationProfile {
76- jwt : jsonResponse ["auth" ].(map [string ]interface {})["jwt_key" ].(string ),
77- userId : jsonResponse ["jwt" ].(map [string ]interface {})["iam_issuer" ].(string ),
74+ jwt : jsonResponse ["token" ].(string ),
7875 }
7976
8077 return & client , nil
8178}
8279
8380func (client * ScalewayClient ) ListOrganizations () (map [string ]string , error ) {
84- jsonResponse , err := client .sendRequest (ORGANIZATION_API + client .issuer , nil , client .getOrCreateOrganizationProfile (client .defaultOrganizationId ).jwt , "GET" )
81+ jsonResponse , err := client .sendRequest (IAM_USERS_API + client .issuer , nil , client .getOrCreateOrganizationProfile (client .defaultOrganizationId ).jwt , "GET" )
8582 if err != nil {
8683 return nil , err
8784 }
85+ accountRootUserId := jsonResponse ["account_root_user_id" ].(string )
8886
87+ jsonResponse , err = client .sendRequest (ACCOUNT_USERS_API + accountRootUserId , nil , client .getOrCreateOrganizationProfile (client .defaultOrganizationId ).jwt , "GET" )
88+ if err != nil {
89+ return nil , err
90+ }
8991 orgs := jsonResponse ["organizations" ].([]interface {})
9092 result := make (map [string ]string )
9193 for _ , org := range orgs {
0 commit comments