github.com/huaweicloud/golangsdk@v0.0.0-20210831081626-d823fe11ceba/openstack/identity/v2/extensions/admin/roles/doc.go (about)

     1  /*
     2  Package roles provides functionality to interact with and control roles on
     3  the API.
     4  
     5  A role represents a personality that a user can assume when performing a
     6  specific set of operations. If a role includes a set of rights and
     7  privileges, a user assuming that role inherits those rights and privileges.
     8  
     9  When a token is generated, the list of roles that user can assume is returned
    10  back to them. Services that are being called by that user determine how they
    11  interpret the set of roles a user has and to which operations or resources
    12  each role grants access.
    13  
    14  It is up to individual services such as Compute or Image to assign meaning
    15  to these roles. As far as the Identity service is concerned, a role is an
    16  arbitrary name assigned by the user.
    17  
    18  Example to List Roles
    19  
    20  	allPages, err := roles.List(identityClient).AllPages()
    21  	if err != nil {
    22  		panic(err)
    23  	}
    24  
    25  	allRoles, err := roles.ExtractRoles(allPages)
    26  	if err != nil {
    27  		panic(err)
    28  	}
    29  
    30  	for _, role := range allRoles {
    31  		fmt.Printf("%+v\n", role)
    32  	}
    33  
    34  Example to Grant a Role to a User
    35  
    36  	tenantID := "a99e9b4e620e4db09a2dfb6e42a01e66"
    37  	userID := "9df1a02f5eb2416a9781e8b0c022d3ae"
    38  	roleID := "9fe2ff9ee4384b1894a90878d3e92bab"
    39  
    40  	err := roles.AddUser(identityClient, tenantID, userID, roleID).ExtractErr()
    41  	if err != nil {
    42  		panic(err)
    43  	}
    44  
    45  Example to Remove a Role from a User
    46  
    47  	tenantID := "a99e9b4e620e4db09a2dfb6e42a01e66"
    48  	userID := "9df1a02f5eb2416a9781e8b0c022d3ae"
    49  	roleID := "9fe2ff9ee4384b1894a90878d3e92bab"
    50  
    51  	err := roles.DeleteUser(identityClient, tenantID, userID, roleID).ExtractErr()
    52  	if err != nil {
    53  		panic(err)
    54  	}
    55  */
    56  package roles