Skip to content

Commit

Permalink
Merge branch 'marshmallow-3.18' into 'master'
Browse files Browse the repository at this point in the history
Upgrade to Marshmallow v3.18 and drop support for Python 2.x

See merge request qacafe/cdrouter/cdrouter.py!10
  • Loading branch information
twintersunh committed Oct 11, 2022
2 parents 72d510e + 058d234 commit 0e93f4f
Show file tree
Hide file tree
Showing 33 changed files with 591 additions and 412 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ cdrouter is available on PyPI.
$ pip install -U cdrouter
cdrouter supports Python 3.5 or newer.

Documentation
=============

Expand Down
54 changes: 26 additions & 28 deletions cdrouter/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@

"""Module for accessing CDRouter Alerts."""

import collections
from collections import namedtuple
from functools import partial

from marshmallow import Schema, fields, post_load
from .cdr_datetime import DateTime
from .cdr_dictfield import DictField

class Alert(object):
"""Model for CDRouter Alerts.
Expand Down Expand Up @@ -75,35 +73,35 @@ def __init__(self, **kwargs):
class AlertSchema(Schema):
id = fields.Int(as_string=True)
idx = fields.Int(as_string=True)
created = DateTime()
updated = DateTime()
created = fields.DateTime()
updated = fields.DateTime()

seq = fields.Int(as_string=True)
loop = fields.Int(as_string=True)
test_name = fields.Str()
test_description = fields.Str()

category = fields.Str()
description = fields.Str(missing=None)
description = fields.Str(load_default=None)
dest_ip = fields.Str()
dest_port = fields.Int(as_string=True, missing=None)
dest_port = fields.Int(as_string=True, load_default=None)
interface = fields.Str()
payload = fields.Str(missing=None)
payload_ascii = fields.Str(missing=None)
payload_hex = fields.Str(missing=None)
payload = fields.Str(load_default=None)
payload_ascii = fields.Str(load_default=None)
payload_hex = fields.Str(load_default=None)
proto = fields.Str()
references = fields.List(fields.Str(), missing=None)
references = fields.List(fields.Str(), load_default=None)
rev = fields.Int(as_string=True)
rule = fields.Str()
rule_set = fields.Str()
severity = fields.Int(as_string=True)
sid = fields.Int(as_string=True)
signature = fields.Str()
src_ip = fields.Str()
src_port = fields.Int(as_string=True, missing=None)
src_port = fields.Int(as_string=True, load_default=None)

@post_load
def post_load(self, data):
def post_load(self, data, **kwargs): # pylint: disable=unused-argument
return Alert(**data)

class SeverityCount(object):
Expand All @@ -124,7 +122,7 @@ class SeverityCountSchema(Schema):
count = fields.Int(as_string=True)

@post_load
def post_load(self, data):
def post_load(self, data, **kwargs): # pylint: disable=unused-argument
return SeverityCount(**data)

class CategoryCount(object):
Expand All @@ -145,7 +143,7 @@ class CategoryCountSchema(Schema):
count = fields.Int(as_string=True)

@post_load
def post_load(self, data):
def post_load(self, data, **kwargs): # pylint: disable=unused-argument
return CategoryCount(**data)

class RuleSetCount(object):
Expand All @@ -163,7 +161,7 @@ class RuleSetCountSchema(Schema):
count = fields.Int(as_string=True)

@post_load
def post_load(self, data):
def post_load(self, data, **kwargs): # pylint: disable=unused-argument
return RuleSetCount(**data)

class SignatureCount(object):
Expand All @@ -184,7 +182,7 @@ class SignatureCountSchema(Schema):
count = fields.Int(as_string=True)

@post_load
def post_load(self, data):
def post_load(self, data, **kwargs): # pylint: disable=unused-argument
return SignatureCount(**data)

class TestCount(object):
Expand All @@ -202,7 +200,7 @@ class TestCountSchema(Schema):
count = fields.Int(as_string=True)

@post_load
def post_load(self, data):
def post_load(self, data, **kwargs): # pylint: disable=unused-argument
return TestCount(**data)

class AddrCount(object):
Expand All @@ -220,7 +218,7 @@ class AddrCountSchema(Schema):
count = fields.Int(as_string=True)

@post_load
def post_load(self, data):
def post_load(self, data, **kwargs): # pylint: disable=unused-argument
return AddrCount(**data)

class AllStats(object):
Expand All @@ -244,19 +242,19 @@ def __init__(self, **kwargs):
self.frequent_destinations = kwargs.get('frequent_destinations', None)

class AllStatsSchema(Schema):
severities = DictField(fields.Int(), SeverityCountSchema())
categories = fields.Nested(CategoryCountSchema, many=True)
rule_sets = fields.Nested(RuleSetCountSchema, many=True)
signatures = fields.Nested(SignatureCountSchema, many=True)
tests = fields.Nested(TestCountSchema, many=True)
frequent_sources = fields.Nested(AddrCountSchema, many=True)
frequent_destinations = fields.Nested(AddrCountSchema, many=True)
severities = fields.Dict(keys=fields.Int(), values=fields.Nested(SeverityCountSchema()))
categories = fields.Nested(lambda: CategoryCountSchema(many=True))
rule_sets = fields.Nested(lambda: RuleSetCountSchema(many=True))
signatures = fields.Nested(lambda: SignatureCountSchema(many=True))
tests = fields.Nested(lambda: TestCountSchema(many=True))
frequent_sources = fields.Nested(lambda: AddrCountSchema(many=True))
frequent_destinations = fields.Nested(lambda: AddrCountSchema(many=True))

@post_load
def post_load(self, data):
def post_load(self, data, **kwargs): # pylint: disable=unused-argument
return AllStats(**data)

class Page(collections.namedtuple('Page', ['data', 'links'])):
class Page(namedtuple('Page', ['data', 'links'])):
"""Named tuple for a page of list response data.
:param data: :class:`alerts.Alert <alerts.Alert>` list
Expand Down
2 changes: 1 addition & 1 deletion cdrouter/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AnnotationSchema(Schema):
comment = fields.Str()

