users

package
v2.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 25, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package users manages and retrieves Users in the Enterprise Cloud Identity Service.

Example to List Users

listOpts := users.ListOpts{
	DomainID: "default",
}

allPages, err := users.List(identityClient, listOpts).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

projectID := "a99e9b4e620e4db09a2dfb6e42a01e66"

createOpts := users.CreateOpts{
	Name:             "username",
	DomainID:         "default",
	DefaultProjectID: projectID,
	Enabled:          eclcloud.Enabled,
	Password:         "supersecret",
	Extra: map[string]interface{}{
		"email": "username@example.com",
	}
}

user, err := users.Create(identityClient, createOpts).Extract()
if err != nil {
	panic(err)
}

Example to Update a User

userID := "0fe36e73809d46aeae6705c39077b1b3"

updateOpts := users.UpdateOpts{
	Enabled: eclcloud.Disabled,
}

user, err := users.Update(identityClient, userID, updateOpts).Extract()
if err != nil {
	panic(err)
}

Example to Change Password of a User

userID := "0fe36e73809d46aeae6705c39077b1b3"
originalPassword := "secretsecret"
password := "new_secretsecret"

changePasswordOpts := users.ChangePasswordOpts{
	OriginalPassword: originalPassword,
	Password:         password,
}

err := users.ChangePassword(identityClient, userID, changePasswordOpts).ExtractErr()
if err != nil {
	panic(err)
}

Example to Delete a User

userID := "0fe36e73809d46aeae6705c39077b1b3"
err := users.Delete(identityClient, userID).ExtractErr()
if err != nil {
	panic(err)
}

Example to List Groups a User Belongs To

userID := "0fe36e73809d46aeae6705c39077b1b3"

allPages, err := users.ListGroups(identityClient, userID).AllPages()
if err != nil {
	panic(err)
}

allGroups, err := groups.ExtractGroups(allPages)
if err != nil {
	panic(err)
}

for _, group := range allGroups {
	fmt.Printf("%+v\n", group)
}

Example to Add a User to a Group

groupID := "bede500ee1124ae9b0006ff859758b3a"
userID := "0fe36e73809d46aeae6705c39077b1b3"
err := users.AddToGroup(identityClient, groupID, userID).ExtractErr()

if err != nil {
	panic(err)
}

Example to Check Whether a User Belongs to a Group

groupID := "bede500ee1124ae9b0006ff859758b3a"
userID := "0fe36e73809d46aeae6705c39077b1b3"
ok, err := users.IsMemberOfGroup(identityClient, groupID, userID).Extract()
if err != nil {
	panic(err)
}

if ok {
	fmt.Printf("user %s is a member of group %s\n", userID, groupID)
}

Example to Remove a User from a Group

groupID := "bede500ee1124ae9b0006ff859758b3a"
userID := "0fe36e73809d46aeae6705c39077b1b3"
err := users.RemoveFromGroup(identityClient, groupID, userID).ExtractErr()

if err != nil {
	panic(err)
}

Example to List Projects a User Belongs To

userID := "0fe36e73809d46aeae6705c39077b1b3"

allPages, err := users.ListProjects(identityClient, userID).AllPages()
if err != nil {
	panic(err)
}

allProjects, err := projects.ExtractProjects(allPages)
if err != nil {
	panic(err)
}

for _, project := range allProjects {
	fmt.Printf("%+v\n", project)
}

Example to List Users in a Group

groupID := "bede500ee1124ae9b0006ff859758b3a"
listOpts := users.ListOpts{
	DomainID: "default",
}

allPages, err := users.ListInGroup(identityClient, groupID, listOpts).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)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func List

func List(client *eclcloud.ServiceClient, opts ListOptsBuilder) pagination.Pager

List enumerates the Users to which the current token has access.

func ListGroups

func ListGroups(client *eclcloud.ServiceClient, userID string) pagination.Pager

ListGroups enumerates groups user belongs to.

func ListInGroup

func ListInGroup(client *eclcloud.ServiceClient, groupID string, opts ListOptsBuilder) pagination.Pager

ListInGroup enumerates users that belong to a group.

func ListProjects

func ListProjects(client *eclcloud.ServiceClient, userID string) pagination.Pager

ListProjects enumerates groups user belongs to.

Types

type AddToGroupResult

type AddToGroupResult struct {
	eclcloud.ErrResult
}

AddToGroupResult is the response from a AddToGroup operation. Call its ExtractErr method to determine if the request succeeded or failed.

func AddToGroup

func AddToGroup(client *eclcloud.ServiceClient, groupID, userID string) (r AddToGroupResult)

AddToGroup adds a user to a group.

type ChangePasswordOpts

type ChangePasswordOpts struct {
	// OriginalPassword is the original password of the user.
	OriginalPassword string `json:"original_password"`

	// Password is the new password of the user.
	Password string `json:"password"`
}

ChangePasswordOpts provides options for changing password for a user.

func (ChangePasswordOpts) ToUserChangePasswordMap

func (opts ChangePasswordOpts) ToUserChangePasswordMap() (map[string]interface{}, error)

ToUserChangePasswordMap formats a ChangePasswordOpts into a ChangePassword request.

type ChangePasswordOptsBuilder

type ChangePasswordOptsBuilder interface {
	ToUserChangePasswordMap() (map[string]interface{}, error)
}

ChangePasswordOptsBuilder allows extensions to add additional parameters to the ChangePassword request.

type ChangePasswordResult

type ChangePasswordResult struct {
	eclcloud.ErrResult
}

ChangePasswordResult is the response from a ChangePassword operation. Call its ExtractErr method to determine if the request succeeded or failed.

func ChangePassword

func ChangePassword(client *eclcloud.ServiceClient, userID string, opts ChangePasswordOptsBuilder) (r ChangePasswordResult)

ChangePassword changes password for a user.

type CreateOpts

type CreateOpts struct {
	// Name is the name of the new user.
	Name string `json:"name" required:"true"`

	// DefaultProjectID is the ID of the default project of the user.
	DefaultProjectID string `json:"default_project_id,omitempty"`

	// Description is a description of the user.
	Description string `json:"description,omitempty"`

	// DomainID is the ID of the domain the user belongs to.
	DomainID string `json:"domain_id,omitempty"`

	// Enabled sets the user status to enabled or disabled.
	Enabled *bool `json:"enabled,omitempty"`

	// Extra is free-form extra key/value pairs to describe the user.
	Extra map[string]interface{} `json:"-"`

	// Options are defined options in the API to enable certain features.
	Options map[Option]interface{} `json:"options,omitempty"`

	// Password is the password of the new user.
	Password string `json:"password,omitempty"`
}

CreateOpts provides options used to create a user.

func (CreateOpts) ToUserCreateMap

func (opts CreateOpts) ToUserCreateMap() (map[string]interface{}, error)

ToUserCreateMap formats a CreateOpts into a create request.

type CreateOptsBuilder

type CreateOptsBuilder interface {
	ToUserCreateMap() (map[string]interface{}, error)
}

CreateOptsBuilder allows extensions to add additional parameters to the Create request.

type CreateResult

type CreateResult struct {
	// contains filtered or unexported fields
}

CreateResult is the response from a Create operation. Call its Extract method to interpret it as a User.

func Create

func Create(client *eclcloud.ServiceClient, opts CreateOptsBuilder) (r CreateResult)

Create creates a new User.

func (CreateResult) Extract

func (r CreateResult) Extract() (*User, error)

Extract interprets any user results as a User.

type DeleteResult

type DeleteResult struct {
	eclcloud.ErrResult
}

DeleteResult is the response from a Delete operation. Call its ExtractErr to determine if the request succeeded or failed.

func Delete

func Delete(client *eclcloud.ServiceClient, userID string) (r DeleteResult)

Delete deletes a user.

type GetResult

type GetResult struct {
	// contains filtered or unexported fields
}

GetResult is the response from a Get operation. Call its Extract method to interpret it as a User.

func Get

func Get(client *eclcloud.ServiceClient, id string) (r GetResult)

Get retrieves details on a single user, by ID.

func (GetResult) Extract

func (r GetResult) Extract() (*User, error)

Extract interprets any user results as a User.

type InvalidListFilter

type InvalidListFilter struct {
	FilterName string
}

InvalidListFilter is returned by the ToUserListQuery method when validation of a filter does not pass

func (InvalidListFilter) Error

func (e InvalidListFilter) Error() string

type IsMemberOfGroupResult

type IsMemberOfGroupResult struct {
	eclcloud.Result
	// contains filtered or unexported fields
}

IsMemberOfGroupResult is the response from a IsMemberOfGroup operation. Call its Extract method to determine if the request succeeded or failed.

func IsMemberOfGroup

func IsMemberOfGroup(client *eclcloud.ServiceClient, groupID, userID string) (r IsMemberOfGroupResult)

IsMemberOfGroup checks whether a user belongs to a group.

func (IsMemberOfGroupResult) Extract

func (r IsMemberOfGroupResult) Extract() (bool, error)

Extract extracts IsMemberOfGroupResult as bool and error values

type ListOpts

type ListOpts struct {
	// DomainID filters the response by a domain ID.
	DomainID string `q:"domain_id"`

	// Enabled filters the response by enabled users.
	Enabled *bool `q:"enabled"`

	// IdpID filters the response by an Identity Provider ID.
	IdPID string `q:"idp_id"`

	// Name filters the response by username.
	Name string `q:"name"`

	// PasswordExpiresAt filters the response based on expiring passwords.
	PasswordExpiresAt string `q:"password_expires_at"`

	// ProtocolID filters the response by protocol ID.
	ProtocolID string `q:"protocol_id"`

	// UniqueID filters the response by unique ID.
	UniqueID string `q:"unique_id"`

	// Filters filters the response by custom filters such as
	// 'name__contains=foo'
	Filters map[string]string `q:"-"`
}

