Exemplo n.º 1
0
def s3signatures(request):
    """ Returns a signature so that files can be uploaded to the s3 materials bucket """

    if 's3_object_name' not in request.QUERY_PARAMS:
        return Response({"message": "missing s3_object_name from request"},
                        status=status.HTTP_400_BAD_REQUEST)

    s3name = upload_path(request.user.username,
                         request.QUERY_PARAMS['s3_object_name'])
    # Canonical strings and key signing are documented in the s3 developer guide.
    # http://s3.amazonaws.com/doc/s3-developer-guide/RESTAuthentication.html
    amz_date = datetime.datetime.now(
        tzlocal()).strftime('%a, %d %b %Y %H:%M:%S %Z')
    canonical_string = "POST\n\n\nx-amz-date:{}\n{}".format(amz_date, s3name)
    h = hmac.new(settings.AWS_SECRET_ACCESS_KEY, canonical_string, sha)
    signature = base64.encodestring(h.digest()).strip()

    return Response({
        'signed_request':
        signature,
        'url':
        s3name,
        'key_id':
        settings.AWS_ACCESS_KEY_ID,
        'x-amz-date':
        amz_date,
        'canonical_string':
        canonical_string,
        'Authorization':
        'AWS {}:{}'.format(settings.AWS_ACCESS_KEY_ID, signature),
    })
Exemplo n.º 2
0
def s3signatures(request):
    """ Returns a signature so that files can be uploaded to the s3 materials bucket """

    if 's3_object_name' not in request.QUERY_PARAMS:
        return Response({"message": "missing s3_object_name from request"}, status=status.HTTP_400_BAD_REQUEST)

    s3name = upload_path(request.user.username, request.QUERY_PARAMS['s3_object_name'])
    # Canonical strings and key signing are documented in the s3 developer guide.
    # http://s3.amazonaws.com/doc/s3-developer-guide/RESTAuthentication.html
    amz_date = datetime.datetime.now(tzlocal()).strftime('%a, %d %b %Y %H:%M:%S %Z')
    canonical_string = "POST\n\n\nx-amz-date:{}\n{}".format(amz_date, s3name)
    h = hmac.new(settings.AWS_SECRET_ACCESS_KEY, canonical_string, sha)
    signature = base64.encodestring(h.digest()).strip()

    return Response({
        'signed_request': signature,
        'url': s3name,
        'key_id': settings.AWS_ACCESS_KEY_ID,
        'x-amz-date': amz_date,
        'canonical_string': canonical_string,
        'Authorization': 'AWS {}:{}'.format(settings.AWS_ACCESS_KEY_ID, signature),
    })
Exemplo n.º 3
0
 def upload_materials_callback(self, filename):
     return upload_path('materials', filename)
Exemplo n.º 4
0
 def upload_article_callback(self, filename):
     return upload_path('articles', filename)
Exemplo n.º 5
0
 def upload_callback(self, filename):
     return upload_path('results', filename)
Exemplo n.º 6
0
 def upload_materials_callback(self, filename):
     return upload_path('materials', filename)
Exemplo n.º 7
0
 def upload_article_callback(self, filename):
     return upload_path('articles', filename)
Exemplo n.º 8
0
 def upload_callback(self, filename):
     return upload_path('results', filename)