github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/identity/v3.0/users/ModifyUser.go (about)

     1  package users
     2  
     3  import (
     4  	golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
     5  	"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
     6  	"github.com/opentelekomcloud/gophertelekomcloud/internal/extract"
     7  )
     8  
     9  // UpdateOpts provides options used to create a user.
    10  type UpdateOpts struct {
    11  	// Name is the name of the new user.
    12  	Name string `json:"name,omitempty"`
    13  
    14  	// Password is the password of the new user.
    15  	Password string `json:"password,omitempty"`
    16  
    17  	// Email address with a maximum of 255 characters
    18  	Email string `json:"email,omitempty"`
    19  
    20  	// AreaCode is a country code, must be used together with Phone.
    21  	AreaCode string `json:"areacode,omitempty"`
    22  
    23  	// Phone is a mobile number with a maximum of 32 digits, must be used together with AreaCode.
    24  	Phone string `json:"phone,omitempty"`
    25  
    26  	// Description is a description of the user.
    27  	Description string `json:"description,omitempty"`
    28  
    29  	// AccessMode is the access type for IAM user
    30  	AccessMode string `json:"access_mode,omitempty"`
    31  
    32  	// Enabled sets the user status to enabled or disabled.
    33  	Enabled *bool `json:"enabled,omitempty"`
    34  
    35  	// PasswordReset Indicates whether password reset is required at the first login.
    36  	// By default, password reset is true.
    37  	PasswordReset *bool `json:"pwd_status,omitempty"`
    38  }
    39  
    40  func ModifyUser(client *golangsdk.ServiceClient, id string, opts UpdateOpts) (*User, error) {
    41  	b, err := build.RequestBody(opts, "user")
    42  	if err != nil {
    43  		return nil, err
    44  	}
    45  
    46  	// PUT /v3.0/OS-USER/users/{user_id}
    47  	raw, err := client.Put(client.ServiceURL("OS-USER", "users", id), b, nil, &golangsdk.RequestOpts{
    48  		OkCodes: []int{200},
    49  	})
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  
    54  	var res User
    55  	return &res, extract.IntoStructPtr(raw.Body, &res, "user")
    56  }