Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
A decoration mechanism for boto3 that allows automatic decoration of any and all boto3 clients and resources
Botoinator allows you to apply decorators to boto3 methods on either a class or object level. It works through boto3 sessions to allow you to apply decorators to either all clients/resources of a particular session, or to specific clients/resources of boto3.DEFAULT_SESSION.
You can see the pydoc generated documentation HERE
session = boto3.session.Session()
session.register_client_decorator(service_name, method_names, decorator)
Arguments:
session = boto3.session.Session()
session.register_resource_decorator(service_name, resource_name, method_names, decorator)
Arguments:
boto3.session.Session.add_client_decorator(service_name, method_names, decorator)
Arguments:
boto3.session.Session.add_resource_decorator(service_name, resource_name, method_names, decorator)
Arguments:
session = boto3.session.Session()
session.unregister_client_decorator(service_name, method_names)
Arguments:
session = boto3.session.Session()
session.unregister_resource_decorator(service_name, resource_name, method_names)
Arguments:
boto3.session.Session.remove_client_decorator(service_name, method_names)
Arguments:
boto3.session.Session.remove_resource_decorator(service_name, resource_name, method_names)
Arguments:
If you use the boto3.client()
or boto3.resource()
methods, these create a default session object found at boto3.DEFAULT_SESSION
.
Changing the default session's decorators requires using the register_xxx
and unregister_xxx
methods documented here.
For example boto3.DEFAULT_SESSION.register_client_decorator(...)
.
import boto3
import botoinator
from moto import mock_s3, mock_sqs
""" This is our decorator that we will apply to boto3 methods """
def myDecorator(func):
def test_decorator(*args, **kwargs):
setattr(test_decorator, 'testValue', True) # Add this attribute to the returned function for testing
return func(*args, **kwargs)
return test_decorator
@mock_s3
def testRegisterToClient():
"""
Test registering a decorator to a single boto3 session
"""
# Create a boto3 session
s = boto3.session.Session()
# Register the create_bucket() method to use our decorator for this session
s.register_client_decorator('s3', 'create_bucket', myDecorator)
# Now create our client as we normally would
client1 = s.client('s3')
# Now we can see that create_bucket() was decorated by testing the attribute we added
client1.create_bucket(Bucket='foo')
assert hasattr(client1.create_bucket, 'testValue')
# We can also see that this only applies to calls made by the session we registered by creating a new session through boto3.client() and not registering a decorator
client2 = boto3.client('s3')
client2.create_bucket(Bucket='foo')
# Now we can see that client.create_bucket() is not decorated
assert not hasattr(client2.create_bucket, 'testValue')
# Remove the decorator from the session
s.unregister_client_decorator('s3', 'create_bucket')
# Now create a new client on the same session we created at first
client3 = s.client('s3')
client3.create_bucket(Bucket='bar')
# The session should no longer be decorating methods for new clients
assert not hasattr(client3.create_bucket, 'testValue1')
FAQs
A decoration mechanism for boto3 that allows automatic decoration of any and all boto3 clients and resources
We found that botoinator demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.