Skip to content

Commit

Permalink
Merge pull request #70 from abhishek-ram/abhishek-use-github-actions
Browse files Browse the repository at this point in the history
Multiple changs for a new release
  • Loading branch information
abhishek-ram authored Feb 6, 2022
2 parents a83590e + d2851e3 commit 95d80c0
Show file tree
Hide file tree
Showing 16 changed files with 181 additions and 74 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Run Tests
on:
push:
branches:
- "master"
pull_request:
branches:
- "master"
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9, "3.10"]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[tests]"
- name: Run Tests
run: |
pytest --cov-report term --cov-config .coveragerc --cov=pyas2 --black --pylama pyas2
- name: Generate CodeCov Report
run: |
pip install codecov
codecov
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

3 changes: 2 additions & 1 deletion AUTHORS.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
* Abhishek Ram <abhishek.ram@me.com> @abhishek-ram
* Abhishek Ram <abhishek.ram@me.com> @abhishek-ram
* Wassilios Lytras @chadgates
3 changes: 3 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ django-pyAS2
.. image:: https://travis-ci.org/abhishek-ram/django-pyas2.svg?branch=master
:target: https://travis-ci.org/abhishek-ram/django-pyas2

.. image:: https://github.com/abhishek-ram/django-pyas2/actions/workflows/run-tests.yml/badge.svg?branch=master&event=push
:target: https://github.com/abhishek-ram/django-pyas2/actions/workflows/run-tests.yml?query=branch%3Amaster++

.. image:: https://codecov.io/gh/abhishek-ram/django-pyas2/branch/master/graph/badge.svg
:target: https://codecov.io/gh/abhishek-ram/django-pyas2

Expand Down
2 changes: 0 additions & 2 deletions example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@

USE_I18N = True

USE_L10N = True

USE_TZ = True


Expand Down
43 changes: 34 additions & 9 deletions pyas2/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,14 @@

@admin.register(PrivateKey)
class PrivateKeyAdmin(admin.ModelAdmin):
"""Admin class for the PrivateKey model."""

form = PrivateKeyForm
list_display = ("name", "valid_from", "valid_to", "serial_number", "download_key")

def download_key(self, obj):
@staticmethod
def download_key(obj):
"""Return the url to download the private key."""
download_url = reverse_lazy("download-file", args=["private_key", obj.id])
return format_html(
'<a href="{}" class="button">Click to Download</a>', download_url
Expand All @@ -34,10 +38,14 @@ def download_key(self, obj):

@admin.register(PublicCertificate)
class PublicCertificateAdmin(admin.ModelAdmin):
"""Admin class for the PublicCertificate model."""

form = PublicCertificateForm
list_display = ("name", "valid_from", "valid_to", "serial_number", "download_cert")

def download_cert(self, obj):
@staticmethod
def download_cert(obj):
"""Return the url to download the public cert."""
download_url = reverse_lazy("download-file", args=["public_cert", obj.id])
return format_html(
'<a href="{}" class="button">Click to Download</a>', download_url
Expand All @@ -49,6 +57,8 @@ def download_cert(self, obj):

@admin.register(Partner)
class PartnerAdmin(admin.ModelAdmin):
"""Admin class for the Partner model."""

form = PartnerForm
list_display = [
"name",
Expand Down Expand Up @@ -119,7 +129,8 @@ class PartnerAdmin(admin.ModelAdmin):
)
actions = ["send_message"]

def send_message(self, request, queryset):
def send_message(self, request, queryset): # pylint: disable=W0613,R0201
"""Send the message to the first partner chosen by the user."""
partner = queryset.first()
return HttpResponseRedirect(
reverse_lazy("as2-send") + "?partner_id=%s" % partner.as2_name
Expand All @@ -130,14 +141,15 @@ def send_message(self, request, queryset):

@admin.register(Organization)
class OrganizationAdmin(admin.ModelAdmin):
"""Admin class for the Organization model."""

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
"""Admin class for the Message model."""

search_fields = ("message_id", "payload")

Expand All @@ -157,36 +169,49 @@ def has_add_permission(self, request):
"mdn_url",
]

def mdn_url(self, obj):
@staticmethod
def mdn_url(obj):
"""Return the URL to the related MDN if present for the message."""
# pylint: disable=W0212

if hasattr(obj, "mdn"):
view_url = reverse_lazy(
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)
return None

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

def download_file(self, obj):
@staticmethod
def download_file(obj):
"""Return the URL to download the message payload."""
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)
)
return None

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

def has_add_permission(self, request):
return False


@admin.register(Mdn)
class MdnAdmin(admin.ModelAdmin):
def has_add_permission(self, request):
return False
"""Admin class for the Mdn model."""

search_fields = (
"mdn_id",
"message__message_id",
)
list_display = ("mdn_id", "message", "timestamp", "status")
list_filter = ("status",)

def has_add_permission(self, request):
return False
6 changes: 2 additions & 4 deletions pyas2/apps.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
from django.apps import AppConfig


class Pyas2Config(AppConfig):
"""App config for the pyas2 app."""

name = "pyas2"
verbose_name = "pyAS2 File Transfer Server"

def ready(self):
super(Pyas2Config, self).ready()
27 changes: 22 additions & 5 deletions pyas2/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@


class PartnerForm(forms.ModelForm):
"""Form for creating and editing AS2 partners."""

def clean(self):
cleaned_data = super(PartnerForm, self).clean()
cleaned_data = super().clean()

# If http auth is set and credentials are missing raise error
if cleaned_data.get("http_auth"):
Expand Down Expand Up @@ -57,14 +59,19 @@ def clean(self):
return cleaned_data

class Meta:
"""Define additional config for the PartnerForm class."""

model = Partner
exclude = []


class PrivateKeyForm(forms.ModelForm):
"""Form for creating and editing AS2 Organization private keys."""

key_file = forms.FileField()

def clean_key_file(self):
"""Validate that uploaded private key has the right extension."""
key_file = self.cleaned_data["key_file"]

ext = os.path.splitext(key_file.name)[1]
Expand All @@ -78,7 +85,7 @@ def clean_key_file(self):
return key_file

def clean(self):
cleaned_data = super(PrivateKeyForm, self).clean()
cleaned_data = super().clean()
key_file = cleaned_data.get("key_file")

if key_file:
Expand All @@ -96,14 +103,16 @@ def clean(self):
return cleaned_data

def save(self, commit=True):
instance = super(PrivateKeyForm, self).save(commit=False)
instance = super().save(commit=False)
instance.name = self.cleaned_data["key_filename"]
instance.key = self.cleaned_data["key_file"]
if commit:
instance.save()
return instance

class Meta:
"""Define additional config for the PrivateKeyForm class."""

model = PrivateKey
fields = ["key_file", "key_pass"]
widgets = {
Expand All @@ -112,10 +121,13 @@ class Meta:


class PublicCertificateForm(forms.ModelForm):
"""Form for creating and editing AS2 Partner public certs."""

cert_file = forms.FileField(label="Certificate File")
cert_ca_file = forms.FileField(label="Certificate CA File", required=False)

def clean_cert_file(self):
"""Validate that uploaded cert file has the right extension."""
cert_file = self.cleaned_data["cert_file"]

ext = os.path.splitext(cert_file.name)[1]
Expand All @@ -130,6 +142,7 @@ def clean_cert_file(self):
return cert_file

def clean_cert_ca_file(self):
"""Validate that uploaded cert ca file has the right extension."""
cert_ca_file = self.cleaned_data["cert_ca_file"]

if cert_ca_file:
Expand All @@ -148,7 +161,7 @@ def clean_cert_ca_file(self):
return cert_ca_file

def clean(self):
cleaned_data = super(PublicCertificateForm, self).clean()
cleaned_data = super().clean()
cert_file = cleaned_data.get("cert_file")
cert_ca_file = cleaned_data.get("cert_ca_file", "")

Expand All @@ -173,7 +186,7 @@ def clean(self):
return cleaned_data

def save(self, commit=True):
instance = super(PublicCertificateForm, self).save(commit=False)
instance = super().save(commit=False)
instance.name = self.cleaned_data["cert_filename"]
instance.certificate = self.cleaned_data["cert_file"]

Expand All @@ -185,11 +198,15 @@ def save(self, commit=True):
return instance

class Meta:
"""Define additional config for the PublicCertificateForm class."""

model = PublicCertificate
fields = ["cert_file", "cert_ca_file", "verify_cert"]


class SendAs2MessageForm(forms.Form):
"""Form for sending AS2 messages to Partners from the Admin."""

organization = forms.ModelChoiceField(
queryset=Organization.objects.all(), empty_label=None
)
Expand Down
12 changes: 8 additions & 4 deletions pyas2/management/commands/manageas2server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import os
import requests
from email.parser import BytesHeaderParser
from datetime import timedelta
from email.parser import BytesHeaderParser

import requests
from django.core.management.base import BaseCommand
from django.utils import timezone
from pyas2lib import Message as AS2Message
Expand All @@ -11,6 +12,8 @@


class Command(BaseCommand):
"""Command to manage the django pyas2 server."""

help = (
"Command to manage the as2 server, includes options to cleanup, "
"handle async mdns and message retries"
Expand Down Expand Up @@ -43,6 +46,7 @@ def add_arguments(self, parser):
)

def retry(self, retry_msg):
"""Retry sending the message to the partner."""
# Increase the retry count
if not retry_msg.retries:
retry_msg.retries = 1
Expand Down Expand Up @@ -146,10 +150,10 @@ def handle(self, *args, **options):
for pending_msg in out_pending_msgs:
self.retry(pending_msg)

self.stdout.write(u"Successfully processed all pending mdns.")
self.stdout.write("Successfully processed all pending mdns.")

if options["clean"]:
self.stdout.write(u"Cleanup maintenance process started")
self.stdout.write("Cleanup maintenance process started")
max_archive_dt = timezone.now() - timedelta(settings.MAX_ARCH_DAYS)
self.stdout.write(
"Delete all messages older than %s" % settings.MAX_ARCH_DAYS
Expand Down
2 changes: 2 additions & 0 deletions pyas2/management/commands/sendas2bulk.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@


class Command(BaseCommand):
"""Command to send all pending messages."""

help = "Command for sending all pending messages in the outbox folders"

def handle(self, *args, **options):
Expand Down
Loading

0 comments on commit 95d80c0

Please sign in to comment.