Skip to content

Commit

Permalink
root user pwd change (#637)
Browse files Browse the repository at this point in the history
[IAM]: root user pwd change

What this PR does / why we need it
Added function to change root user password.

Reviewed-by: Artem Sh.
Reviewed-by: Anton Sidelnikov
  • Loading branch information
artem-lifshits authored Mar 22, 2024
1 parent d52d70e commit 9c5bb50
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
22 changes: 22 additions & 0 deletions acceptance/openstack/identity/v3/users_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,25 @@ func TestUserLifecycle(t *testing.T) {
}
th.AssertEquals(t, userUpdateExt.Email, extendedUpdateOpts.Email)
}

func TestRootUserChangePassword(t *testing.T) {
// Don't run this test unless you want to fix your password in clouds.yaml later
if os.Getenv("OS_TENANT_ADMIN_USER_ID") == "" {
t.Skip("Policy doesn't allow NewIdentityV3AdminClient() to be initialized.")
}
if os.Getenv("OS_TENANT_ADMIN_PASSWORD") == "" {
t.Skip("Password not provided.")
}
if os.Getenv("OS_NEW_TENANT_PASSWORD") == "" {
t.Skip("New password not provided.")
}
client, err := clients.NewIdentityV3AdminClient()
th.AssertNoErr(t, err)

err = users.ChangePassword(client, users.ChangePasswordOpts{
UserId: os.Getenv("OS_TENANT_ADMIN_USER_ID"),
OriginalPassword: os.Getenv("OS_TENANT_ADMIN_PASSWORD"),
NewPassword: os.Getenv("OS_NEW_TENANT_PASSWORD"),
})
th.AssertNoErr(t, err)
}
28 changes: 28 additions & 0 deletions openstack/identity/v3/users/ChangePassword.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package users

import (
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
)

type ChangePasswordOpts struct {
UserId string `json:"-"`
OriginalPassword string `json:"original_password"`
NewPassword string `json:"password"`
}

func ChangePassword(client *golangsdk.ServiceClient, opts ChangePasswordOpts) error {
b, err := build.RequestBody(opts, "user")
if err != nil {
return err
}

_, err = client.Post(client.ServiceURL("users", opts.UserId, "password"), b, nil, &golangsdk.RequestOpts{
OkCodes: []int{204},
})
if err != nil {
return err
}

return nil
}

0 comments on commit 9c5bb50

Please sign in to comment.