Exemplo n.º 1
0
def _generate_blob_sas_url(prefix, extension):
    """
    Helper to generate SAS URL for creating a BLOB.
    """
    blob_name = '{0}/{1}{2}'.format(prefix, str(uuid4()), extension)

    if settings.USE_AWS:
        return {
            'url':
            _make_url_sassy(blob_name, permission='w', duration=60 * 60 * 24),
            'id':
            blob_name
        }
    else:
        url = make_blob_sas_url(settings.BUNDLE_AZURE_ACCOUNT_NAME,
                                settings.BUNDLE_AZURE_ACCOUNT_KEY,
                                settings.BUNDLE_AZURE_CONTAINER,
                                blob_name,
                                permission='w',
                                duration=60 * 60 * 24)
        logger.debug("_generate_blob_sas_url: sas=%s; blob_name=%s.", url,
                     blob_name)
        return {
            'url': url,
            'id': blob_name,
            'version': PREFERRED_STORAGE_X_MS_VERSION
        }
Exemplo n.º 2
0
    def get(self, request, *args, **kwargs):
        submission_id = self.kwargs.get('submission_id')
        try:
            sub = CompetitionSubmission.objects.get(pk=submission_id)
            log_sas_urls = {}
            if sub:
                for log_attr in self.logs_to_grab:
                    # TODO: Will this cause errors when None? Did not have this occur when testing with Eric
                    temp_log_field = getattr(sub, log_attr)
                    if hasattr(temp_log_field, 'file'):
                        if log_attr == 'detailed_results_file':
                            if not sub.phase.competition.enable_detailed_results:
                                continue
                        log_sas_urls[log_attr] = _make_url_sassy(
                            temp_log_field.file.name,
                            permission='r',
                            duration=
                            604800  # 604800 = 60 * 60 * 24 * 7 (1 week), limited by Amazon >:(
                        )
            if not sub.participant.user == self.request.user:
                raise PermissionDenied("Not authorized!")
            try:
                scores = sub.phase.scores(
                    include_scores_not_on_leaderboard=True)
                headers = list(
                    sorted(scores[0]['headers'],
                           key=lambda x: x.get('ordering')))
                default_score_key = headers[0]['key']

                for group in scores:
                    for _, scoredata in group['scores']:
                        try:
                            default_score = next(
                                val for val in scoredata['values']
                                if val['name'] == default_score_key)
                            if int(scoredata['id']) == int(submission_id):
                                temp_data = {
                                    'score': default_score['val'],
                                    'status': sub.status.codename,
                                    'logs': log_sas_urls
                                }
                                return Response(temp_data,
                                                status=status.HTTP_200_OK)
                        except (KeyError, StopIteration):
                            pass
            except (KeyError, IndexError):
                pass
        except CompetitionSubmission.DoesNotExist:
            # This one is specific to not being able to find the submission
            raise Http404(
                "Submission is not on leaderboard or is not accessible!")
        # This one is for if anything else goes wrong in the logic, our default response is an Http404.
        raise Http404("Could not retrieve submission info!")
def _generate_blob_sas_url(prefix, extension):
    """
    Helper to generate SAS URL for creating a BLOB.
    """
    blob_name = '{0}/{1}{2}'.format(prefix, str(uuid4()), extension)

    if settings.USE_AWS:
        return {'url': _make_url_sassy(blob_name, permission='w', duration=60 * 60 * 24), 'id': blob_name}
    else:
        url = make_blob_sas_url(settings.BUNDLE_AZURE_ACCOUNT_NAME,
                                settings.BUNDLE_AZURE_ACCOUNT_KEY,
                                settings.BUNDLE_AZURE_CONTAINER,
                                blob_name,
                                permission='w',
                                duration=60 * 60 * 24)
        logger.debug("_generate_blob_sas_url: sas=%s; blob_name=%s.", url, blob_name)
        return {'url': url, 'id': blob_name, 'version': PREFERRED_STORAGE_X_MS_VERSION}
Exemplo n.º 4
0
    def handle(self, *args, **options):
        if len(args) == 0:
            raise Exception(
                "the relative dump file path is required -- it is stored in /app/backups so you do not "
                "need to specify full path")
        dump_name = args[0]
        dump_path = join("/app/backups", dump_name)

        # Upload it
        print "Uploading backup '{}'".format(dump_path)
        upload_url = _make_url_sassy('backups/{}'.format(dump_name),
                                     permission='w')
        _put_blob(upload_url, dump_path)

        # Clean up
        print "Success! Removing local dump file '{}'".format(dump_path)
        remove(dump_path)
Exemplo n.º 5
0
def get_sas(value):
    """
    Helper to generate SAS URL for any BLOB.
    """
    return _make_url_sassy(value)
Exemplo n.º 6
0
def get_sas(value):
    """
    Helper to generate SAS URL for any BLOB.
    """
    return _make_url_sassy(value)