本文整理汇总了Python中grouper.models.user.User.get方法的典型用法代码示例。如果您正苦于以下问题:Python User.get方法的具体用法?Python User.get怎么用?Python User.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grouper.models.user.User
的用法示例。
在下文中一共展示了User.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_public_key_admin
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def test_public_key_admin(session, users, http_client, base_url): # noqa: F811
user = users["[email protected]"]
assert not get_public_keys_of_user(session, user.id)
# add it
fe_url = url(base_url, "/users/{}/public-key/add".format(user.username))
resp = yield http_client.fetch(
fe_url,
method="POST",
body=urlencode({"public_key": SSH_KEY_1}),
headers={"X-Grouper-User": user.username},
)
assert resp.code == 200
user = User.get(session, name=user.username)
keys = get_public_keys_of_user(session, user.id)
assert len(keys) == 1
assert keys[0].public_key == SSH_KEY_1
# have an admin delete it
fe_url = url(base_url, "/users/{}/public-key/{}/delete".format(user.username, keys[0].id))
resp = yield http_client.fetch(
fe_url, method="POST", body="", headers={"X-Grouper-User": "[email protected]"}
)
assert resp.code == 200
user = User.get(session, name=user.username)
assert not get_public_keys_of_user(session, user.id)
示例2: test_public_key
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def test_public_key(session, users, http_client, base_url): # noqa: F811
user = users["[email protected]"]
assert not get_public_keys_of_user(session, user.id)
# add it
fe_url = url(base_url, "/users/{}/public-key/add".format(user.username))
resp = yield http_client.fetch(
fe_url,
method="POST",
body=urlencode({"public_key": SSH_KEY_ED25519}),
headers={"X-Grouper-User": user.username},
)
assert resp.code == 200
user = User.get(session, name=user.username)
keys = get_public_keys_of_user(session, user.id)
assert len(keys) == 1
assert keys[0].public_key == SSH_KEY_ED25519
assert keys[0].fingerprint == "fa:d9:ca:40:bd:f7:64:37:a7:99:3a:8e:50:8a:c5:94"
assert keys[0].fingerprint_sha256 == "ExrCZ0nqSJv+LqAEh8CWeKUxiAeZA+N0bKC18dK7Adg"
assert keys[0].comment == "comment"
# delete it
fe_url = url(base_url, "/users/{}/public-key/{}/delete".format(user.username, keys[0].id))
resp = yield http_client.fetch(
fe_url, method="POST", body="", headers={"X-Grouper-User": user.username}
)
assert resp.code == 200
user = User.get(session, name=user.username)
assert not get_public_keys_of_user(session, user.id)
示例3: test_public_key
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def test_public_key(session, users, http_client, base_url):
user = users['[email protected]']
assert not get_public_keys_of_user(session, user.id)
# add it
fe_url = url(base_url, '/users/{}/public-key/add'.format(user.username))
resp = yield http_client.fetch(fe_url, method="POST",
body=urlencode({'public_key': SSH_KEY_1}),
headers={'X-Grouper-User': user.username})
assert resp.code == 200
user = User.get(session, name=user.username)
keys = get_public_keys_of_user(session, user.id)
assert len(keys) == 1
assert keys[0].public_key == SSH_KEY_1
assert keys[0].fingerprint == 'e9:ae:c5:8f:39:9b:3a:9c:6a:b8:33:6b:cb:6f:ba:35'
assert keys[0].fingerprint_sha256 == 'MP9uWaujW96EWxbjDtPdPWheoMDu6BZ8FZj0+CBkVWU'
assert keys[0].comment == 'some-comment'
# delete it
fe_url = url(base_url, '/users/{}/public-key/{}/delete'.format(user.username, keys[0].id))
resp = yield http_client.fetch(fe_url, method="POST", body='',
headers={'X-Grouper-User': user.username})
assert resp.code == 200
user = User.get(session, name=user.username)
assert not get_public_keys_of_user(session, user.id)
示例4: test_user_status_changes
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def test_user_status_changes(session, tmpdir, users, groups): # noqa: F811
username = "[email protected]"
groupname = "team-sre"
# add user to a group
call_main(session, tmpdir, "group", "add_member", "--member", groupname, username)
# disable the account
call_main(session, tmpdir, "user", "disable", username)
assert not User.get(session, name=username).enabled
# double disabling is a no-op
call_main(session, tmpdir, "user", "disable", username)
assert not User.get(session, name=username).enabled
# re-enable the account, preserving memberships
call_main(session, tmpdir, "user", "enable", "--preserve-membership", username)
assert User.get(session, name=username).enabled
assert (u"User", username) in groups[groupname].my_members()
# enabling an active account is a no-op
call_main(session, tmpdir, "user", "enable", username)
assert User.get(session, name=username).enabled
# disable and re-enable without the --preserve-membership flag
call_main(session, tmpdir, "user", "disable", username)
call_main(session, tmpdir, "user", "enable", username)
assert User.get(session, name=username).enabled
assert (u"User", username) not in groups[groupname].my_members()
示例5: test_sa_pubkeys
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def test_sa_pubkeys(session, users, http_client, base_url):
user = users['[email protected]']
# Add account
create_role_user(session, user, '[email protected]', 'Hi', 'canjoin')
u = User.get(session, name="[email protected]")
g = Group.get(session, name="[email protected]")
assert u is not None
assert g is not None
assert is_role_user(session, user=u)
assert is_role_user(session, group=g)
assert get_role_user(session, user=u).group.id == g.id
assert get_role_user(session, group=g).user.id == u.id
assert not is_role_user(session, user=user)
assert not is_role_user(session, group=Group.get(session, name="team-sre"))
assert not get_public_keys_of_user(session, user.id)
with pytest.raises(HTTPError):
# add it
fe_url = url(base_url, '/users/{}/public-key/add'.format("[email protected]"))
resp = yield http_client.fetch(fe_url, method="POST",
body=urlencode({'public_key': SSH_KEY_1}),
headers={'X-Grouper-User': "[email protected]"})
# add it
fe_url = url(base_url, '/users/{}/public-key/add'.format("[email protected]"))
resp = yield http_client.fetch(fe_url, method="POST",
body=urlencode({'public_key': SSH_KEY_1}),
headers={'X-Grouper-User': user.username})
assert resp.code == 200
# add bad key -- shouldn't add
fe_url = url(base_url, '/users/{}/public-key/add'.format("[email protected]"))
resp = yield http_client.fetch(fe_url, method="POST",
body=urlencode({'public_key': SSH_KEY_BAD}),
headers={'X-Grouper-User': user.username})
assert resp.code == 200
sa = User.get(session, name="[email protected]")
keys = get_public_keys_of_user(session, sa.id)
assert len(keys) == 1
assert keys[0].public_key == SSH_KEY_1
with pytest.raises(HTTPError):
# delete it
fe_url = url(base_url, '/users/{}/public-key/{}/delete'.format("[email protected]", keys[0].id))
resp = yield http_client.fetch(fe_url, method="POST", body='',
headers={'X-Grouper-User': "[email protected]"})
# delete it
fe_url = url(base_url, '/users/{}/public-key/{}/delete'.format("[email protected]", keys[0].id))
resp = yield http_client.fetch(fe_url, method="POST", body='',
headers={'X-Grouper-User': user.username})
assert resp.code == 200
sa = User.get(session, name="[email protected]")
assert not get_public_keys_of_user(session, sa.id)
示例6: test_user_status_changes
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def test_user_status_changes(make_user_session, make_group_session, session, users, groups):
make_user_session.return_value = session
make_group_session.return_value = session
username = '[email protected]'
groupname = 'team-sre'
# add user to a group
call_main('group', 'add_member', '--member', groupname, username)
# disable the account
call_main('user', 'disable', username)
assert not User.get(session, name=username).enabled
# double disabling is a no-op
call_main('user', 'disable', username)
assert not User.get(session, name=username).enabled
# re-enable the account, preserving memberships
call_main('user', 'enable', '--preserve-membership', username)
assert User.get(session, name=username).enabled
assert (u'User', username) in groups[groupname].my_members()
# enabling an active account is a no-op
call_main('user', 'enable', username)
assert User.get(session, name=username).enabled
# disable and re-enable without the --preserve-membership flag
call_main('user', 'disable', username)
call_main('user', 'enable', username)
assert User.get(session, name=username).enabled
assert (u'User', username) not in groups[groupname].my_members()
示例7: test_add_service_account
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def test_add_service_account(session, users, http_client, base_url):
user = users['[email protected]']
# Add account
fe_url = url(base_url, '/service/create')
resp = yield http_client.fetch(fe_url, method="POST",
body=urlencode({'name': '[email protected]', "description": "Hi", "canjoin": "canjoin"}),
headers={'X-Grouper-User': user.username})
assert resp.code == 200
assert User.get(session, name="[email protected]") is None
assert Group.get(session, name="[email protected]") is None
# Add account
fe_url = url(base_url, '/service/create')
resp = yield http_client.fetch(fe_url, method="POST",
body=urlencode({'name': '[email protected]', "description": "Hi", "canjoin": "canjoin"}),
headers={'X-Grouper-User': user.username})
assert resp.code == 200
u = User.get(session, name="[email protected]")
g = Group.get(session, name="[email protected]")
assert u is not None
assert g is not None
assert is_service_account(session, user=u)
assert is_service_account(session, group=g)
assert get_service_account(session, user=u).group.id == g.id
assert get_service_account(session, group=g).user.id == u.id
assert not is_service_account(session, user=user)
assert not is_service_account(session, group=Group.get(session, name="team-sre"))
示例8: test_user_public_key
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def test_user_public_key(make_session, session, users):
make_session.return_value = session
# good key
username = '[email protected]'
good_key = ('ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDCUQeasspT/etEJR2WUoR+h2sMOQYbJgr0Q'
'E+J8p97gEhmz107KWZ+3mbOwyIFzfWBcJZCEg9wy5Paj+YxbGONqbpXAhPdVQ2TLgxr41bNXvbcR'
'AxZC+Q12UZywR4Klb2kungKz4qkcmSZzouaKK12UxzGB3xQ0N+3osKFj3xA1+B6HqrVreU19XdVo'
'AJh0xLZwhw17/NDM+dAcEdMZ9V89KyjwjraXtOVfFhQF0EDF0ame8d6UkayGrAiXC2He0P2Cja+J'
'371P27AlNLHFJij8WGxvcGGSeAxMLoVSDOOllLCYH5UieV8mNpX1kNe2LeA58ciZb0AXHaipSmCH'
'gh/ some-comment')
call_main('user', 'add_public_key', username, good_key)
user = User.get(session, name=username)
keys = get_public_keys_of_user(session, user.id)
assert len(keys) == 1
assert keys[0].public_key == good_key
# bad key
username = '[email protected]'
bad_key = 'ssh-rsa AAAblahblahkey some-comment'
call_main('user', 'add_public_key', username, good_key)
user = User.get(session, name=username)
keys = get_public_keys_of_user(session, user.id)
assert len(keys) == 1
assert keys[0].public_key == good_key
示例9: post
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def post(self, user_id=None, name=None):
user = User.get(self.session, user_id, name)
if not user:
return self.notfound()
if not self.check_access(self.session, self.current_user, user):
return self.forbidden()
form = UserEnableForm(self.request.arguments)
if not form.validate():
# TODO: add error message
return self.redirect("/users/{}?refresh=yes".format(user.name))
if user.role_user:
enable_service_account(self.session, actor=self.current_user,
preserve_membership=form.preserve_membership.data, user=user)
else:
enable_user(self.session, user, self.current_user,
preserve_membership=form.preserve_membership.data)
self.session.commit()
AuditLog.log(self.session, self.current_user.id, 'enable_user',
'Enabled user.', on_user_id=user.id)
return self.redirect("/users/{}?refresh=yes".format(user.name))
示例10: post
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def post(self):
supplied_token = self.get_body_argument("token")
match = TokenValidate.validator.match(supplied_token)
if not match:
return self.error(((1, "Token format not recognized"),))
sess = Session()
token_name = match.group("token_name")
token_secret = match.group("token_secret")
owner = User.get(sess, name=match.group("name"))
token = UserToken.get(sess, owner, token_name)
if token is None:
return self.error(((2, "Token specified does not exist"),))
if not token.enabled:
return self.error(((3, "Token is disabled"),))
if not token.check_secret(token_secret):
return self.error(((4, "Token secret mismatch"),))
return self.success({
"owner": owner.username,
"identity": str(token),
"act_as_owner": True,
"valid": True,
})
示例11: post
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def post(self, user_id=None, name=None):
user = User.get(self.session, user_id, name)
if not user:
return self.notfound()
if not self.check_access(self.session, self.current_user, user):
return self.forbidden()
form = UserShellForm(self.request.arguments)
form.shell.choices = settings.shell
if not form.validate():
return self.render(
"user-shell.html", form=form, user=user,
alerts=self.get_form_alerts(form.errors),
)
user.set_metadata(USER_METADATA_SHELL_KEY, form.data["shell"])
user.add(self.session)
self.session.commit()
AuditLog.log(self.session, self.current_user.id, 'changed_shell',
'Changed shell: {}'.format(form.data["shell"]),
on_user_id=user.id)
return self.redirect("/users/{}?refresh=yes".format(user.name))
示例12: role
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def role(self, role):
prev_role = self._role
self._role = GROUP_EDGE_ROLES.index(role)
# Groups should always "member".
if not (OBJ_TYPES_IDX[self.member_type] == "User"):
return
# If ownership status is unchanged, no notices need to be adjusted.
if (self._role in OWNER_ROLE_INDICES) == (prev_role in OWNER_ROLE_INDICES):
return
recipient = User.get(self.session, pk=self.member_pk).username
expiring_supergroups = self.group.my_expiring_groups()
member_name = self.group.name
if role in ["owner", "np-owner"]:
# We're creating a new owner, who should find out when this group
# they now own loses its membership in larger groups.
for supergroup_name, expiration in expiring_supergroups:
AsyncNotification.add_expiration(self.session,
expiration,
group_name=supergroup_name,
member_name=member_name,
recipients=[recipient],
member_is_user=False)
else:
# We're removing an owner, who should no longer find out when this
# group they no longer own loses its membership in larger groups.
for supergroup_name, _ in expiring_supergroups:
AsyncNotification.cancel_expiration(self.session,
group_name=supergroup_name,
member_name=member_name,
recipients=[recipient])
示例13: test_user_public_key
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def test_user_public_key(make_session, session, users):
make_session.return_value = session
# good key
username = '[email protected]'
call_main('user', 'add_public_key', username, SSH_KEY_1)
user = User.get(session, name=username)
keys = get_public_keys_of_user(session, user.id)
assert len(keys) == 1
assert keys[0].public_key == SSH_KEY_1
# duplicate key
call_main('user', 'add_public_key', username, SSH_KEY_1)
keys = get_public_keys_of_user(session, user.id)
assert len(keys) == 1
assert keys[0].public_key == SSH_KEY_1
# bad key
call_main('user', 'add_public_key', username, SSH_KEY_BAD)
keys = get_public_keys_of_user(session, user.id)
assert len(keys) == 1
assert keys[0].public_key == SSH_KEY_1
示例14: get_role_user
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def get_role_user(session, user=None, group=None):
# type: (Session, User, Group) -> RoleUser
"""
Takes in a User or a Group and returns a dictionary that contains
all of the service account components for the service account that
the user/group is part of.
Args:
session: the database session
user: a User object to check
group: a Group object to check
Throws:
RoleUserNotFound: if the user or group is not part of a service account
Returns:
a dictionary with all components of the service account of the
user or group passed in
"""
if not is_role_user(session, user, group):
raise RoleUserNotFound()
if user:
name = user.name
else:
assert group is not None
name = group.name
return RoleUser(User.get(session, name=name), Group.get(session, name=name))
示例15: get
# 需要导入模块: from grouper.models.user import User [as 别名]
# 或者: from grouper.models.user.User import get [as 别名]
def get(self, user_id=None, name=None):
self.handle_refresh()
user = User.get(self.session, user_id, name)
if not user:
return self.notfound()
if user.role_user:
return self.redirect("/service/{}".format(user_id or name))
if user.is_service_account:
service_account = user.service_account
if service_account.owner:
return self.redirect("/groups/{}/service/{}".format(
service_account.owner.group.name, user.username))
else:
self.render(
"service-account.html", service_account=service_account, group=None, user=user,
**get_user_view_template_vars(self.session, self.current_user, user, self.graph)
)
return
self.render("user.html",
user=user,
**get_user_view_template_vars(self.session, self.current_user, user, self.graph)
)