@@ -2,58 +2,79 @@ package linodego
22
33import "context"
44
5+ // UserRolePermissions are the account and entity permissions for the User
56type UserRolePermissions struct {
67 AccountAccess []string `json:"account_access"`
78 EntityAccess []UserAccess `json:"entity_access"`
89}
910
11+ // GetUpdateOptions converts UserRolePermissions for use in UpdateUserRolePermissions
1012func (p * UserRolePermissions ) GetUpdateOptions () UserRolePermissionsUpdateOptions {
1113 return UserRolePermissionsUpdateOptions {
1214 AccountAccess : p .AccountAccess ,
1315 EntityAccess : p .EntityAccess ,
1416 }
1517}
1618
19+ // UserRolePermissionsUpdateOptions are fields accepted by UpdateUserRolePermissions
1720type UserRolePermissionsUpdateOptions struct {
1821 AccountAccess []string `json:"account_access"`
1922 EntityAccess []UserAccess `json:"entity_access"`
2023}
2124
25+ // UserAccess is the breakdown of entities Roles
2226type UserAccess struct {
2327 ID int `json:"id"`
2428 Type string `json:"type"`
2529 Roles []string `json:"roles"`
2630}
2731
32+ // AccountRolePermissions are the account and entity roles for the Account
2833type AccountRolePermissions struct {
2934 AccountAccess []AccountAccess `json:"account_access"`
3035 EntityAccess []AccountAccess `json:"entity_access"`
3136}
3237
38+ // AccountAccess is the Roles for each Type for the Account
3339type AccountAccess struct {
3440 Type string `json:"type"`
3541 Roles []Role `json:"roles"`
3642}
3743
44+ // Role is the IAM Role and its Permissions
3845type Role struct {
3946 Name string `json:"name"`
4047 Description string `json:"description"`
4148 Permissions []string `json:"permissions"`
4249}
4350
51+ // GetUserRolePermissions returns any role permissions for username
4452func (c * Client ) GetUserRolePermissions (ctx context.Context , username string ) (* UserRolePermissions , error ) {
4553 return doGETRequest [UserRolePermissions ](ctx , c ,
4654 formatAPIPath ("iam/users/%s/role-permissions" , username ),
4755 )
4856}
4957
58+ // UpdateUserRolePermissions updates any role permissions for username
5059func (c * Client ) UpdateUserRolePermissions (ctx context.Context , username string , opts UserRolePermissionsUpdateOptions ) (* UserRolePermissions , error ) {
5160 return doPUTRequest [UserRolePermissions ](ctx , c ,
5261 formatAPIPath ("iam/users/%s/role-permissions" , username ),
5362 opts ,
5463 )
5564}
5665
66+ // GetAccountRolePermissions returns the role permissions for this Account
5767func (c * Client ) GetAccountRolePermissions (ctx context.Context ) (* AccountRolePermissions , error ) {
5868 return doGETRequest [AccountRolePermissions ](ctx , c , "iam/role-permissions" )
5969}
70+
71+ // GetUserAccountPermissions returns the account permissions for username
72+ func (c * Client ) GetUserAccountPermissions (ctx context.Context , username string ) ([]string , error ) {
73+ perms , err := doGETRequest [[]string ](ctx , c ,
74+ formatAPIPath ("iam/users/%s/permissions/account" , username ))
75+ if err != nil || perms == nil {
76+ return nil , err
77+ }
78+
79+ return (* perms ), err
80+ }
0 commit comments