@@ -665,6 +665,14 @@ type ScalewayDashboard struct {
665665 IPsCount int `json:"ips_count"`
666666}
667667
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+
668676// FuncMap used for json inspection
669677var FuncMap = template.FuncMap {
670678 "json" : func (v interface {}) string {
@@ -1674,6 +1682,28 @@ func (s *ScalewayAPI) GetUser() (*ScalewayUserDefinition, error) {
16741682 return & user .User , nil
16751683}
16761684
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+
16771707// GetDashboard returns the dashboard
16781708func (s * ScalewayAPI ) GetDashboard () (* ScalewayDashboard , error ) {
16791709 resp , err := s .GetResponse ("dashboard" )
0 commit comments