github.com/opentelekomcloud/gophertelekomcloud@v0.9.3/openstack/dcs/v1/instance/UpdatePassword.go (about)

     1  package instance
     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  type UpdatePasswordOpts struct {
    10  	OldPassword string `json:"old_password"`
    11  	// New password.
    12  	// Password complexity requirements:
    13  	// Cannot be empty.
    14  	// Cannot be the username or the username spelled backwards.
    15  	// Can be 8 to 32 characters long.
    16  	// Contain at least three of the following character types:
    17  	// Lowercase letters
    18  	// Uppercase letters
    19  	// Digits
    20  	// Special characters (`~!@#$^&*()-_=+\|{}:,<.>/?)
    21  	NewPassword string `json:"new_password"`
    22  }
    23  
    24  func UpdatePassword(client *golangsdk.ServiceClient, instanceID string, opts UpdatePasswordOpts) (*UpdatePasswordResponse, error) {
    25  	b, err := build.RequestBody(opts, "")
    26  	if err != nil {
    27  		return nil, err
    28  	}
    29  
    30  	raw, err := client.Put(client.ServiceURL("instances", instanceID, "password"), b, nil, &golangsdk.RequestOpts{
    31  		OkCodes: []int{200},
    32  	})
    33  	if err != nil {
    34  		return nil, err
    35  	}
    36  
    37  	var res UpdatePasswordResponse
    38  	err = extract.Into(raw.Body, &res)
    39  	return &res, err
    40  }
    41  
    42  type UpdatePasswordResponse struct {
    43  	// Account lockout duration. If the old password is incorrect or the account is locked, the value of this parameter is not null.
    44  	LockTime string `json:"lock_time,omitempty"`
    45  	// An indicator of whether the password is successfully changed: Options:
    46  	// Success: Password changed successfully.
    47  	// passwordFailed: The old password is incorrect.
    48  	// Locked: This account has been locked.
    49  	// Failed: Failed to change the password.
    50  	Result string `json:"result,omitempty"`
    51  	// Remaining time before the account is unlocked. If the account is locked, the value of this parameter is not null.
    52  	LockTimeLeft string `json:"lock_time_left,omitempty"`
    53  	// Number of remaining password attempts. If the old password is incorrect, the value of this parameter is not null.
    54  	RetryTimesLeft string `json:"retry_times_left,omitempty"`
    55  	// Result of password change.
    56  	Message string `json:"message,omitempty"`
    57  }