Created decorator for setting INITIAL_NO_AUTH_ACTION_COUNT.
This commit is contained in:
parent
bbf003d335
commit
15c872cffc
@ -1,4 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
from .models import BaseModel, BaseBackend, moto_api_backend # flake8: noqa
|
||||
|
||||
from .models import BaseModel, BaseBackend, moto_api_backend, set_initial_no_auth_action_count # flake8: noqa
|
||||
|
||||
moto_api_backends = {"global": moto_api_backend}
|
||||
set_initial_no_auth_action_count = set_initial_no_auth_action_count
|
||||
|
@ -27,6 +27,22 @@ os.environ.setdefault("AWS_ACCESS_KEY_ID", "foobar_key")
|
||||
os.environ.setdefault("AWS_SECRET_ACCESS_KEY", "foobar_secret")
|
||||
|
||||
|
||||
def set_initial_no_auth_action_count(initial_no_auth_action_count):
|
||||
def decorator(function):
|
||||
def wrapper(*args, **kwargs):
|
||||
original_initial_no_auth_action_count = settings.INITIAL_NO_AUTH_ACTION_COUNT
|
||||
settings.INITIAL_NO_AUTH_ACTION_COUNT = initial_no_auth_action_count
|
||||
result = function(*args, **kwargs)
|
||||
settings.INITIAL_NO_AUTH_ACTION_COUNT = original_initial_no_auth_action_count
|
||||
return result
|
||||
|
||||
functools.update_wrapper(wrapper, function)
|
||||
wrapper.__wrapped__ = function
|
||||
return wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
class BaseMockAWS(object):
|
||||
nested_count = 0
|
||||
|
||||
|
@ -24,7 +24,7 @@ from werkzeug.exceptions import HTTPException
|
||||
import boto3
|
||||
from moto.compat import OrderedDict
|
||||
from moto.core.utils import camelcase_to_underscores, method_names_from_class
|
||||
from moto.settings import INITIAL_NO_AUTH_ACTION_COUNT
|
||||
from moto import settings
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -110,7 +110,7 @@ class ActionAuthenticatorMixin(object):
|
||||
request_count = 0
|
||||
|
||||
def _authenticate_action(self, iam_request_cls):
|
||||
if ActionAuthenticatorMixin.request_count >= INITIAL_NO_AUTH_ACTION_COUNT:
|
||||
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()
|
||||
iam_request.check_action_permitted()
|
||||
|
Loading…
Reference in New Issue
Block a user