Skip to content

Commit

Permalink
Merge pull request #31 from abhishek-ram/support-cloud-storage
Browse files Browse the repository at this point in the history
Support cloud storage and improve test coverage
  • Loading branch information
abhishek-ram authored Apr 12, 2020
2 parents 05683a6 + b3b7ecc commit 54ca691
Show file tree
Hide file tree
Showing 30 changed files with 1,862 additions and 1,077 deletions.
5 changes: 4 additions & 1 deletion .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ omit =
pyas2/admin.py

# Omit the template tags
pyas2/templatetags/pyas2.py
pyas2/templatetags/pyas2.py

# Omit tests
pyas2/tests/*
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ language: python
python:
- '3.6'
- '3.7'
- '3.8'
install:
- python setup.py install
- pip install pytest-cov pytest-django mock
- pip install -r requirements/test.txt
script:
- pytest --cov-report term --cov-config .coveragerc --cov=pyas2
- pytest --cov-report term --cov-config .coveragerc --cov=pyas2 --black --pylama pyas2
after_success:
- pip install codecov
- codecov
12 changes: 12 additions & 0 deletions example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"""

import os
import environ

# reading .env file
env = environ.Env()
environ.Env.read_env()

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Expand Down Expand Up @@ -121,3 +126,10 @@

STATIC_URL = '/static/'

if env.bool("USE_S3_FILE_STORAGE", False):
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_ACCESS_KEY_ID = env('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = env('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = env('AWS_STORAGE_BUCKET_NAME')
AWS_LOCATION = 'pyas2_data'
AWS_DEFAULT_ACL = None
6 changes: 3 additions & 3 deletions pyas2/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Set the version
__version__ = '1.1.1'
__version__ = "1.1.1"

default_app_config = 'pyas2.apps.Pyas2Config'
default_app_config = "pyas2.apps.Pyas2Config"

__all__ = [
'default_app_config',
"default_app_config",
]
163 changes: 109 additions & 54 deletions pyas2/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
@admin.register(PrivateKey)
class PrivateKeyAdmin(admin.ModelAdmin):
form = PrivateKeyForm
list_display = ('name', 'valid_from', 'valid_to', 'serial_number', 'download_key')
list_display = ("name", "valid_from", "valid_to", "serial_number", "download_key")

def download_key(self, obj):
download_url = reverse_lazy('download-file',
args=['private_key', obj.id])
return format_html('<a href="{}" class="button">Click to Download</a>',
download_url)
download_url = reverse_lazy("download-file", args=["private_key", obj.id])
return format_html(
'<a href="{}" class="button">Click to Download</a>', download_url
)

download_key.allow_tags = True
download_key.short_description = "Key File"
Expand All @@ -35,13 +35,13 @@ def download_key(self, obj):
@admin.register(PublicCertificate)
class PublicCertificateAdmin(admin.ModelAdmin):
form = PublicCertificateForm
list_display = ('name', 'valid_from', 'valid_to', 'serial_number', 'download_cert')
list_display = ("name", "valid_from", "valid_to", "serial_number", "download_cert")

def download_cert(self, obj):
download_url = reverse_lazy('download-file',
args=['public_cert', obj.id])
return format_html('<a href="{}" class="button">Click to Download</a>',
download_url)
download_url = reverse_lazy("download-file", args=["public_cert", obj.id])
return format_html(
'<a href="{}" class="button">Click to Download</a>', download_url
)

download_cert.allow_tags = True
download_cert.short_description = "Certificate File"
Expand All @@ -50,88 +50,143 @@ def download_cert(self, obj):
@admin.register(Partner)
class PartnerAdmin(admin.ModelAdmin):
form = PartnerForm
list_display = ['name', 'as2_name', 'target_url', 'encryption',
'encryption_cert', 'signature', 'signature_cert',
'mdn', 'mdn_mode']
list_filter = ('name', 'as2_name')
list_display = [
"name",
"as2_name",
"target_url",
"encryption",
"encryption_cert",
"signature",
"signature_cert",
"mdn",
"mdn_mode",
]
list_filter = ("name", "as2_name")
fieldsets = (
(None, {
'fields': (
'name', 'as2_name', 'email_address', 'target_url',
'subject', 'content_type', 'confirmation_message')
}),
('Http Authentication', {
'classes': ('collapse', 'wide'),
'fields': ('http_auth', 'http_auth_user', 'http_auth_pass', 'https_verify_ssl')
}),
('Security Settings', {
'classes': ('collapse', 'wide'),
'fields': ('compress', 'encryption', 'encryption_cert', 'signature',
'signature_cert')
}),
('MDN Settings', {
'classes': ('collapse', 'wide'),
'fields': ('mdn', 'mdn_mode', 'mdn_sign')
}),
('Advanced Settings', {
'classes': ('collapse', 'wide'),
'fields': ('keep_filename', 'cmd_send', 'cmd_receive')
}),
(
None,
{
"fields": (
"name",
"as2_name",
"email_address",
"target_url",
"subject",
"content_type",
"confirmation_message",
)
},
),
(
"Http Authentication",
{
"classes": ("collapse", "wide"),
"fields": (
"http_auth",
"http_auth_user",
"http_auth_pass",
"https_verify_ssl",
),
},
),
(
"Security Settings",
{
"classes": ("collapse", "wide"),
"fields": (
"compress",
"encryption",
"encryption_cert",
"signature",
"signature_cert",
),
},
),
(
"MDN Settings",
{
"classes": ("collapse", "wide"),
"fields": ("mdn", "mdn_mode", "mdn_sign"),
},
),
(
"Advanced Settings",
{
"classes": ("collapse", "wide"),
"fields": ("keep_filename", "cmd_send", "cmd_receive"),
},
),
)
actions = ['send_message']
actions = ["send_message"]

def send_message(self, request, queryset):
partner = queryset.first()
return HttpResponseRedirect(
reverse_lazy('as2-send') + '?partner_id=%s' % partner.as2_name)
reverse_lazy("as2-send") + "?partner_id=%s" % partner.as2_name
)

send_message.short_description = "Send a message to the selected partner"


@admin.register(Organization)
class OrganizationAdmin(admin.ModelAdmin):
list_display = ['name', 'as2_name']
list_filter = ('name', 'as2_name')
list_display = ["name", "as2_name"]
list_filter = ("name", "as2_name")


@admin.register(Message)
class MessageAdmin(admin.ModelAdmin):

def has_add_permission(self, request):
return False

search_fields = ('message_id', 'payload')
search_fields = ("message_id", "payload")

list_filter = ('direction', 'status', 'organization__as2_name', 'partner__as2_name')
list_filter = ("direction", "status", "organization__as2_name", "partner__as2_name")

list_display = ['message_id', 'timestamp', 'status', 'direction',
'organization', 'partner', 'compressed', 'encrypted',
'signed', 'download_file', 'mdn_url']
list_display = [
"message_id",
"timestamp",
"status",
"direction",
"organization",
"partner",
"compressed",
"encrypted",
"signed",
"download_file",
"mdn_url",
]

def mdn_url(self, obj):
if hasattr(obj, 'mdn'):
if hasattr(obj, "mdn"):
view_url = reverse_lazy(
f'admin:{Mdn._meta.app_label}_{Mdn._meta.model_name}_change', args=[obj.mdn.id])
f"admin:{Mdn._meta.app_label}_{Mdn._meta.model_name}_change",
args=[obj.mdn.id],
)
return format_html('<a href="{}" class="">{}</a>', view_url, obj.mdn.mdn_id)

mdn_url.allow_tags = True
mdn_url.short_description = "MDN"

def download_file(self, obj):
if obj.payload:
view_url = reverse_lazy('download-file', args=['message_payload', obj.id])
return format_html('<a href="{}">{}</a>', view_url, os.path.basename(obj.payload.name))
view_url = reverse_lazy("download-file", args=["message_payload", obj.id])
return format_html(
'<a href="{}">{}</a>', view_url, os.path.basename(obj.payload.name)
)

download_file.allow_tags = True
download_file.short_description = "Payload"


@admin.register(Mdn)
class MdnAdmin(admin.ModelAdmin):

def has_add_permission(self, request):
return False

search_fields = ('mdn_id', 'message_id',)
list_display = ('mdn_id', 'message', 'timestamp', 'status')
list_filter = ('status',)
search_fields = (
"mdn_id",
"message_id",
)
list_display = ("mdn_id", "message", "timestamp", "status")
list_filter = ("status",)
4 changes: 2 additions & 2 deletions pyas2/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@


class Pyas2Config(AppConfig):
name = 'pyas2'
verbose_name = 'pyAS2 File Transfer Server'
name = "pyas2"
verbose_name = "pyAS2 File Transfer Server"

def ready(self):
super(Pyas2Config, self).ready()
Loading

0 comments on commit 54ca691

Please sign in to comment.