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

     1  /*
     2  Package users manages and retrieves Users in the OpenStack Identity Service.
     3  
     4  Example to List Users
     5  
     6  	listOpts := users.ListOpts{
     7  		DomainID: "default",
     8  	}
     9  
    10  	allPages, err := users.List(identityClient, listOpts).AllPages()
    11  	if err != nil {
    12  		panic(err)
    13  	}
    14  
    15  	allUsers, err := users.ExtractUsers(allPages)
    16  	if err != nil {
    17  		panic(err)
    18  	}
    19  
    20  	for _, user := range allUsers {
    21  		fmt.Printf("%+v\n", user)
    22  	}
    23  
    24  Example to Create a User
    25  
    26  	projectID := "a99e9b4e620e4db09a2dfb6e42a01e66"
    27  
    28  	createOpts := users.CreateOpts{
    29  		Name:             "username",
    30  		DomainID:         "default",
    31  		DefaultProjectID: projectID,
    32  		Enabled:          golangsdk.Enabled,
    33  		Password:         "supersecret",
    34  		Extra: map[string]interface{}{
    35  			"email": "username@example.com",
    36  		}
    37  	}
    38  
    39  	user, err := users.Create(identityClient, createOpts).Extract()
    40  	if err != nil {
    41  		panic(err)
    42  	}
    43  
    44  Example to Update a User
    45  
    46  	userID := "0fe36e73809d46aeae6705c39077b1b3"
    47  
    48  	updateOpts := users.UpdateOpts{
    49  		Enabled: golangsdk.Disabled,
    50  	}
    51  
    52  	user, err := users.Update(identityClient, userID, updateOpts).Extract()
    53  	if err != nil {
    54  		panic(err)
    55  	}
    56  
    57  Example to Delete a User
    58  
    59  	userID := "0fe36e73809d46aeae6705c39077b1b3"
    60  	err := users.Delete(identityClient, userID).ExtractErr()
    61  	if err != nil {
    62  		panic(err)
    63  	}
    64  
    65  Example to List Groups a User Belongs To
    66  
    67  	userID := "0fe36e73809d46aeae6705c39077b1b3"
    68  
    69  	allPages, err := users.ListGroups(identityClient, userID).AllPages()
    70  	if err != nil {
    71  		panic(err)
    72  	}
    73  
    74  	allGroups, err := groups.ExtractGroups(allPages)
    75  	if err != nil {
    76  		panic(err)
    77  	}
    78  
    79  	for _, group := range allGroups {
    80  		fmt.Printf("%+v\n", group)
    81  	}
    82  
    83  Example to List Projects a User Belongs To
    84  
    85  	userID := "0fe36e73809d46aeae6705c39077b1b3"
    86  
    87  	allPages, err := users.ListProjects(identityClient, userID).AllPages()
    88  	if err != nil {
    89  		panic(err)
    90  	}
    91  
    92  	allProjects, err := projects.ExtractProjects(allPages)
    93  	if err != nil {
    94  		panic(err)
    95  	}
    96  
    97  	for _, project := range allProjects {
    98  		fmt.Printf("%+v\n", project)
    99  	}
   100  
   101  Example to List Users in a Group
   102  
   103  	groupID := "bede500ee1124ae9b0006ff859758b3a"
   104  	listOpts := users.ListOpts{
   105  		DomainID: "default",
   106  	}
   107  
   108  	allPages, err := users.ListInGroup(identityClient, groupID, listOpts).AllPages()
   109  	if err != nil {
   110  		panic(err)
   111  	}
   112  
   113  	allUsers, err := users.ExtractUsers(allPages)
   114  	if err != nil {
   115  		panic(err)
   116  	}
   117  
   118  	for _, user := range allUsers {
   119  		fmt.Printf("%+v\n", user)
   120  	}
   121  
   122  */
   123  package users