@post_load
def post_load(self, data):
def post_load(self, data, **kwargs): # pylint: disable=unused-argument
return Annotation(**data)

class AnnotationsService(object):
Expand Down
13 changes: 6 additions & 7 deletions cdrouter/attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
# All Rights Reserved.
#

import collections
from collections import namedtuple
from functools import partial
import io

from requests_toolbelt.downloadutils import stream
from marshmallow import Schema, fields, post_load
from .cdr_datetime import DateTime

class Attachment(object):
"""Model for CDRouter Attachments.
Expand Down Expand Up @@ -37,17 +36,17 @@ class AttachmentSchema(Schema):
id = fields.Int(as_string=True)
name = fields.Str()
description = fields.Str()
created = DateTime()
updated = DateTime()
created = fields.DateTime()
updated = fields.DateTime()
size = fields.Int()
path = fields.Str()
device_id = fields.Int(as_string=True)

@post_load
def post_load(self, data):
def post_load(self, data, **kwargs): # pylint: disable=unused-argument
return Attachment(**data)

class Page(collections.namedtuple('Page', ['data', 'links'])):
class Page(namedtuple('Page', ['data', 'links'])):
"""Named tuple for a page of list response data.
:param data: :class:`attachments.Attachment <attachments.Attachment>` list
Expand Down Expand Up @@ -79,7 +78,7 @@ def list(self, id, filter=None, type=None, sort=None, limit=None, page=None, det
"""
schema = AttachmentSchema()
if not detailed:
schema = AttachmentSchema(exclude=('path'))
schema = AttachmentSchema(exclude=('path',))
resp = self.service.list(self._base(id), filter, type, sort, limit, page, detailed=detailed)
at, l = self.service.decode(schema, resp, many=True, links=True)
return Page(at, l)
Expand Down
7 changes: 5 additions & 2 deletions cdrouter/captures.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,26 @@ class Capture(object):
:param id: (optional) Result ID as an int.
:param seq: (optional) TestResult sequence ID as an int.
:param type: (optional) Capture type as string.
:param interface: (optional) Interface name as string.
:param filename: (optional) Path to capture file as string.
"""
def __init__(self, **kwargs):
self.id = kwargs.get('id', None)
self.seq = kwargs.get('seq', None)
self.type = kwargs.get('type', None)
self.interface = kwargs.get('interface', None)
self.filename = kwargs.get('filename', None)

class CaptureSchema(Schema):
id = mfields.Int(as_string=True)
seq = mfields.Int(as_string=True)
type = mfields.Str(load_default=None)
interface = mfields.Str()
filename = mfields.Str()

@post_load
def post_load(self, data):
def post_load(self, data, **kwargs): # pylint: disable=unused-argument
return Capture(**data)

class CloudShark(object):
Expand All @@ -47,7 +50,7 @@ class CloudSharkSchema(Schema):
url = mfields.Str()

@post_load
def post_load(self, data):
def post_load(self, data, **kwargs): # pylint: disable=unused-argument
return CloudShark(**data)

class CapturesService(object):
Expand Down
27 changes: 0 additions & 27 deletions cdrouter/cdr_datetime.py

This file was deleted.

43 changes: 0 additions & 43 deletions cdrouter/cdr_dictfield.py

This file was deleted.

0 comments on commit 0e93f4f

Please sign in to comment.