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() 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) return error_response, is_updated
def storage_service_bucket(course_key=None): """ Returns an S3 bucket for video upload. The S3 bucket returned depends on which pipeline, VEDA or VEM, is enabled. """ if waffle_flags()[ENABLE_DEVSTACK_VIDEO_UPLOADS].is_enabled(): credentials = AssumeRole.get_instance().credentials params = { 'aws_access_key_id': credentials['access_key'], 'aws_secret_access_key': credentials['secret_key'], 'security_token': credentials['session_token'] } else: params = { 'aws_access_key_id': settings.AWS_ACCESS_KEY_ID, 'aws_secret_access_key': settings.AWS_SECRET_ACCESS_KEY } conn = s3.connection.S3Connection(**params) vem_pipeline = VEMPipelineIntegration.current() course_hash_value = get_course_hash_value(course_key) vem_override = course_key and waffle_flags()[ENABLE_VEM_PIPELINE].is_enabled(course_key) allow_course_to_use_vem = vem_pipeline.enabled and course_hash_value < vem_pipeline.vem_enabled_courses_percentage # We don't need to validate our bucket, it requires a very permissive IAM permission # set since behind the scenes it fires a HEAD request that is equivalent to get_all_keys() # meaning it would need ListObjects on the whole bucket, not just the path used in each # environment (since we share a single bucket for multiple deployments in some configurations) if vem_override or allow_course_to_use_vem: LOGGER.info('Uploading course: {} to VEM bucket.'.format(course_key)) return conn.get_bucket(settings.VIDEO_UPLOAD_PIPELINE['VEM_S3_BUCKET'], validate=False) else: return conn.get_bucket(settings.VIDEO_UPLOAD_PIPELINE['BUCKET'], validate=False)
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