Pontus
Flask utility for signing Amazon S3 POST requests and validating Amazon S3 files. Both Python 2.7 and 3.4 are supported.
Upgrade note: Pontus 1.x branch uses Boto3. If you are still using boto, use 0.x.x versions. Check Git branch `version-0`.
Installation
Install with pip:
pip install Pontus
Dependencies
Pontus has the following dependencies:
Flask >= 0.10.1
boto3 >= 1.4.7
python-magic >= 0.4.6 (https://github.com/ahupp/python-magic)
Moreover python-magic depends on the libmagic file type identification library.
Examples
Signed POST request
Creating form fields for a signed Amazon S3 POST request
import boto3
from flask import current_app
from pontus import AmazonS3SignedRequest
session = boto3.session.Session(
aws_access_key_id=current_app.config.get('AWS_ACCESS_KEY_ID'),
aws_secret_access_key=current_app.config.get('AWS_SECRET_ACCESS_KEY'),
region_name=current_app.config.get('AWS_REGION_NAME')
)
bucket = session.resource('s3').Bucket('testbucket')
signed_request = AmazonS3SignedRequest(
key_name=u'my/file.jpg',
mime_type=u'image/jpeg',
bucket=bucket,
session=session
)
signed_request.form_fields
# {
# 'x-amz-algorithm': 'AWS4-HMAC-SHA256',
# 'x-amz-credential': 'your-aws-access-key-id/date/region-name/s3/aws4_request',
# 'x-amz-date': 'date',
# 'x-amz-signature': 'generated-signature',
# 'success_action_status': '201',
# 'acl': 'public-read',
# 'Content-Type': 'image/png',
# 'key': u'f6c157e1-1a1a-4418-99fe-3362dcf7b1ea/images/my-image.jpg',
# 'policy': 'generated-policy-document'
# }
These form fields can be used to POST files to Amazon S3 as described in Amazon’s documentation.
Amazon S3 file validation
Validating that an image file is less than 2MB and is of image/jpeg
MIME type.
import boto3
from flask import current_app
from pontus import AmazonS3FileValidator
from pontus.validators import FileSize, MimeType
session = boto3.session.Session(
aws_access_key_id=current_app.config.get('AWS_ACCESS_KEY_ID'),
aws_secret_access_key=current_app.config.get('AWS_SECRET_ACCESS_KEY')
)
bucket = session.resource('s3').Bucket('testbucket')
validator = AmazonS3FileValidator(
key_name='images/my-image.jpg',
bucket=bucket,
validators=[FileSize(max=2097152), MimeType('image/jpeg')],
session=session
)
if validator.validate():
# File is <2MB image/jpeg
pass
else:
# File was invalid, printing errors
print validator.errors
Validators can either be instances of a class inheriting
pontus.validators.BaseValidator or callable functions that take one
parameter obj, which is a boto.S3.Object instance.
from pontus.exceptions import ValidationError
from pontus.validators import BaseValidator
def name_starts_with_images(obj):
if not obj.key.startswith('images/'):
raise ValidationError()
# OR
class NameStartsWith(BaseValidator):
def __init__(self, starts_with_str):
self.starts_with_str = starts_with_str
def __call__(self, obj):
if not obj.key.startswith(starts_with_str):
raise ValidationError()
name_starts_with_images = NameStartsWith('images/')
Metadata
Release files for Pontus 4.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pontus-4.1.0.tar.gz | 40.7 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| Pontus-4.1.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details |
Total release size: 50.9 kB
Release files / pontus-4.1.0.tar.gz
| Download URL | pontus-4.1.0.tar.gz |
|---|---|
| Size | 40.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5b86b4d8af046692c72f81286d4df52ac9dc0932b74592cfd4febba4cd028e5c
|
|
BLAKE2b-256 checksum How to use checksums |
b0385a367d52e817d98f0846213637d3e60100a080a7140cfb6a754695c9dd34
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.8.19
|
Release files / Pontus-4.1.0-py2.py3-none-any.whl
| Download URL | Pontus-4.1.0-py2.py3-none-any.whl |
|---|---|
| Size | 10.3 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
bfa203c63e8234f933d3793006da0c95ca2a1dc6320fcac9b56999ed96c783a1
|
|
BLAKE2b-256 checksum How to use checksums |
9abac8ccedcddb4d16d95a051223c409ba9372f80e83768a2515bc864f11ab15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.8.19
|
Security for Pontus 4.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.