openstacksdk如何更改当前用户密码 [英] how openstacksdk change current user password
问题描述
我找到了 CLI 或 API 请求 方法,它们对我有用,如下所示:
I found the CLI or API request methods and they work for me, like this:
# source /etc/kolla/admin-openrc.sh
# openstack user password set --password newpsw --original-password oripsw
Or
# source /etc/kolla/admin-openrc.sh
# curl -v -s -X POST $OS_AUTH_URL/auth/tokens?nocatalog
-H "Content-Type: application/json"
-d '{ "auth": { "identity": { "methods": ["password"],
"password": {"user": {"domain": {"name": "'"$OS_USER_DOMAIN_NAME"'"},
"name": "'"$OS_USERNAME"'", "password": "'"$OS_PASSWORD"'"} } },
"scope": { "project": { "domain": { "name": "'"$OS_PROJECT_DOMAIN_NAME"'" },
"name": "'"$OS_PROJECT_NAME"'" } } }}'
< HTTP/1.1 201 CREATED
< Date: Mon, 18 Oct 2021 11:44:39 GMT
< Server: Apache
< Content-Length: 720
< X-Subject-Token: gAAAAABhbV4o9WvatToB4Z7dUhaNqyYqpwUt4T3wwOmnN2-YCioaSYZ-HpqdWNDvAq0pvnSe6qIuvoZXOIUjmxxUu03tWk2mp2TOJ_LTLECXOHqlQT22vqNvgJj_YTgOWbwHVlrrqbkcUWM4WDvbsD1HjM8xiEYidSNMzpw2LOHtO43cIN0nyvs
< Vary: X-Auth-Token
# export OS_TOKEN=gAAAAABhbV4o9WvatToB4Z7dUhaNqyYqpwUt4T3wwOmnN2-YCioaSYZ-HpqdWNDvAq0pvnSe6qIuvoZXOIUjmxxUu03tWk2mp2TOJ_LTLECXOHqlQT22vqNvgJj_YTgOWbwHVlrrqbkcUWM4WDvbsD1HjM8xiEYidSNMzpw2LOHtO43cIN0nyvs
# curl --header "Content-Type: application/json" --request POST --data '{"user":{"password":"123","original_password":"aaa"}}' http://10.32.17.172:5000/v3/users/e1c5cc75489f4e0cbb05c39d03b46097/password
API请求最后的Change password for user
方法文档.
但我需要通过使用 openstacksdk 在我们的项目中,我在 openstacksdk
文档中找到了最后一个方法 -- update_user(user, **attrs)
,它似乎最像我寻找.不幸的是, openstack.identity.v3.user 实例 没有original_password
,我的代码无法运行:
But I need to achieve that by using openstacksdk in our project, I found the last method in the openstacksdk
documentation -- update_user(user, **attrs)
, it seems the most like I look for. Unfortunately, the openstack.identity.v3.user instance doesn't have the original_password
, and my code can't work:
import openstack
conn = openstack.connect(
region_name = 'RegionOne',
auth_url = 'http://10.32.17.172:35357/v3',
domain_name = 'Default',
project_name = 'admin',
username = 'admin',
password = '123'
)
user_args = {
"name":"admin",
"pasword":'aaa', # new password
"password_expires_at":None,
"links":{u'self': u'http://10.32.17.172:5000/v3/users/e1c5cc75489f4e0cbb05c39d03b46097'},
"enabled":True,
"domain_id":"default",
"original_password": "123",
}
conn.identity.update_user(user_args)
如何通过 openstacksdk
实现更改当前用户密码?提前谢谢.
How could I implement change current user passord by openstacksdk
? Thanks advance.
推荐答案
这样解决:
import openstack
conn = openstack.connect(
...
)
user_args = {
"id":"e1c5cc75489f4e0cbb05c39d03b46097"
}
user = conn.identity.get_user(user_args)
user.description = "test_update_psw"
user.password="123456"
conn.identity.update_user(user)
更新用户信息应该使用 user
对象,而不是像问题代码那样的 dictionary
.
Update the user's info should use the user
object instead of the dictionary
like the question's code.
为我糟糕的程序语言技能和缺乏 API 文档知识感到羞耻.
Shame of my bad program language skill and lack of API documentation knowledge.
这篇关于openstacksdk如何更改当前用户密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!