Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
A-UNDERSCORE-D committed Jan 17, 2022
0 parents commit 135a066
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 0 deletions.
41 changes: 41 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[flake8]
# Show exactly where in a line the error happened
#show-source = True

max-line-length = 88
# Add _ as a builtin for localisation stuff

# check syntax in doctests
doctests = True
max-complexity = 15

# Plugin configs
# required plugins:

# https://github.com/Melevir/flake8-cognitive-complexity
# Provides cognitive complexity checking

# https://github.com/adamchainz/flake8-comprehensions
# Checks list/dict/set/* comprehensions for simplification or replacement

# https://github.com/PyCQA/pep8-naming
# checks names against PEP8 rules (eg CamelCase for class names)

# https://github.com/best-doctor/flake8-annotations-coverage
# Checks code for type annotations

# https://pypi.org/project/flake8-isort/
# Ensures imports are well sorted

# https://pypi.org/project/flake8-noqa/
# Ensures that noqa statements are correctly formed

# https://github.com/MichaelKim0407/flake8-use-fstring
# Prefers fstrings over .format and modulo based formatters

max-cognitive-complexity = 15

# require that all noqa directves disable specific errors
noqa-require-code = True

docstring-convention = numpy
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
venv
.mypy_cache
.pytest_cache
.vscode
2 changes: 2 additions & 0 deletions .mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[mypy]
strict=True
9 changes: 9 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[tool.isort]
multi_line_output = 5
line_length = 88

[tool.pytest.ini_options]
testpaths = ["tests"] # Search for tests in tests/

[tool.coverage.run]
omit = ["venv/*"] # when running pytest --cov, dont report coverage in venv directories
29 changes: 29 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
attrs==21.4.0
cognitive-complexity==1.2.0
coverage==6.2
flake8==4.0.1
flake8-annotations-coverage==0.0.5
flake8-cognitive-complexity==0.1.0
flake8-docstrings==1.6.0
flake8-noqa==1.2.1
flake8-polyfill==1.0.2
flake8-use-fstring==1.3
iniconfig==1.1.1
isort==5.10.1
mccabe==0.6.1
mypy==0.931
mypy-extensions==0.4.3
packaging==21.3
pep8-naming==0.12.1
pluggy==1.0.0
py==1.11.0
pycodestyle==2.8.0
pydocstyle==6.1.1
pyflakes==2.4.0
pyparsing==3.0.6
pytest==6.2.5
pytest-cov==3.0.0
snowballstemmer==2.2.0
toml==0.10.2
tomli==2.0.0
typing_extensions==4.0.1
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
irctokens==2.0.1
Empty file added riker/__init__.py
Empty file.
Empty file added riker/__main__.py
Empty file.
Empty file added riker/command.py
Empty file.
24 changes: 24 additions & 0 deletions riker/permission/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import annotations

import abc

from irctokens.line import Line


class BasePermissionHandler(abc.ABC):
"""
BasePermisionHandler covers everything required to manage permissions based
on incoming information from an IRC message
"""

@abc.abstractmethod
def check_permissions(self, line: Line) -> list[str]:
"""
Return the permissions available to the sender of a given line.
Do NOT modify line.
:param line: The line to check permissions on
:return: Any and all permissions a user on a given line may have
"""
...
55 changes: 55 additions & 0 deletions riker/permission/simple.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from __future__ import annotations

from fnmatch import fnmatch

from base import BasePermissionHandler
from irctokens.line import Line

# spell-checker: words oper


class DefaultPermissionHandler(BasePermissionHandler):
def __init__(self) -> None:
self.mask_permissions: dict[str, list[str]] = {}
self.enable_oper = True
self.oper_permissions: dict[str, list[str]] = {}
super().__init__()

def check_masks(self, to_check: str) -> list[str]:
out: list[str] = []

for mask in self.mask_permissions:
if fnmatch(to_check, mask):
out.extend(self.mask_permissions[mask])

return out

def check_oper(self, oper_name: str) -> list[str]:
if not self.enable_oper:
return []

out = []

for name in self.oper_permissions:
if fnmatch(oper_name, name):
out.extend(self.oper_permissions[name])

return out

def check_permissions(self, line: Line) -> list[str]:
"""
Return the permissions the sender of a given line has
:param line: The line to check
:return: a list of permission strings
"""
out: list[str] = []
out.extend(self.check_masks(str(line.hostmask)))

if self.enable_oper and line.tags is not None and "oper" in line.tags:
out.append("oper")

if line.tags["oper"] != "":
out.extend(self.check_oper(line.tags["oper"]))

return super().check_permissions(line)

0 comments on commit 135a066

Please sign in to comment.