Esempio n. 1
0
def get_ozzy_ticket(host, ozzy_email, ozzy_password, logger=None, http_flags={}):
    body = _RENGA_REQUEST_TEMPLATE % (ozzy_email, ozzy_password)
    url = "https://%s/account/amfgateway2" % host
    response = http.request_raw("POST", url, body=body, body_content_type="text/xml", logger=logger, flags=http_flags)
    root = fromstring(response)

    assert root.tag == "RespBody"

    resp_node = root.find("resp")
    assert resp_node is not None
    assert resp_node.get("dest") == "UserManagement"
    assert resp_node.get("api") == "authUserWithCredentials"

    auth_response_node = resp_node.find("AuthResponse")
    assert auth_response_node is not None

    request_results_node = auth_response_node.find("requestResults")
    assert request_results_node is not None
    assert request_results_node.get("class") == "tree-map"

    entry = {}
    for entry_node in request_results_node.findall("entry"):
        entry[entry_node.get("key")] = entry_node.text

    if "ERROR_CODE" in entry:
        error_code = entry["ERROR_CODE"]
        if error_code == "CUS05051":
            raise RuntimeError("Invalid Renga user name or password")
        raise RuntimeError("Renga authentication failed with error code %s" % error_code)

    assert entry["OzzyGetTicket"] == "ok"
    ozzy_ticket = entry["OzzyGetTicket_Ticket"]
    ozzy_nonce  = entry["OzzyGetTicket_TicketNonz"]
    return ozzy_ticket, ozzy_nonce
Esempio n. 2
0
 def __request_ex(self, method, path, query={}, headers={}, upload_mime_type=None, upload_path=None, upload_range_start=None, upload_range_size=None,
                  download_path=None, download_range_start=None, download_range_end=None, port=None, ssl=None, xml_response=True):
     post = dict(dummy="ozzy_requires_post_content") if method == "POST" and upload_path is None else None
     url = self.__get_request_url(path, query, port, ssl)
     response = http.request_raw(method, url, headers=headers, post=post, upload_mime_type=upload_mime_type, upload_path=upload_path,
                                 upload_range_start=upload_range_start, upload_range_size=upload_range_size,
                                 download_path=download_path, download_range_start=download_range_start, download_range_end=download_range_end,
                                 download_chunked=True, return_headers=not xml_response, logger=self.__logger, flags=self.__http_flags)
     if xml_response:
         result = fromstring(response)
         self.__check_result(result)
         return result
     else:
         return response