def get_user_id(server, auth_token, site_id, username_to_audit):
"""
Returns the user id of the user to audit permissions for, if found.
'server' specified server address
'auth_token' authentication token that grants user access to API calls
'site_id' ID of the site that the user is signed into
'username_to_audit' username to audit permission for on server
"""
url = server + "/api/{0}/sites/{1}/users".format(VERSION, site_id)
server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
_check_status(server_response, 200)
server_response = ET.fromstring(_encode_for_display(server_response.text))
# Find all user tags in the response and look for matching id
users = server_response.findall('.//t:user', namespaces=xmlns)
for user in users:
if user.get('name') == username_to_audit:
return user.get('id')
error = "User id for {0} not found".format(username_to_audit)
raise LookupError(error)
评论列表
文章目录