Ejemplo n.º 1
0
def get_file_as_string(digest_login, url):
    """
    Get the file content as a string

    :param url: The url to the file
    :type url: str
    :param digest_login: The login credentials for digest authentication
    :type digest_login: DigestLogin
    :return: The file content
    :rtype: str
    :raise RequestError:
    """

    response = get_request(url, digest_login, "file")
    return get_string_content(response)
Ejemplo n.º 2
0
def accepts_url(digest_login, server_url, url_to_sign):
    """
    Checks if a URL can be signed.

    :param digest_login: The login credentials for digest auth
    :type digest_login: DigestLogin
    :param server_url: The server URL
    :type server_url: str
    :param url_to_sign: The url to check
    :type url_to_sign: str
    :return: If the URL can be signed.
    :rtype: bool
    :raise RequestError:
    """

    url = '{}/signing/accepts?baseUrl={}'.format(server_url, url_to_sign)
    response = get_request(url, digest_login, "URL signing check")
    return get_string_content(response) == "true"
Ejemplo n.º 3
0
def get_media_package(base_url, digest_login, mp_id):
    """
    Get a media package from the asset manager.

    :param base_url: The URL for the request
    :type base_url: str
    :param digest_login: The login credentials for digest authentication
    :type digest_login: DigestLogin
    :param mp_id: The ID of the media package
    :type mp_id: str
    :return: A media package definition in XML format
    :rtype str:
    """

    url = '{}/assets/episode/{}'.format(base_url, mp_id)

    response = get_request(url, digest_login, "media package")

    media_package = get_string_content(response)

    return media_package
Ejemplo n.º 4
0
def sign_url(digest_login, server_url, url_to_sign):
    """
    Get a URL signed for 2 hours.

    :param digest_login: The login credentials for digest auth
    :type digest_login: DigestLogin
    :param server_url: The server URL
    :type server_url: str
    :param url_to_sign: The url to be signed
    :type url_to_sign: str
    :return: The signed URL
    :rtype: str
    :raise RequestError:
    """

    now = datetime.now()
    two_hours = timedelta(hours=2)
    two_hours_from_now = now + two_hours
    two_hours_from_now_timestamp = int(two_hours_from_now.timestamp())

    url = '{}/signing/sign?baseUrl={}&validUntil={}'.format(server_url, url_to_sign, two_hours_from_now_timestamp)
    response = get_request(url, digest_login, "signed URL")
    return get_string_content(response)