Beispiel #1
0
    async def generate_presigned_post(self,
                                      request_dict,
                                      fields=None,
                                      conditions=None,
                                      expires_in=3600,
                                      region_name=None):
        if fields is None:
            fields = {}

        if conditions is None:
            conditions = []

        # Create the policy for the post.
        policy = {}

        # Create an expiration date for the policy
        datetime_now = datetime.datetime.utcnow()
        expire_date = datetime_now + datetime.timedelta(seconds=expires_in)
        policy['expiration'] = expire_date.strftime(botocore.auth.ISO8601)

        # Append all of the conditions that the user supplied.
        policy['conditions'] = []
        for condition in conditions:
            policy['conditions'].append(condition)

        # Store the policy and the fields in the request for signing
        request = create_request_object(request_dict)
        request.context['s3-presign-post-fields'] = fields
        request.context['s3-presign-post-policy'] = policy

        await self._request_signer.sign('PutObject', request, region_name,
                                        'presign-post')
        # Return the url and the fields for th form to post.
        return {'url': request.url, 'fields': fields}
Beispiel #2
0
    async def generate_presigned_url(self, request_dict, operation_name,
                                     expires_in=3600, region_name=None,
                                     signing_name=None):
        request = create_request_object(request_dict)
        await self.sign(operation_name, request, region_name,
                        'presign-url', expires_in, signing_name)

        request.prepare()
        return request.url