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

     1  /*
     2  Package roles provides information and interaction with the roles API
     3  resource for the OpenStack Identity service.
     4  
     5  Example to List Roles
     6  
     7  	listOpts := roles.ListOpts{
     8  		DomainID: "default",
     9  	}
    10  
    11  	allPages, err := roles.List(identityClient, listOpts).AllPages()
    12  	if err != nil {
    13  		panic(err)
    14  	}
    15  
    16  	allRoles, err := roles.ExtractRoles(allPages)
    17  	if err != nil {
    18  		panic(err)
    19  	}
    20  
    21  	for _, role := range allRoles {
    22  		fmt.Printf("%+v\n", role)
    23  	}
    24  
    25  Example to Create a Role
    26  
    27  	createOpts := roles.CreateOpts{
    28  		Name:             "read-only-admin",
    29  		DomainID:         "default",
    30  		Extra: map[string]interface{}{
    31  			"description": "this role grants read-only privilege cross tenant",
    32  		}
    33  	}
    34  
    35  	role, err := roles.Create(identityClient, createOpts).Extract()
    36  	if err != nil {
    37  		panic(err)
    38  	}
    39  
    40  Example to Update a Role
    41  
    42  	roleID := "0fe36e73809d46aeae6705c39077b1b3"
    43  
    44  	updateOpts := roles.UpdateOpts{
    45  		Name: "read only admin",
    46  	}
    47  
    48  	role, err := roles.Update(identityClient, roleID, updateOpts).Extract()
    49  	if err != nil {
    50  		panic(err)
    51  	}
    52  
    53  Example to Delete a Role
    54  
    55  	roleID := "0fe36e73809d46aeae6705c39077b1b3"
    56  	err := roles.Delete(identityClient, roleID).ExtractErr()
    57  	if err != nil {
    58  		panic(err)
    59  	}
    60  
    61  Example to List Role Assignments
    62  
    63  	listOpts := roles.ListAssignmentsOpts{
    64  		UserID:         "97061de2ed0647b28a393c36ab584f39",
    65  		ScopeProjectID: "9df1a02f5eb2416a9781e8b0c022d3ae",
    66  	}
    67  
    68  	allPages, err := roles.ListAssignments(identityClient, listOpts).AllPages()
    69  	if err != nil {
    70  		panic(err)
    71  	}
    72  
    73  	allRoles, err := roles.ExtractRoleAssignments(allPages)
    74  	if err != nil {
    75  		panic(err)
    76  	}
    77  
    78  	for _, role := range allRoles {
    79  		fmt.Printf("%+v\n", role)
    80  	}
    81  
    82  Example to Assign a Role to a User in a Project
    83  
    84  	projectID := "a99e9b4e620e4db09a2dfb6e42a01e66"
    85  	userID := "9df1a02f5eb2416a9781e8b0c022d3ae"
    86  	roleID := "9fe2ff9ee4384b1894a90878d3e92bab"
    87  
    88  	err := roles.Assign(identityClient, roleID, roles.AssignOpts{
    89  		UserID:    userID,
    90  		ProjectID: projectID,
    91  	}).ExtractErr()
    92  
    93  	if err != nil {
    94  		panic(err)
    95  	}
    96  
    97  Example to Unassign a Role From a User in a Project
    98  
    99  	projectID := "a99e9b4e620e4db09a2dfb6e42a01e66"
   100  	userID := "9df1a02f5eb2416a9781e8b0c022d3ae"
   101  	roleID := "9fe2ff9ee4384b1894a90878d3e92bab"
   102  
   103  	err := roles.Unassign(identityClient, roleID, roles.UnassignOpts{
   104  		UserID:    userID,
   105  		ProjectID: projectID,
   106  	}).ExtractErr()
   107  
   108  	if err != nil {
   109  		panic(err)
   110  	}
   111  */
   112  package roles