From f3f47d44ac296405310f9cc272cc32c1816f5d67 Mon Sep 17 00:00:00 2001 From: acsbendi Date: Fri, 26 Jul 2019 21:05:04 +0200 Subject: [PATCH] Fixed error in python 2 and did some refactoring. --- .../{authentication.py => access_control.py} | 2 +- moto/core/responses.py | 14 ++++++------- moto/s3/responses.py | 20 +++++++++---------- 3 files changed, 18 insertions(+), 18 deletions(-) rename moto/core/{authentication.py => access_control.py} (99%) diff --git a/moto/core/authentication.py b/moto/core/access_control.py similarity index 99% rename from moto/core/authentication.py rename to moto/core/access_control.py index 2fec59808..0739fd167 100644 --- a/moto/core/authentication.py +++ b/moto/core/access_control.py @@ -127,7 +127,7 @@ class AssumedRoleAccessKey(object): class CreateAccessKeyFailure(Exception): def __init__(self, reason, *args): - super().__init__(*args) + super(CreateAccessKeyFailure, self).__init__(*args) self.reason = reason diff --git a/moto/core/responses.py b/moto/core/responses.py index fe3581800..2310dea2c 100644 --- a/moto/core/responses.py +++ b/moto/core/responses.py @@ -10,7 +10,7 @@ import io import pytz -from moto.core.authentication import IAMRequest, S3IAMRequest +from moto.core.access_control import IAMRequest, S3IAMRequest from moto.core.exceptions import DryRunClientError from jinja2 import Environment, DictLoader, TemplateNotFound @@ -110,7 +110,7 @@ class ActionAuthenticatorMixin(object): request_count = 0 - def _authenticate_action(self, iam_request_cls): + def _authenticate_and_authorize_action(self, iam_request_cls): if ActionAuthenticatorMixin.request_count >= settings.INITIAL_NO_AUTH_ACTION_COUNT: iam_request = iam_request_cls(method=self.method, path=self.path, data=self.data, headers=self.headers) iam_request.check_signature() @@ -118,11 +118,11 @@ class ActionAuthenticatorMixin(object): else: ActionAuthenticatorMixin.request_count += 1 - def _authenticate_normal_action(self): - self._authenticate_action(IAMRequest) + def _authenticate_and_authorize_normal_action(self): + self._authenticate_and_authorize_action(IAMRequest) - def _authenticate_s3_action(self): - self._authenticate_action(S3IAMRequest) + def _authenticate_and_authorize_s3_action(self): + self._authenticate_and_authorize_action(S3IAMRequest) @staticmethod def set_initial_no_auth_action_count(initial_no_auth_action_count): @@ -319,7 +319,7 @@ class BaseResponse(_TemplateEnvironmentMixin, ActionAuthenticatorMixin): headers = self.response_headers try: - self._authenticate_normal_action() + self._authenticate_and_authorize_normal_action() except HTTPException as http_error: response = http_error.description, dict(status=http_error.code) return self._send_response(headers, response) diff --git a/moto/s3/responses.py b/moto/s3/responses.py index 2617f139d..b09ea966b 100644 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -120,7 +120,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin): def all_buckets(self): self.data["Action"] = "ListAllMyBuckets" - self._authenticate_s3_action() + self._authenticate_and_authorize_s3_action() # No bucket specified. Listing all buckets all_buckets = self.backend.get_all_buckets() @@ -266,7 +266,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin): def _bucket_response_get(self, bucket_name, querystring): self._set_action("BUCKET", "GET", querystring) - self._authenticate_s3_action() + self._authenticate_and_authorize_s3_action() if 'uploads' in querystring: for unsup in ('delimiter', 'max-uploads'): @@ -500,7 +500,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin): return 411, {}, "Content-Length required" self._set_action("BUCKET", "PUT", querystring) - self._authenticate_s3_action() + self._authenticate_and_authorize_s3_action() if 'versioning' in querystring: ver = re.search('([A-Za-z]+)', body.decode()) @@ -602,7 +602,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin): def _bucket_response_delete(self, body, bucket_name, querystring): self._set_action("BUCKET", "DELETE", querystring) - self._authenticate_s3_action() + self._authenticate_and_authorize_s3_action() if 'policy' in querystring: self.backend.delete_bucket_policy(bucket_name, body) @@ -638,12 +638,12 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin): if self.is_delete_keys(request, path, bucket_name): self.data["Action"] = "DeleteObject" - self._authenticate_s3_action() + self._authenticate_and_authorize_s3_action() return self._bucket_response_delete_keys(request, body, bucket_name) self.data["Action"] = "PutObject" - self._authenticate_s3_action() + self._authenticate_and_authorize_s3_action() # POST to bucket-url should create file from form if hasattr(request, 'form'): @@ -797,7 +797,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin): def _key_response_get(self, bucket_name, query, key_name, headers): self._set_action("KEY", "GET", query) - self._authenticate_s3_action() + self._authenticate_and_authorize_s3_action() response_headers = {} if query.get('uploadId'): @@ -834,7 +834,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin): def _key_response_put(self, request, body, bucket_name, query, key_name, headers): self._set_action("KEY", "PUT", query) - self._authenticate_s3_action() + self._authenticate_and_authorize_s3_action() response_headers = {} if query.get('uploadId') and query.get('partNumber'): @@ -1204,7 +1204,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin): def _key_response_delete(self, bucket_name, query, key_name): self._set_action("KEY", "DELETE", query) - self._authenticate_s3_action() + self._authenticate_and_authorize_s3_action() if query.get('uploadId'): upload_id = query['uploadId'][0] @@ -1227,7 +1227,7 @@ class ResponseObject(_TemplateEnvironmentMixin, ActionAuthenticatorMixin): def _key_response_post(self, request, body, bucket_name, query, key_name): self._set_action("KEY", "POST", query) - self._authenticate_s3_action() + self._authenticate_and_authorize_s3_action() if body == b'' and 'uploads' in query: metadata = metadata_from_headers(request.headers)