def _serialize_data(self, serialized, data): if serialized['method'].lower() == "get": serialized['body'] = {} serialized['query_string'].update(data) else: serialized['body'] = json.dumps(data).encode(self.DEFAULT_ENCODING) return serialized
def add_auth(self, request): fields = {} if request.context.get('s3-presign-post-fields', None) is not None: fields = request.context['s3-presign-post-fields'] policy = {} conditions = [] if request.context.get('s3-presign-post-policy', None) is not None: policy = request.context['s3-presign-post-policy'] if policy.get('conditions', None) is not None: conditions = policy['conditions'] policy['conditions'] = conditions fields['AWSAccessKeyId'] = self.credentials.access_key if self.credentials.token is not None: fields['x-amz-security-token'] = self.credentials.token conditions.append({'x-amz-security-token': self.credentials.token}) # Dump the base64 encoded policy into the fields dictionary. fields['policy'] = base64.b64encode( json.dumps(policy).encode('utf-8')).decode('utf-8') fields['signature'] = self.sign_string(fields['policy']) request.context['s3-presign-post-fields'] = fields request.context['s3-presign-post-policy'] = policy
def serialize_to_request(self, parameters, operation_model): serialized = JSONSerializer.serialize_to_request(self, parameters, operation_model) query_params = self.MAP_TYPE() query_params['Action'] = operation_model.name query_params['Version'] = operation_model.metadata['apiVersion'] serialized['query_string'] = query_params headers = {'Content-Type': 'application/json', 'Accept': 'application/json'} serialized['headers'].update(headers) body = {} input_shape = operation_model.input_shape if input_shape is not None: self._serialize(body, parameters, input_shape) serialized['body'] = json.dumps(body).encode(self.DEFAULT_ENCODING) return serialized
def serialize_to_request(self, parameters, operation_model): target = '%s.%s' % (operation_model.metadata['targetPrefix'], operation_model.name) json_version = operation_model.metadata['jsonVersion'] serialized = self._create_default_request() serialized['method'] = operation_model.http.get( 'method', self.DEFAULT_METHOD) serialized['headers'] = { 'X-Amz-Target': target, 'Content-Type': 'application/x-amz-json-%s' % json_version, } body = {} input_shape = operation_model.input_shape if input_shape is not None: self._serialize(body, parameters, input_shape) serialized['body'] = json.dumps(body).encode(self.DEFAULT_ENCODING) return serialized
def serialize_to_request(self, parameters, operation_model): target = '%s.%s' % (operation_model.metadata['targetPrefix'], operation_model.name) json_version = operation_model.metadata['jsonVersion'] serialized = self._create_default_request() serialized['method'] = operation_model.http.get('method', self.DEFAULT_METHOD) serialized['headers'] = { 'X-Amz-Target': target, 'Content-Type': 'application/x-amz-json-%s' % json_version, } body = {} input_shape = operation_model.input_shape if input_shape is not None: self._serialize(body, parameters, input_shape) serialized['body'] = json.dumps(body).encode(self.DEFAULT_ENCODING) return serialized
def add_auth(self, request): datetime_now = datetime.datetime.utcnow() request.context['timestamp'] = datetime_now.strftime(SIGV4_TIMESTAMP) fields = {} if request.context.get('s3-presign-post-fields', None) is not None: fields = request.context['s3-presign-post-fields'] policy = {} conditions = [] if request.context.get('s3-presign-post-policy', None) is not None: policy = request.context['s3-presign-post-policy'] if policy.get('conditions', None) is not None: conditions = policy['conditions'] policy['conditions'] = conditions fields['x-amz-algorithm'] = 'AWS4-HMAC-SHA256' fields['x-amz-credential'] = self.scope(request) fields['x-amz-date'] = request.context['timestamp'] conditions.append({'x-amz-algorithm': 'AWS4-HMAC-SHA256'}) conditions.append({'x-amz-credential': self.scope(request)}) conditions.append({'x-amz-date': request.context['timestamp']}) if self.credentials.token is not None: fields['x-amz-security-token'] = self.credentials.token conditions.append({'x-amz-security-token': self.credentials.token}) # Dump the base64 encoded policy into the fields dictionary. fields['policy'] = base64.b64encode( json.dumps(policy).encode('utf-8')).decode('utf-8') fields['x-amz-signature'] = self.signature(fields['policy'], request) request.context['s3-presign-post-fields'] = fields request.context['s3-presign-post-policy'] = policy
def _serialize_body_params(self, params, shape): serialized_body = self.MAP_TYPE() self._serialize(serialized_body, params, shape) return json.dumps(serialized_body).encode(self.DEFAULT_ENCODING)
def _serialize_data(self, serialized, data): serialized['body'] = json.dumps(data).encode(self.DEFAULT_ENCODING) return serialized
def _serialize_data(self, serialized, data, body=None): if body is not None: serialized['body'] = json.dumps(body).encode(self.DEFAULT_ENCODING) serialized['query_string'] = data return serialized