def assert_integration_created(self, args, options):
        """
        Verify that the integration record was created.
        """
        integration = VideoPipelineIntegration.current()

        for index, attr in enumerate(('client_name', 'api_url', 'service_username')):
            self.assertEqual(args[index], getattr(integration, attr))

        self.assertEqual(integration.enabled, options.get('enabled'))
    def assert_integration_created(self, args, options):
        """
        Verify that the integration record was created.
        """
        integration = VideoPipelineIntegration.current()

        for index, attr in enumerate(('client_name', 'api_url', 'service_username')):
            self.assertEqual(args[index], getattr(integration, attr))

        self.assertEqual(integration.enabled, options.get('enabled'))
Beispiel #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
    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
Beispiel #4
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
Beispiel #5
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 '
                 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
Beispiel #6
0
def update_3rd_party_transcription_service_credentials(**credentials_payload):
    """
    Updates the 3rd party transcription service's credentials. Credentials are updated
    for all the enabled pipelines.

    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.

    Note: If one of the pipeline fails to update the credentials, False is returned, meaning
    that credentials were not updated and both calls should be tried again.
    """
    error_response, is_updated = {}, False

    vem_pipeline_integration = VEMPipelineIntegration.current()
    veda_pipeline_integration = VideoPipelineIntegration.current()

    if vem_pipeline_integration.enabled:
        log.info(
            'Sending transcript credentials to VEM for org: {} and provider: {}'
            .format(credentials_payload.get('org'),
                    credentials_payload.get('provider')))
        error_response, is_updated = send_transcript_credentials(
            vem_pipeline_integration, credentials_payload)
        # If credentials update fail for VEM, return proper error message and discontinue to
        # send credentials to VEDA because we are going to try it next time anyway
        if not is_updated:
            return error_response, is_updated

    if veda_pipeline_integration.enabled:
        log.info(
            'Sending transcript credentials to VEDA for org: {} and provider: {}'
            .format(credentials_payload.get('org'),
                    credentials_payload.get('provider')))
        error_response, is_updated = send_transcript_credentials(
            veda_pipeline_integration, credentials_payload)

    return error_response, is_updated