Documentation
¶
Overview ¶
Package users provides information and interaction with the users API resource for the OpenStack Identity Service.
Example to List Users
allPages, err := users.List(identityClient).AllPages()
if err != nil {
panic(err)
}
allUsers, err := users.ExtractUsers(allPages)
if err != nil {
panic(err)
}
for _, user := range allUsers {
fmt.Printf("%+v\n", user)
}
Example to Create a User
createOpts := users.CreateOpts{
Name: "name",
TenantID: "c39e3de9be2d4c779f1dfd6abacc176d",
Enabled: gophercloud.Enabled,
}
user, err := users.Create(identityClient, createOpts).Extract()
if err != nil {
panic(err)
}
Example to Update a User
userID := "9fe2ff9ee4384b1894a90878d3e92bab"
updateOpts := users.UpdateOpts{
Name: "new_name",
Enabled: gophercloud.Disabled,
}
user, err := users.Update(identityClient, userID, updateOpts).Extract()
if err != nil {
panic(err)
}
Example to Delete a User
userID := "9fe2ff9ee4384b1894a90878d3e92bab"
err := users.Delete(identityClient, userID).ExtractErr()
if err != nil {
panic(err)
}
Example to List a User's Roles
tenantID := "1d8b6120dcc640fda4fc9194ffc80273"
userID := "c39e3de9be2d4c779f1dfd6abacc176d"
allPages, err := users.ListRoles(identityClient, tenantID, userID).AllPages()
if err != nil {
panic(err)
}
allRoles, err := users.ExtractRoles(allPages)
if err != nil {
panic(err)
}
for _, role := range allRoles {
fmt.Printf("%+v\n", role)
}
Index ¶
- func List(client *gophercloud.ServiceClient) pagination.Pager
- func ListRoles(client *gophercloud.ServiceClient, tenantID, userID string) pagination.Pager
- func ResourceURL(c *gophercloud.ServiceClient, id string) string
- type CommonOpts
- type CreateOpts
- type CreateOptsBuilder
- type CreateResult
- type DeleteResult
- type GetResult
- type Role
- type RolePage
- type UpdateOpts
- type UpdateOptsBuilder
- type UpdateResult
- type User
- type UserPage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func List ¶
func List(client *gophercloud.ServiceClient) pagination.Pager
List lists the existing users.
func ListRoles ¶
func ListRoles(client *gophercloud.ServiceClient, tenantID, userID string) pagination.Pager
ListRoles lists the existing roles that can be assigned to users.
func ResourceURL ¶
func ResourceURL(c *gophercloud.ServiceClient, id string) string
Types ¶
type CommonOpts ¶
type CommonOpts struct {
// Either a name or username is required. When provided, the value must be
// unique or a 409 conflict error will be returned. If you provide a name but
// omit a username, the latter will be set to the former; and vice versa.
Name string `json:"name,omitempty"`
Username string `json:"username,omitempty"`
// TenantID is the ID of the tenant to which you want to assign this user.
TenantID string `json:"tenantId,omitempty"`
// Enabled indicates whether this user is enabled or not.
Enabled *bool `json:"enabled,omitempty"`
// Email is the email address of this user.
Email string `json:"email,omitempty"`
}
CommonOpts are the parameters that are shared between CreateOpts and UpdateOpts
type CreateOpts ¶
type CreateOpts CommonOpts
CreateOpts represents the options needed when creating new users.
func (CreateOpts) ToUserCreateMap ¶
func (opts CreateOpts) ToUserCreateMap() (map[string]interface{}, error)
ToUserCreateMap assembles a request body based on the contents of a CreateOpts.
type CreateOptsBuilder ¶
CreateOptsBuilder allows extensions to add additional parameters to the Create request.
type CreateResult ¶
type CreateResult struct {
// contains filtered or unexported fields
}
CreateResult represents the result of a Create operation. Call its Extract method to interpret the result as a User.
func Create ¶
func Create(client *gophercloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)
Create is the operation responsible for creating new users.
type DeleteResult ¶
type DeleteResult struct {
// contains filtered or unexported fields
}
DeleteResult represents the result of a Delete operation. Call its ExtractErr method to determine if the request succeeded or failed.
func Delete ¶
func Delete(client *gophercloud.ServiceClient, id string) (r DeleteResult)
Delete is the operation responsible for permanently deleting a User.
type GetResult ¶
type GetResult struct {
// contains filtered or unexported fields
}
GetResult represents the result of a Get operation. Call its Extract method to interpret the result as a User.
func Get ¶
func Get(client *gophercloud.ServiceClient, id string) (r GetResult)
Get requests details on a single user, either by ID or Name.
type Role ¶
type Role struct {
// ID is the UUID of the role.
ID string
// Name is the name of the role.
Name string
}
Role assigns specific responsibilities to users, allowing them to accomplish certain API operations whilst scoped to a service.
func ExtractRoles ¶
func ExtractRoles(r pagination.Page) ([]Role, error)
ExtractRoles returns a slice of Roles contained in a single page of results.
type RolePage ¶
type RolePage struct {
pagination.SinglePageBase
}
RolePage is a single page of a user Role collection.
type UpdateOpts ¶
type UpdateOpts CommonOpts
UpdateOpts specifies the base attributes that may be updated on an existing server.
func (UpdateOpts) ToUserUpdateMap ¶
func (opts UpdateOpts) ToUserUpdateMap() (map[string]interface{}, error)
ToUserUpdateMap formats an UpdateOpts structure into a request body.
type UpdateOptsBuilder ¶
UpdateOptsBuilder allows extensions to add additional parameters to the Update request.
type UpdateResult ¶
type UpdateResult struct {
// contains filtered or unexported fields
}
UpdateResult represents the result of an Update operation. Call its Extract method to interpret the result as a User.
func Update ¶
func Update(client *gophercloud.ServiceClient, id string, opts UpdateOptsBuilder) (r UpdateResult)
Update is the operation responsible for updating exist users by their ID.
type User ¶
type User struct {
// ID is the UUID for this user.
ID string
// Name is the human name for this user.
Name string
// Username is the username for this user.
Username string
// Enabled indicates whether the user is enabled (true) or disabled (false).
Enabled bool
// Email is the email address for this user.
Email string
// TenantID is the ID of the tenant to which this user belongs.
TenantID string `json:"tenant_id"`
}
User represents a user resource that exists on the API.
func ExtractUsers ¶
func ExtractUsers(r pagination.Page) ([]User, error)
ExtractUsers returns a slice of Users contained in a single page of results.
type UserPage ¶
type UserPage struct {
pagination.SinglePageBase
}
UserPage is a single page of a User collection.