ListOpts provides options to filter the List results.

func (ListOpts) ToUserListQuery

func (opts ListOpts) ToUserListQuery() (string, error)

ToUserListQuery formats a ListOpts into a query string.

type ListOptsBuilder

type ListOptsBuilder interface {
	ToUserListQuery() (string, error)
}

ListOptsBuilder allows extensions to add additional parameters to the List request

type Option

type Option string

Option is a specific option defined at the API to enable features on a user account.

const (
	IgnoreChangePasswordUponFirstUse Option = "ignore_change_password_upon_first_use"
	IgnorePasswordExpiry             Option = "ignore_password_expiry"
	IgnoreLockoutFailureAttempts     Option = "ignore_lockout_failure_attempts"
	MultiFactorAuthRules             Option = "multi_factor_auth_rules"
	MultiFactorAuthEnabled           Option = "multi_factor_auth_enabled"
)

type RemoveFromGroupResult

type RemoveFromGroupResult struct {
	eclcloud.ErrResult
}

RemoveFromGroupResult is the response from a RemoveFromGroup operation. Call its ExtractErr method to determine if the request succeeded or failed.

func RemoveFromGroup

func RemoveFromGroup(client *eclcloud.ServiceClient, groupID, userID string) (r RemoveFromGroupResult)

RemoveFromGroup removes a user from a group.

type UpdateOpts

type UpdateOpts struct {
	// Name is the name of the new user.
	Name string `json:"name,omitempty"`

	// DefaultProjectID is the ID of the default project of the user.
	DefaultProjectID string `json:"default_project_id,omitempty"`

	// Description is a description of the user.
	Description string `json:"description,omitempty"`

	// DomainID is the ID of the domain the user belongs to.
	DomainID string `json:"domain_id,omitempty"`

	// Enabled sets the user status to enabled or disabled.
	Enabled *bool `json:"enabled,omitempty"`

	// Extra is free-form extra key/value pairs to describe the user.
	Extra map[string]interface{} `json:"-"`

	// Options are defined options in the API to enable certain features.
	Options map[Option]interface{} `json:"options,omitempty"`

	// Password is the password of the new user.
	Password string `json:"password,omitempty"`
}

UpdateOpts provides options for updating a user account.

func (UpdateOpts) ToUserUpdateMap

func (opts UpdateOpts) ToUserUpdateMap() (map[string]interface{}, error)

ToUserUpdateMap formats a UpdateOpts into an update request.

type UpdateOptsBuilder

type UpdateOptsBuilder interface {
	ToUserUpdateMap() (map[string]interface{}, error)
}

UpdateOptsBuilder allows extensions to add additional parameters to the Update request.

type UpdateResult

type UpdateResult struct {
	// contains filtered or unexported fields
}

UpdateResult is the response from an Update operation. Call its Extract method to interpret it as a User.

func Update

func Update(client *eclcloud.ServiceClient, userID string, opts UpdateOptsBuilder) (r UpdateResult)

Update updates an existing User.

func (UpdateResult) Extract

func (r UpdateResult) Extract() (*User, error)

Extract interprets any user results as a User.

type User

type User struct {
	// DefaultProjectID is the ID of the default project of the user.
	DefaultProjectID string `json:"default_project_id"`

	// Description is the description of the user.
	Description string `json:"description"`

	// DomainID is the domain ID the user belongs to.
	DomainID string `json:"domain_id"`

	// Enabled is whether or not the user is enabled.
	Enabled bool `json:"enabled"`

	// Extra is a collection of miscellaneous key/values.
	Extra map[string]interface{} `json:"-"`

	// ID is the unique ID of the user.
	ID string `json:"id"`

	// Links contains referencing links to the user.
	Links map[string]interface{} `json:"links"`

	// Name is the name of the user.
	Name string `json:"name"`

	// Options are a set of defined options of the user.
	Options map[string]interface{} `json:"options"`

	// PasswordExpiresAt is the timestamp when the user's password expires.
	PasswordExpiresAt time.Time `json:"-"`
}

User represents a User in the Enterprise Cloud Identity Service.

func ExtractUsers

func ExtractUsers(r pagination.Page) ([]User, error)

ExtractUsers returns a slice of Users contained in a single page of results.

func (*User) UnmarshalJSON

func (r *User) UnmarshalJSON(b []byte) error

type UserPage

type UserPage struct {
	pagination.LinkedPageBase
}

UserPage is a single page of User results.

func (UserPage) IsEmpty

func (r UserPage) IsEmpty() (bool, error)

IsEmpty determines whether or not a UserPage contains any results.

func (UserPage) NextPageURL

func (r UserPage) NextPageURL() (string, error)

NextPageURL extracts the "next" link from the links section of the result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL