Skip to content

Commit 9c5bb50

Browse files
root user pwd change (#637)
[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
1 parent d52d70e commit 9c5bb50

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

acceptance/openstack/identity/v3/users_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,25 @@ func TestUserLifecycle(t *testing.T) {
9999
}
100100
th.AssertEquals(t, userUpdateExt.Email, extendedUpdateOpts.Email)
101101
}
102+
103+
func TestRootUserChangePassword(t *testing.T) {
104+
// Don't run this test unless you want to fix your password in clouds.yaml later
105+
if os.Getenv("OS_TENANT_ADMIN_USER_ID") == "" {
106+
t.Skip("Policy doesn't allow NewIdentityV3AdminClient() to be initialized.")
107+
}
108+
if os.Getenv("OS_TENANT_ADMIN_PASSWORD") == "" {
109+
t.Skip("Password not provided.")
110+
}
111+
if os.Getenv("OS_NEW_TENANT_PASSWORD") == "" {
112+
t.Skip("New password not provided.")
113+
}
114+
client, err := clients.NewIdentityV3AdminClient()
115+
th.AssertNoErr(t, err)
116+
117+
err = users.ChangePassword(client, users.ChangePasswordOpts{
118+
UserId: os.Getenv("OS_TENANT_ADMIN_USER_ID"),
119+
OriginalPassword: os.Getenv("OS_TENANT_ADMIN_PASSWORD"),
120+
NewPassword: os.Getenv("OS_NEW_TENANT_PASSWORD"),
121+
})
122+
th.AssertNoErr(t, err)
123+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package users
2+
3+
import (
4+
golangsdk "github.com/opentelekomcloud/gophertelekomcloud"
5+
"github.com/opentelekomcloud/gophertelekomcloud/internal/build"
6+
)
7+
8+
type ChangePasswordOpts struct {
9+
UserId string `json:"-"`
10+
OriginalPassword string `json:"original_password"`
11+
NewPassword string `json:"password"`
12+
}
13+
14+
func ChangePassword(client *golangsdk.ServiceClient, opts ChangePasswordOpts) error {
15+
b, err := build.RequestBody(opts, "user")
16+
if err != nil {
17+
return err
18+
}
19+
20+
_, err = client.Post(client.ServiceURL("users", opts.UserId, "password"), b, nil, &golangsdk.RequestOpts{
21+
OkCodes: []int{204},
22+
})
23+
if err != nil {
24+
return err
25+
}
26+
27+
return nil
28+
}

0 commit comments

Comments
 (0)