MCPcopy Create free account
hub / github.com/aws/aws-cli / _modify_request_before_signing

Method _modify_request_before_signing

awscli/botocore/auth.py:721–786  ·  view source on GitHub ↗
(self, request)

Source from the content-addressed store, hash-verified

719 self._expires = expires
720
721 def _modify_request_before_signing(self, request):
722 # We automatically set this header, so if it's the auto-set value we
723 # want to get rid of it since it doesn't make sense for presigned urls.
724 content_type = request.headers.get('content-type')
725 blacklisted_content_type = (
726 'application/x-www-form-urlencoded; charset=utf-8'
727 )
728 if content_type == blacklisted_content_type:
729 del request.headers['content-type']
730
731 # Note that we're not including X-Amz-Signature.
732 # From the docs: "The Canonical Query String must include all the query
733 # parameters from the preceding table except for X-Amz-Signature.
734 signed_headers = self.signed_headers(self.headers_to_sign(request))
735
736 auth_params = {
737 'X-Amz-Algorithm': 'AWS4-HMAC-SHA256',
738 'X-Amz-Credential': self.scope(request),
739 'X-Amz-Date': request.context['timestamp'],
740 'X-Amz-Expires': self._expires,
741 'X-Amz-SignedHeaders': signed_headers,
742 }
743 if self.credentials.token is not None:
744 auth_params['X-Amz-Security-Token'] = self.credentials.token
745 # Now parse the original query string to a dict, inject our new query
746 # params, and serialize back to a query string.
747 url_parts = urlsplit(request.url)
748 # parse_qs makes each value a list, but in our case we know we won't
749 # have repeated keys so we know we have single element lists which we
750 # can convert back to scalar values.
751 query_dict = dict(
752 [
753 (k, v[0])
754 for k, v in parse_qs(
755 url_parts.query, keep_blank_values=True
756 ).items()
757 ]
758 )
759 # The spec is particular about this. It *has* to be:
760 # https://<endpoint>?<operation params>&<auth params>
761 # You can't mix the two types of params together, i.e just keep doing
762 # new_query_params.update(op_params)
763 # new_query_params.update(auth_params)
764 # percent_encode_sequence(new_query_params)
765 operation_params = ''
766 if request.data:
767 # We also need to move the body params into the query string. To
768 # do this, we first have to convert it to a dict.
769 query_dict.update(_get_body_as_dict(request))
770 request.data = ''
771 if query_dict:
772 operation_params = percent_encode_sequence(query_dict) + '&'
773 new_query_string = operation_params + percent_encode_sequence(
774 auth_params
775 )
776 # url_parts is a tuple (and therefore immutable) so we need to create
777 # a new url_parts with the new query string.
778 # <part> - <index>

Callers

nothing calls this directly

Calls 6

percent_encode_sequenceFunction · 0.90
_get_body_as_dictFunction · 0.85
signed_headersMethod · 0.80
headers_to_signMethod · 0.80
scopeMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected