Skip to content

Commit

Permalink
Blacken the whole repository and add CI job
Browse files Browse the repository at this point in the history
  • Loading branch information
fepitre committed Oct 14, 2024
1 parent 37f5f14 commit 5c028c0
Show file tree
Hide file tree
Showing 24 changed files with 1,421 additions and 787 deletions.
8 changes: 8 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
include:
- file: /common.yml
project: QubesOS/qubes-continuous-integration
- file: /r4.3/gitlab-base.yml
project: QubesOS/qubes-continuous-integration
- file: /r4.3/gitlab-host.yml
Expand Down Expand Up @@ -42,3 +44,9 @@ checks:fuzz:
extends: .qrexec_checks
script:
- make -C fuzz test

lint:
extends: .lint
variables:
SKIP_PYLINT: 1
DIR: .
84 changes: 50 additions & 34 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,24 @@
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

sys.path.insert(0, os.path.abspath('../'))
sys.path.insert(0, os.path.abspath("../"))


# -- Project information -----------------------------------------------------

project = 'qubes-core-qrexec'
copyright = u'2010-{}, Invisible Things Lab'.format(time.strftime('%Y'))
author = 'Invisible Things Lab'
project = "qubes-core-qrexec"
copyright = "2010-{}, Invisible Things Lab".format(time.strftime("%Y"))
author = "Invisible Things Lab"

# The short X.Y version
version = open('../version').read().strip()
version = open("../version").read().strip()
# The full version, including alpha/beta/rc tags.
try:
release = subprocess.check_output(['git', 'describe', '--long', '--dirty']).strip().decode()
release = (
subprocess.check_output(["git", "describe", "--long", "--dirty"])
.strip()
.decode()
)
except:
release = "1"

Expand All @@ -45,25 +49,24 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.coverage',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode',

'recommonmark',
"sphinx.ext.autodoc",
"sphinx.ext.coverage",
"sphinx.ext.doctest",
"sphinx.ext.intersphinx",
"sphinx.ext.napoleon",
"sphinx.ext.viewcode",
"recommonmark",
]

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
source_suffix = ['.rst', '.markdown']
source_suffix = [".rst", ".markdown"]

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand All @@ -75,18 +78,18 @@
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path .
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"


# -- Options for HTML output -------------------------------------------------

# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'nature'
html_theme = "nature"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand All @@ -97,7 +100,7 @@
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_static_path = ["_static"]

# Custom sidebar templates, must be a dictionary that maps document names
# to template names.
Expand All @@ -113,7 +116,7 @@
# -- Options for HTMLHelp output ---------------------------------------------

# Output file base name for HTML help builder.
htmlhelp_basename = 'qubes-core-qrexecdoc'
htmlhelp_basename = "qubes-core-qrexecdoc"


# -- Options for LaTeX output ------------------------------------------------
Expand All @@ -122,15 +125,12 @@
# The paper size ('letterpaper' or 'a4paper').
#
# 'papersize': 'letterpaper',

# The font size ('10pt', '11pt' or '12pt').
#
# 'pointsize': '10pt',

# Additional stuff for the LaTeX preamble.
#
# 'preamble': '',

# Latex figure (float) alignment
#
# 'figure_align': 'htbp',
Expand All @@ -140,8 +140,13 @@
# (source start file, target name, title,
# author, documentclass [howto, manual, or own class]).
latex_documents = [
(master_doc, 'qubes-core-qrexec.tex', 'qubes-core-qrexec Documentation',
'Invisible Things Lab', 'manual'),
(
master_doc,
"qubes-core-qrexec.tex",
"qubes-core-qrexec Documentation",
"Invisible Things Lab",
"manual",
),
]


Expand All @@ -150,8 +155,13 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'qubes-core-qrexec', 'qubes-core-qrexec Documentation',
[author], 1)
(
master_doc,
"qubes-core-qrexec",
"qubes-core-qrexec Documentation",
[author],
1,
)
]


Expand All @@ -161,9 +171,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'qubes-core-qrexec', 'qubes-core-qrexec Documentation',
author, 'qubes-core-qrexec', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"qubes-core-qrexec",
"qubes-core-qrexec Documentation",
author,
"qubes-core-qrexec",
"One line description of project.",
"Miscellaneous",
),
]


Expand All @@ -173,6 +189,6 @@

# Example configuration for intersphinx: refer to the Python standard library.
intersphinx_mapping = {
'python': ('https://docs.python.org/', None),
'qubes': ('http://dev.qubes-os.org/projects/core-admin/en/latest/', None),
"python": ("https://docs.python.org/", None),
"qubes": ("http://dev.qubes-os.org/projects/core-admin/en/latest/", None),
}
14 changes: 9 additions & 5 deletions qrexec/exc.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import pathlib
from typing import Optional


class AccessDenied(Exception):
"""
Raised when qrexec policy denied access.
Expand All @@ -30,18 +31,21 @@ class AccessDenied(Exception):
(e.g. because we applied a policy that says `notify=no`).
"""

def __init__(self, msg: str, notify:bool=True):
def __init__(self, msg: str, notify: bool = True):
super().__init__(msg)
self.notify = notify


class PolicySyntaxError(AccessDenied):
"""Syntax error in qrexec policy, abort parsing"""

def __init__(self, filepath: Optional[pathlib.PurePath], lineno: Optional[int], msg: str):
super().__init__(
f"{filepath or '<unknown>'}:{lineno}: {msg}"
)
def __init__(
self,
filepath: Optional[pathlib.PurePath],
lineno: Optional[int],
msg: str,
):
super().__init__(f"{filepath or '<unknown>'}:{lineno}: {msg}")


class PolicyNotFound(AccessDenied):
Expand Down
20 changes: 12 additions & 8 deletions qrexec/policy/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ def handle_request(

if not all(char in RPCNAME_ALLOWED_CHARSET for char in arg):
raise PolicyAdminException(
"Invalid argument: \"{}\"\n"
'Invalid argument: "{}"\n'
"Valid characters are letters, numbers, dot, plus, hyphen and "
"underline".format(arg))
"underline".format(arg)
)

func = self._find_method(service_name)
if not func:
Expand Down Expand Up @@ -244,12 +245,14 @@ def _common_remove(self, path: Path, payload: str) -> None:
@method("policy.GetFiles", no_payload=True)
def policy_get_files(self, arg):
if not isinstance(arg, str) or not arg:
raise PolicyAdminException('Service cannot be empty.')
raise PolicyAdminException("Service cannot be empty.")
invalid_chars = get_invalid_characters(arg, disallowed="+")
if invalid_chars:
raise PolicyAdminException(
"Service {!r} contains invalid characters: {!r}".format(
arg, invalid_chars))
arg, invalid_chars
)
)

service = arg

Expand All @@ -267,16 +270,17 @@ def policy_get_files(self, arg):
if path_to_append not in file_list:
file_list.append(path_to_append)

return ("".join(f"{f}\n" for f in file_list)).encode('utf-8')
return ("".join(f"{f}\n" for f in file_list)).encode("utf-8")

# helpers

def _get_path(self, arg: str, dir_path: str , suffix: str) -> Path:
if not re.compile(r'^[\w-]+$').match(arg):
def _get_path(self, arg: str, dir_path: str, suffix: str) -> Path:
if not re.compile(r"^[\w-]+$").match(arg):
raise PolicyAdminException(
f"Invalid policy file name: {arg}\n"
"Names must contain only alphanumeric characters, "
"underscore and hyphen.")
"underscore and hyphen."
)
path = dir_path / (arg + suffix)
path = path.resolve()
if path.parent != dir_path:
Expand Down
Loading

0 comments on commit 5c028c0

Please sign in to comment.