コード例 #1
0
def send_transcript_credentials(pipeline_integration, credentials_payload):
    """
    Sends transcript credentials to video pipeline
    """
    error_response, is_updated = {}, False
    try:
        oauth_client = Application.objects.get(
            name=pipeline_integration.client_name)
    except ObjectDoesNotExist:
        return error_response, is_updated

    client = create_video_pipeline_api_client(oauth_client.client_id,
                                              oauth_client.client_secret)
    error_message = "Unable to update transcript credentials -- org=%s, provider=%s, response=%s"
    try:
        response = client.post(pipeline_integration.api_url,
                               json=credentials_payload)
        response.raise_for_status()
        if response.ok:
            is_updated = True
        else:
            is_updated = False
            error_response = json.loads(response.text)
            log.error(error_message, credentials_payload.get('org'),
                      credentials_payload.get('provider'), response.text)
    except HTTPError as ex:
        is_updated = False
        log.exception(error_message, credentials_payload.get('org'),
                      credentials_payload.get('provider'), ex.response.content)
        error_response = json.loads(ex.response.content)

    return error_response, is_updated
コード例 #2
0
ファイル: api.py プロジェクト: sethips/edx-platform
def update_3rd_party_transcription_service_credentials(**credentials_payload):
    """
    Updates the 3rd party transcription service's credentials.

    Arguments:
        credentials_payload(dict): A payload containing org, provider and its credentials.

    Returns:
        A Boolean specifying whether the credentials were updated or not
        and an error response received from pipeline.
    """
    error_response, is_updated = {}, False
    course_key = credentials_payload.pop('course_key', None)

    if course_key and waffle_flags()[ENABLE_VEM_PIPELINE].is_enabled(
            course_key):
        pipeline_integration = VEMPipelineIntegration.current()
    else:
        pipeline_integration = VideoPipelineIntegration.current()

    if pipeline_integration.enabled:
        try:
            oauth_client = Application.objects.get(
                name=pipeline_integration.client_name)
        except ObjectDoesNotExist:
            return error_response, is_updated

        client = create_video_pipeline_api_client(oauth_client.client_id,
                                                  oauth_client.client_secret)
        error_message = "Unable to update transcript credentials -- org={}, provider={}, response={}"
        try:
            response = client.request("POST",
                                      pipeline_integration.api_url,
                                      json=credentials_payload)
            if response.ok:
                is_updated = True
            else:
                is_updated = False
                error_response = json.loads(response.text)
                log.error(
                    error_message.format(credentials_payload.get('org'),
                                         credentials_payload.get('provider'),
                                         response.text))
        except HttpClientError as ex:
            is_updated = False
            log.exception(
                error_message.format(credentials_payload.get('org'),
                                     credentials_payload.get('provider'),
                                     ex.content))
            error_response = json.loads(ex.content)

    return error_response, is_updated
コード例 #3
0
def update_3rd_party_transcription_service_credentials(**credentials_payload):
    """
    Updates the 3rd party transcription service's credentials.

    Arguments:
        credentials_payload(dict): A payload containing org, provider and its credentials.

    Returns:
        A Boolean specifying whether the credentials were updated or not
        and an error response received from pipeline.
    """
    error_response, is_updated = {}, False
    pipeline_integration = VideoPipelineIntegration.current()
    if pipeline_integration.enabled:
        try:
            video_pipeline_user = pipeline_integration.get_service_user()
            oauth_client = Client.objects.get(
                name=pipeline_integration.client_name)
        except ObjectDoesNotExist:
            return error_response, is_updated

        client = create_video_pipeline_api_client(
            user=video_pipeline_user,
            api_client_id=oauth_client.client_id,
            api_client_secret=oauth_client.client_secret,
            api_url=pipeline_integration.api_url)

        try:
            client.transcript_credentials.post(credentials_payload)
            is_updated = True
        except HttpClientError as ex:
            is_updated = False
            log.exception(
                ('[video-pipeline-service] Unable to update transcript credentials '
                 '-- org=%s -- provider=%s -- response=%s.'),
                credentials_payload.get('org'),
                credentials_payload.get('provider'),
                ex.content,
            )
            error_response = json.loads(ex.content)

    return error_response, is_updated
コード例 #4
0
ファイル: api.py プロジェクト: edx/edx-platform
def update_3rd_party_transcription_service_credentials(**credentials_payload):
    """
    Updates the 3rd party transcription service's credentials.

    Arguments:
        credentials_payload(dict): A payload containing org, provider and its credentials.

    Returns:
        A Boolean specifying whether the credentials were updated or not
        and an error response received from pipeline.
    """
    error_response, is_updated = {}, False
    pipeline_integration = VideoPipelineIntegration.current()
    if pipeline_integration.enabled:
        try:
            video_pipeline_user = pipeline_integration.get_service_user()
            oauth_client = Client.objects.get(name=pipeline_integration.client_name)
        except ObjectDoesNotExist:
            return error_response, is_updated

        client = create_video_pipeline_api_client(
            user=video_pipeline_user,
            api_client_id=oauth_client.client_id,
            api_client_secret=oauth_client.client_secret,
            api_url=pipeline_integration.api_url
        )

        try:
            client.transcript_credentials.post(credentials_payload)
            is_updated = True
        except HttpClientError as ex:
            is_updated = False
            log.exception(
                ('[video-pipeline-service] Unable to update transcript credentials '
                 u'-- org=%s -- provider=%s -- response=%s.'),
                credentials_payload.get('org'),
                credentials_payload.get('provider'),
                ex.content,
            )
            error_response = json.loads(ex.content)

    return error_response, is_updated