@@ -665,6 +665,14 @@ type ScalewayDashboard struct {
665
665
IPsCount int `json:"ips_count"`
666
666
}
667
667
668
+ type ScalewayPermissions map [string ]ScalewayPermCategory
669
+ type ScalewayPermCategory map [string ][]string
670
+
671
+ // ScalewayPermissionDefinition represents the permissions
672
+ type ScalewayPermissionDefinition struct {
673
+ Permissions ScalewayPermissions `json:"permissions"`
674
+ }
675
+
668
676
// FuncMap used for json inspection
669
677
var FuncMap = template.FuncMap {
670
678
"json" : func (v interface {}) string {
@@ -1674,6 +1682,28 @@ func (s *ScalewayAPI) GetUser() (*ScalewayUserDefinition, error) {
1674
1682
return & user .User , nil
1675
1683
}
1676
1684
1685
+ func (s * ScalewayAPI ) GetPermissions () (* ScalewayPermissionDefinition , error ) {
1686
+ s .EnableAccountAPI ()
1687
+ defer s .DisableAccountAPI ()
1688
+ resp , err := s .GetResponse (fmt .Sprintf ("tokens/%s/permissions" , s .Token ))
1689
+ if err != nil {
1690
+ return nil , err
1691
+ }
1692
+ defer resp .Body .Close ()
1693
+
1694
+ if resp .StatusCode != 200 {
1695
+ return nil , fmt .Errorf ("[%d] no such user" , resp .StatusCode )
1696
+ }
1697
+ var permissions ScalewayPermissionDefinition
1698
+
1699
+ decoder := json .NewDecoder (resp .Body )
1700
+ err = decoder .Decode (& permissions )
1701
+ if err != nil {
1702
+ return nil , err
1703
+ }
1704
+ return & permissions , nil
1705
+ }
1706
+
1677
1707
// GetDashboard returns the dashboard
1678
1708
func (s * ScalewayAPI ) GetDashboard () (* ScalewayDashboard , error ) {
1679
1709
resp , err := s .GetResponse ("dashboard" )
0 commit comments