Skip to content

Commit

Permalink
Merge pull request #6 from r3w0p/1.1
Browse files Browse the repository at this point in the history
1.1
  • Loading branch information
r3w0p authored Sep 16, 2023
2 parents 7035fee + c5266fa commit e6d2a4f
Show file tree
Hide file tree
Showing 33 changed files with 977 additions and 59 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- 'main'
tags-ignore:
- '**'

jobs:
ci:
Expand Down Expand Up @@ -46,7 +48,7 @@ jobs:
- name: Documentation coverage with interrogate
run: |
interrogate -vv bobocep --fail-under 98
interrogate -vv bobocep --fail-under 100
- name: Upload code coverage to Code Climate
uses: paambaati/[email protected]
Expand Down Expand Up @@ -87,7 +89,6 @@ jobs:
--outdir dist/
- name: Publish to PyPI
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@release/v1
with:
password: ${{ secrets.PYPI_TOKEN }}
2 changes: 2 additions & 0 deletions .github/workflows/security.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- 'main'
tags-ignore:
- '**'
schedule:
# At 06:00 on Monday.
- cron: '0 6 * * 1'
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
https://github.com/r3w0p/bobocep/actions/workflows/cicd.yml)
[![Security](https://github.com/r3w0p/bobocep/actions/workflows/security.yml/badge.svg)](
https://github.com/r3w0p/bobocep/actions/workflows/security.yml)
[![Code Repository](https://img.shields.io/badge/code-github-171515)](
https://github.com/r3w0p/bobocep/)
[![Documentation Status](https://readthedocs.org/projects/bobocep/badge/?version=latest)](
https://bobocep.readthedocs.io/)
[![License Scan](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fr3w0p%2Fbobocep.svg?type=shield)](
https://app.fossa.com/projects/git%2Bgithub.com%2Fr3w0p%2Fbobocep?ref=badge_shield)
[![Donate](https://img.shields.io/badge/donate-ko--fi-red?label=donate)](
https://ko-fi.com/r3w0p)
<br/>
Expand All @@ -24,12 +24,12 @@ https://github.com/r3w0p/bobocep/pulse/)

[![Issues](https://img.shields.io/github/issues/r3w0p/bobocep?label=issues)](
https://github.com/r3w0p/bobocep/issues/)
[![Dependencies](https://img.shields.io/librariesio/github/r3w0p/bobocep?label=dependencies)](
https://libraries.io/pypi/bobocep/)
[![Coverage](https://img.shields.io/codeclimate/coverage/r3w0p/bobocep?label=coverage)](
https://codeclimate.com/github/r3w0p/bobocep/)
[![Maintainability](https://img.shields.io/codeclimate/maintainability/r3w0p/bobocep?label=maintainability)](
https://codeclimate.com/github/r3w0p/bobocep/)
[![License Scan](https://app.fossa.com/api/projects/git%2Bgithub.com%2Fr3w0p%2Fbobocep.svg?type=shield)](
https://app.fossa.com/projects/git%2Bgithub.com%2Fr3w0p%2Fbobocep?ref=badge_shield)


`BoboCEP` is a [Complex Event Processing](https://en.wikipedia.org/wiki/Complex_event_processing) (CEP) engine
Expand All @@ -43,7 +43,7 @@ partially-completed complex events across multiple instances of the software.

## License

`BoboCEP` is open source, as per
[The Open Source Definition](https://opensource.org/osd).
`BoboCEP` is open source, as per the
[Open Source Definition](https://opensource.org/osd).
The code in this repository can be redistributed and/or modified under the terms of the
[MIT License](https://github.com/r3w0p/bobocep/blob/main/LICENSE).
27 changes: 14 additions & 13 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Security Policy

> _Last updated: 2023-01-04_
> _Last updated: 2023-09-16_

## Supported Versions
Expand All @@ -10,26 +10,27 @@ Below are the versions that are tested for support.

### Python

| Version | Supported |
|:------------:|:---------:|
| `> 3.10` | &cross; |
| `3.9 - 3.10` | &check; |
| `< 3.9` | &cross; |
| Version | Tested |
|:------------:|:-------:|
| `> 3.10` | &cross; |
| `3.9 - 3.10` | &check; |
| `< 3.9` | &cross; |


### OS

| Version | Supported |
|:----------------:|:---------:|
| `windows-latest` | &check; |
| `macos-latest` | &check; |
| `ubuntu-latest` | &check; |
| Version | Tested |
|:----------------:|:-------:|
| `windows-latest` | &check; |
| `macos-latest` | &check; |
| `ubuntu-latest` | &check; |

The `*-latest` version refers to the `*-latest`
[available environments](https://github.com/actions/virtual-environments#available-environments)
[available environments](https://github.com/actions/runner-images)
from GitHub Actions Virtual Environments.


## Reporting a Vulnerability

Please report vulnerabilities using the contact information [here](https://r3w0p.github.io/contact/).
Please report vulnerabilities using the contact information
[here](https://r3w0p.github.io/contact/).
4 changes: 2 additions & 2 deletions bobocep/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@

__author__ = """r3w0p"""
__email__ = "[email protected]"
__version__ = "1.0.1"
__version__ = "1.1.0"

from bobocep.bobocep import BoboError
from bobocep.bobocep import BoboError, BoboJSONable, BoboJSONableError
3 changes: 2 additions & 1 deletion bobocep/bobocep.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"""
Core classes.
"""

from abc import ABC, abstractmethod


Expand All @@ -22,7 +23,7 @@ class BoboJSONableError(BoboError):

class BoboJSONable(ABC):
"""
A abstract interface for JSONable types.
An abstract interface for JSONable types.
"""

@abstractmethod
Expand Down
7 changes: 7 additions & 0 deletions bobocep/cep/action/common/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright (c) 2019-2023 r3w0p
# The following code can be redistributed and/or
# modified under the terms of the MIT License.

"""
Common actions.
"""
83 changes: 83 additions & 0 deletions bobocep/cep/action/common/multi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright (c) 2019-2023 r3w0p
# The following code can be redistributed and/or
# modified under the terms of the MIT License.

"""
Multi actions.
"""
from abc import ABC
from typing import Tuple, Any, List

from bobocep.cep.action import BoboAction, BoboActionError
from bobocep.cep.event import BoboEventComplex

_ACTIONS_MIN: int = 1


class BoboActionMulti(BoboAction, ABC):
"""
An abstract multi action.
"""

def __init__(self, name: str, *args, **kwargs):
"""
:param name: The action name.
:param args: Action arguments.
:param kwargs: Action keyword arguments.
"""
super().__init__(name=name, args=args, kwargs=kwargs)


class BoboActionMultiSequential(BoboActionMulti):
"""
An abstract sequential multi action.
"""

def __init__(self,
name: str,
actions: List[BoboAction],
stop_on_fail: bool,
*args,
**kwargs):
"""
:param name: The action name.
:param actions: The list of actions to execute.
:param stop_on_fail: If True, the multi-action stops processing its
action list if its current action fails. If False, it continues
to process its remaining actions. Note: failure of any action in
its list will cause the multi-action's success to be False.
:param args: Action arguments.
:param kwargs: Action keyword arguments.
"""
super().__init__(name=name, args=args, kwargs=kwargs)

if len(actions) < 1:
raise BoboActionError(
f"multi sequential action {name} "
f"must contain at least {_ACTIONS_MIN} action")

self._actions: List[BoboAction] = actions
self._stop_on_fail: bool = stop_on_fail

def execute(self, event: BoboEventComplex) \
-> Tuple[bool, List[Tuple[bool, Any]]]:
"""
:param event: The complex event that triggered action.
:return: Whether the action execution was successful, and
any additional data.
"""
success = True
data: List[Tuple[bool, Any]] = []

for action in self._actions:
output: Tuple[bool, Any] = action.execute(event)
data.append(output)

# If action was unsuccessful
if not output[0]:
success = False

if self._stop_on_fail:
break

return success, data
2 changes: 1 addition & 1 deletion bobocep/cep/action/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"""
Handlers that coordinate the execution of actions.
"""

import logging
import multiprocessing
from abc import ABC, abstractmethod
from queue import Queue
from threading import RLock
Expand Down
6 changes: 4 additions & 2 deletions bobocep/cep/engine/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ def run(self) -> None:

def update(self) -> bool:
"""
Performs a single update from the receiver, to the decider, to the
producer, and finally to the forwarder.
Updates the receiver, then the decider, then the producer, and
finally to the forwarder.
It updates each task `n` times, depending on how many times were
chosen during engine instantiation.
:return: `True` if engine is not set to close; `False` otherwise.
"""
Expand Down
44 changes: 44 additions & 0 deletions bobocep/cep/engine/receiver/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,19 @@
from json import dumps
from typing import Any, List, Tuple

from jsonschema import validate as jsonschema_validate # type: ignore
from jsonschema.exceptions import ValidationError, SchemaError # type: ignore

from bobocep import BoboError
from bobocep.cep.event import BoboEvent


class BoboValidatorError(BoboError):
"""
A validator error.
"""


class BoboValidator(ABC):
"""An abstract validator."""

Expand Down Expand Up @@ -89,3 +99,37 @@ def is_valid(self, data: Any) -> bool:
return any(isinstance(data, t) for t in self._types)
else:
return any(type(data) == t for t in self._types)


class BoboValidatorJSONSchema(BoboValidatorJSONable):
"""
Validates whether the data type is valid with respect to
a given JSON Schema. If the data are a BoboEvent,
then the event's data are checked instead.
"""

def __init__(self, schema: dict):
"""
:param schema: The JSON schema against which to compare data.
"""
super().__init__()

self._schema: dict = schema

def is_valid(self, data: Any) -> bool:
"""
:return: `True` if data are valid as per the JSON schema;
`False` otherwise.
:raises: BoboValidatorError: Invalid JSON schema.
"""
try:
jsonschema_validate(instance=data, schema=self._schema)

except ValidationError:
return False

except SchemaError as e:
raise BoboValidatorError(e)

return True
3 changes: 1 addition & 2 deletions bobocep/cep/event/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
from abc import ABC, abstractmethod
from typing import Any

from bobocep import BoboError
from bobocep.bobocep import BoboJSONable
from bobocep import BoboError, BoboJSONable

_EXC_ID_LEN = "event ID must have a length greater than 0"

Expand Down
8 changes: 8 additions & 0 deletions bobocep/cep/phenom/phenom.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def __init__(self,
self._patterns: Tuple[BoboPattern, ...] = tuple(patterns)
self._datagen: Optional[Callable] = datagen
self._action: Optional[BoboAction] = action
self._retain: bool = retain

@property
def name(self) -> str:
Expand Down Expand Up @@ -95,3 +96,10 @@ def action(self) -> Optional[BoboAction]:
:return: Phenomenon action, or `None`.
"""
return self._action

@property
def retain(self) -> bool:
"""
:return: True if retains datagen callable; False otherwise.
"""
return self._retain
1 change: 1 addition & 0 deletions bobocep/dist/pubsub.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2019-2023 r3w0p
# The following code can be redistributed and/or
# modified under the terms of the MIT License.

"""
Distributed publish-subscribe classes.
"""
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
project = "BoboCEP"
copyright = "2019-2023 r3w0p"
author = "r3w0p"
version = "1.0.1"
version = "1.1.0"

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
Expand Down
Loading

0 comments on commit e6d2a4f

Please sign in to comment.