github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/identity/v3.0/users/CreateUser.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  // CreateOpts provides options used to create a user.
    10  type CreateOpts struct {
    11  	// Name is the name of the new user.
    12  	Name string `json:"name" required:"true"`
    13  
    14  	// DomainID is the ID of the domain the user belongs to.
    15  	DomainID string `json:"domain_id" required:"true"`
    16  
    17  	// Password is the password of the new user.
    18  	Password string `json:"password,omitempty"`
    19  
    20  	// Email address with a maximum of 255 characters
    21  	Email string `json:"email,omitempty"`
    22  
    23  	// AreaCode is a country code, must be used together with Phone.
    24  	AreaCode string `json:"areacode,omitempty"`
    25  
    26  	// Phone is a mobile number with a maximum of 32 digits, must be used together with AreaCode.
    27  	Phone string `json:"phone,omitempty"`
    28  
    29  	// Description is a description of the user.
    30  	Description string `json:"description,omitempty"`
    31  
    32  	// AccessMode is the access type for IAM user
    33  	AccessMode string `json:"access_mode,omitempty"`
    34  
    35  	// Enabled sets the user status to enabled or disabled.
    36  	Enabled *bool `json:"enabled,omitempty"`
    37  
    38  	// PasswordReset Indicates whether password reset is required at the first login.
    39  	// By default, password reset is true.
    40  	PasswordReset *bool `json:"pwd_status,omitempty"`
    41  }
    42  
    43  func CreateUser(client *golangsdk.ServiceClient, opts CreateOpts) (*User, error) {
    44  	b, err := build.RequestBody(opts, "user")
    45  	if err != nil {
    46  		return nil, err
    47  	}
    48  
    49  	// POST /v3.0/OS-USER/users
    50  	raw, err := client.Post(client.ServiceURL("OS-USER", "users"), b, nil, nil)
    51  	if err != nil {
    52  		return nil, err
    53  	}
    54  
    55  	var res User
    56  	return &res, extract.IntoStructPtr(raw.Body, &res, "user")
    57  }
    58  
    59  // User represents a User in the OpenStack Identity Service.
    60  type User struct {
    61  	ID                string `json:"id"`
    62  	DomainID          string `json:"domain_id"`
    63  	Name              string `json:"name"`
    64  	Email             string `json:"email"`
    65  	AreaCode          string `json:"areacode"`
    66  	Phone             string `json:"phone"`
    67  	Description       string `json:"description"`
    68  	AccessMode        string `json:"access_mode"`
    69  	Enabled           bool   `json:"enabled"`
    70  	PasswordStatus    bool   `json:"pwd_status"`
    71  	PasswordStrength  string `json:"pwd_strength"`
    72  	PasswordExpiresAt string `json:"password_expires_at"`
    73  	IsDomainOwner     bool   `json:"is_domain_owner"`
    74  	CreateAt          string `json:"create_time"`
    75  	UpdateAt          string `json:"update_time"`
    76  	LastLogin         string `json:"last_login_time"`
    77  	Status            string `json:"status"`
    78  	XuserID           string `json:"xuser_id"`
    79  	XuserType         string `json:"xuser_type"`
    80  }