Compare commits

..

No commits in common. "e40b7730297c69748016d700fcad913d604a1681" and "e4b22fd62094d0d8f088f347906b16fe7b2a6bc1" have entirely different histories.

19 changed files with 65 additions and 275 deletions

View File

@ -30,14 +30,6 @@ ahriman.web.cors module
:no-undoc-members:
:show-inheritance:
ahriman.web.keys module
-----------------------
.. automodule:: ahriman.web.keys
:members:
:no-undoc-members:
:show-inheritance:
ahriman.web.routes module
-------------------------

View File

@ -31,8 +31,8 @@ _shtab_ahriman_repo_check_option_strings=('-h' '--help' '--changes' '--no-change
_shtab_ahriman_check_option_strings=('-h' '--help' '--changes' '--no-changes' '-e' '--exit-code' '--vcs' '--no-vcs' '-y' '--refresh')
_shtab_ahriman_repo_create_keyring_option_strings=('-h' '--help')
_shtab_ahriman_repo_create_mirrorlist_option_strings=('-h' '--help')
_shtab_ahriman_repo_daemon_option_strings=('-h' '--help' '-i' '--interval' '--aur' '--no-aur' '--changes' '--no-changes' '--dependencies' '--no-dependencies' '--dry-run' '--increment' '--no-increment' '--local' '--no-local' '--manual' '--no-manual' '--partitions' '--no-partitions' '-u' '--username' '--vcs' '--no-vcs' '-y' '--refresh')
_shtab_ahriman_daemon_option_strings=('-h' '--help' '-i' '--interval' '--aur' '--no-aur' '--changes' '--no-changes' '--dependencies' '--no-dependencies' '--dry-run' '--increment' '--no-increment' '--local' '--no-local' '--manual' '--no-manual' '--partitions' '--no-partitions' '-u' '--username' '--vcs' '--no-vcs' '-y' '--refresh')
_shtab_ahriman_repo_daemon_option_strings=('-h' '--help' '-i' '--interval' '--aur' '--no-aur' '--changes' '--no-changes' '--dependencies' '--no-dependencies' '--dry-run' '--local' '--no-local' '--manual' '--no-manual' '--partitions' '--no-partitions' '--vcs' '--no-vcs' '-y' '--refresh')
_shtab_ahriman_daemon_option_strings=('-h' '--help' '-i' '--interval' '--aur' '--no-aur' '--changes' '--no-changes' '--dependencies' '--no-dependencies' '--dry-run' '--local' '--no-local' '--manual' '--no-manual' '--partitions' '--no-partitions' '--vcs' '--no-vcs' '-y' '--refresh')
_shtab_ahriman_repo_rebuild_option_strings=('-h' '--help' '--depends-on' '--dry-run' '--from-database' '--increment' '--no-increment' '-e' '--exit-code' '-s' '--status' '-u' '--username')
_shtab_ahriman_rebuild_option_strings=('-h' '--help' '--depends-on' '--dry-run' '--from-database' '--increment' '--no-increment' '-e' '--exit-code' '-s' '--status' '-u' '--username')
_shtab_ahriman_repo_remove_unknown_option_strings=('-h' '--help' '--dry-run')
@ -273,8 +273,6 @@ _shtab_ahriman_repo_daemon___no_changes_nargs=0
_shtab_ahriman_repo_daemon___dependencies_nargs=0
_shtab_ahriman_repo_daemon___no_dependencies_nargs=0
_shtab_ahriman_repo_daemon___dry_run_nargs=0
_shtab_ahriman_repo_daemon___increment_nargs=0
_shtab_ahriman_repo_daemon___no_increment_nargs=0
_shtab_ahriman_repo_daemon___local_nargs=0
_shtab_ahriman_repo_daemon___no_local_nargs=0
_shtab_ahriman_repo_daemon___manual_nargs=0
@ -294,8 +292,6 @@ _shtab_ahriman_daemon___no_changes_nargs=0
_shtab_ahriman_daemon___dependencies_nargs=0
_shtab_ahriman_daemon___no_dependencies_nargs=0
_shtab_ahriman_daemon___dry_run_nargs=0
_shtab_ahriman_daemon___increment_nargs=0
_shtab_ahriman_daemon___no_increment_nargs=0
_shtab_ahriman_daemon___local_nargs=0
_shtab_ahriman_daemon___no_local_nargs=0
_shtab_ahriman_daemon___manual_nargs=0

View File

@ -1,4 +1,4 @@
.TH AHRIMAN "1" "2023\-12\-27" "ahriman" "Generated Python Manual"
.TH AHRIMAN "1" "2023\-12\-26" "ahriman" "Generated Python Manual"
.SH NAME
ahriman
.SH SYNOPSIS
@ -484,9 +484,8 @@ create package which contains list of available mirrors as set by configuration.
.SH COMMAND \fI\,'ahriman repo\-daemon'\/\fR
usage: ahriman repo\-daemon [\-h] [\-i INTERVAL] [\-\-aur | \-\-no\-aur] [\-\-changes | \-\-no\-changes]
[\-\-dependencies | \-\-no\-dependencies] [\-\-dry\-run] [\-\-increment | \-\-no\-increment]
[\-\-local | \-\-no\-local] [\-\-manual | \-\-no\-manual] [\-\-partitions | \-\-no\-partitions]
[\-u USERNAME] [\-\-vcs | \-\-no\-vcs] [\-y]
[\-\-dependencies | \-\-no\-dependencies] [\-\-dry\-run] [\-\-local | \-\-no\-local]
[\-\-manual | \-\-no\-manual] [\-\-partitions | \-\-no\-partitions] [\-\-vcs | \-\-no\-vcs] [\-y]
start process which periodically will run update process
@ -511,10 +510,6 @@ process missing package dependencies
\fB\-\-dry\-run\fR
just perform check for updates, same as check command
.TP
\fB\-\-increment\fR, \fB\-\-no\-increment\fR
increment package release (pkgrel) on duplicate
.TP
\fB\-\-local\fR, \fB\-\-no\-local\fR
enable or disable checking of local packages for updates
@ -527,10 +522,6 @@ include or exclude manual updates
\fB\-\-partitions\fR, \fB\-\-no\-partitions\fR
instead of updating whole repository, split updates into chunks
.TP
\fB\-u\fR \fI\,USERNAME\/\fR, \fB\-\-username\fR \fI\,USERNAME\/\fR
build as user
.TP
\fB\-\-vcs\fR, \fB\-\-no\-vcs\fR
fetch actual version of VCS packages

View File

@ -155,11 +155,9 @@ _shtab_ahriman_daemon_options=(
{--changes,--no-changes}"[calculate changes from the latest known commit if available. Only applicable in dry run mode (default\: True)]:changes:"
{--dependencies,--no-dependencies}"[process missing package dependencies (default\: True)]:dependencies:"
"--dry-run[just perform check for updates, same as check command (default\: False)]"
{--increment,--no-increment}"[increment package release (pkgrel) on duplicate (default\: True)]:increment:"
{--local,--no-local}"[enable or disable checking of local packages for updates (default\: True)]:local:"
{--manual,--no-manual}"[include or exclude manual updates (default\: True)]:manual:"
{--partitions,--no-partitions}"[instead of updating whole repository, split updates into chunks (default\: True)]:partitions:"
{-u,--username}"[build as user (default\: None)]:username:"
{--vcs,--no-vcs}"[fetch actual version of VCS packages (default\: True)]:vcs:"
"*"{-y,--refresh}"[download fresh package databases from the mirror before actions, -yy to force refresh even if up to date (default\: False)]"
)
@ -365,11 +363,9 @@ _shtab_ahriman_repo_daemon_options=(
{--changes,--no-changes}"[calculate changes from the latest known commit if available. Only applicable in dry run mode (default\: True)]:changes:"
{--dependencies,--no-dependencies}"[process missing package dependencies (default\: True)]:dependencies:"
"--dry-run[just perform check for updates, same as check command (default\: False)]"
{--increment,--no-increment}"[increment package release (pkgrel) on duplicate (default\: True)]:increment:"
{--local,--no-local}"[enable or disable checking of local packages for updates (default\: True)]:local:"
{--manual,--no-manual}"[include or exclude manual updates (default\: True)]:manual:"
{--partitions,--no-partitions}"[instead of updating whole repository, split updates into chunks (default\: True)]:partitions:"
{-u,--username}"[build as user (default\: None)]:username:"
{--vcs,--no-vcs}"[fetch actual version of VCS packages (default\: True)]:vcs:"
"*"{-y,--refresh}"[download fresh package databases from the mirror before actions, -yy to force refresh even if up to date (default\: False)]"
)

View File

@ -317,8 +317,7 @@ def _set_package_changes_remove_parser(root: SubParserAction) -> argparse.Argume
description="remove the package changes stored remotely",
formatter_class=_formatter)
parser.add_argument("package", help="package base")
parser.set_defaults(handler=handlers.Change, action=Action.Remove, exit_code=False, lock=None, quiet=True,
report=False, unsafe=True)
parser.set_defaults(handler=handlers.Change, action=Action.Remove, lock=None, quiet=True, report=False, unsafe=True)
return parser
@ -429,8 +428,8 @@ def _set_patch_add_parser(root: SubParserAction) -> argparse.ArgumentParser:
"it must end with ()")
parser.add_argument("patch", help="path to file which contains function or variable value. If not set, "
"the value will be read from stdin", type=Path, nargs="?")
parser.set_defaults(handler=handlers.Patch, action=Action.Update, architecture="", exit_code=False, lock=None,
report=False, repository="")
parser.set_defaults(handler=handlers.Patch, action=Action.Update, architecture="", lock=None, report=False,
repository="")
return parser
@ -472,8 +471,8 @@ def _set_patch_remove_parser(root: SubParserAction) -> argparse.ArgumentParser:
"to remove only specified PKGBUILD variables. In case if not set, "
"it will remove all patches related to the package",
action="append")
parser.set_defaults(handler=handlers.Patch, action=Action.Remove, architecture="", exit_code=False, lock=None,
report=False, repository="")
parser.set_defaults(handler=handlers.Patch, action=Action.Remove, architecture="", lock=None, report=False,
repository="")
return parser
@ -497,8 +496,8 @@ def _set_patch_set_add_parser(root: SubParserAction) -> argparse.ArgumentParser:
parser.add_argument("package", help="path to directory with changed files for patch addition/update", type=Path)
parser.add_argument("-t", "--track", help="files which has to be tracked", action="append",
default=["*.diff", "*.patch"])
parser.set_defaults(handler=handlers.Patch, action=Action.Update, architecture="", exit_code=False, lock=None,
report=False, repository="", variable=None)
parser.set_defaults(handler=handlers.Patch, action=Action.Update, architecture="", lock=None, report=False,
repository="", variable=None)
return parser
@ -543,8 +542,8 @@ def _set_repo_check_parser(root: SubParserAction) -> argparse.ArgumentParser:
parser.add_argument("-y", "--refresh", help="download fresh package databases from the mirror before actions, "
"-yy to force refresh even if up to date",
action="count", default=False)
parser.set_defaults(handler=handlers.Update, aur=True, dependencies=False, dry_run=True, increment=False,
local=True, manual=False, username=None)
parser.set_defaults(handler=handlers.Update, dependencies=False, dry_run=True, aur=True, local=True, manual=False,
username=None)
return parser
@ -1074,8 +1073,8 @@ def _set_user_add_parser(root: SubParserAction) -> argparse.ArgumentParser:
"which is in particular must be used for OAuth2 authorization type.")
parser.add_argument("-R", "--role", help="user access level",
type=UserAccess, choices=enum_values(UserAccess), default=UserAccess.Read)
parser.set_defaults(handler=handlers.Users, action=Action.Update, architecture="", exit_code=False, lock=None,
quiet=True, report=False, repository="")
parser.set_defaults(handler=handlers.Users, action=Action.Update, architecture="", lock=None, quiet=True,
report=False, repository="")
return parser
@ -1114,8 +1113,8 @@ def _set_user_remove_parser(root: SubParserAction) -> argparse.ArgumentParser:
description="remove user from the user mapping and update the configuration",
formatter_class=_formatter)
parser.add_argument("username", help="username for web service")
parser.set_defaults(handler=handlers.Users, action=Action.Remove, architecture="", exit_code=False, lock=None,
quiet=True, report=False, repository="")
parser.set_defaults(handler=handlers.Users, action=Action.Remove, architecture="", lock=None, quiet=True,
report=False, repository="")
return parser

View File

@ -22,7 +22,6 @@ import argparse
from ahriman.application.application import Application
from ahriman.application.application.updates_iterator import FixedUpdatesIterator, UpdatesIterator
from ahriman.application.handlers import Handler
from ahriman.application.handlers.update import Update
from ahriman.core.configuration import Configuration
from ahriman.models.repository_id import RepositoryId
@ -44,6 +43,8 @@ class Daemon(Handler):
configuration(Configuration): configuration instance
report(bool): force enable or disable reporting
"""
from ahriman.application.handlers import Update
application = Application(repository_id, configuration, report=report, refresh_pacman_database=args.refresh)
if args.partitions:
iterator = UpdatesIterator(application, args.interval)

View File

@ -23,7 +23,7 @@ from aiohttp.web import Application
from typing import Any
from ahriman import __version__
from ahriman.web.keys import ConfigurationKey
from ahriman.core.configuration import Configuration
__all__ = ["setup_apispec"]
@ -89,7 +89,7 @@ def _servers(application: Application) -> list[dict[str, Any]]:
Returns:
list[dict[str, Any]]: list (actually only one) of defined web urls
"""
configuration = application[ConfigurationKey]
configuration: Configuration = application["configuration"]
address = configuration.get("web", "address", fallback=None)
if not address:
host = configuration.get("web", "host")

View File

@ -1,40 +0,0 @@
#
# Copyright (c) 2021-2023 ahriman team.
#
# This file is part of ahriman
# (see https://github.com/arcan1s/ahriman).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from aiohttp.web import AppKey
from ahriman.core.auth import Auth
from ahriman.core.configuration import Configuration
from ahriman.core.spawn import Spawn
from ahriman.core.status.watcher import Watcher
from ahriman.models.repository_id import RepositoryId
__all__ = [
"AuthKey",
"ConfigurationKey",
"SpawnKey",
"WatcherKey",
]
AuthKey = AppKey("validator", Auth)
ConfigurationKey = AppKey("configuration", Configuration)
SpawnKey = AppKey("spawn", Spawn)
WatcherKey = AppKey("watcher", dict[RepositoryId, Watcher])

View File

@ -154,7 +154,7 @@ def setup_auth(application: Application, configuration: Configuration, validator
setup_session(application, storage)
authorization_policy = _AuthorizationPolicy(validator)
identity_policy = aiohttp_security.SessionIdentityPolicy()
identity_policy = application["identity"] = aiohttp_security.SessionIdentityPolicy()
aiohttp_security.setup(application, identity_policy, authorization_policy)
application.middlewares.append(_auth_handler(validator.allow_read_only))

View File

@ -29,7 +29,6 @@ from ahriman.core.spawn import Spawn
from ahriman.core.status.watcher import Watcher
from ahriman.models.repository_id import RepositoryId
from ahriman.models.user_access import UserAccess
from ahriman.web.keys import AuthKey, ConfigurationKey, SpawnKey, WatcherKey
T = TypeVar("T", str, list[str])
@ -55,7 +54,8 @@ class BaseView(View, CorsViewMixin):
Returns:
Configuration: configuration instance
"""
return self.request.app[ConfigurationKey]
configuration: Configuration = self.request.app["configuration"]
return configuration
@property
def services(self) -> dict[RepositoryId, Watcher]:
@ -65,7 +65,8 @@ class BaseView(View, CorsViewMixin):
Returns:
dict[RepositoryId, Watcher]: map of loaded watchers per known repository
"""
return self.request.app[WatcherKey]
watchers: dict[RepositoryId, Watcher] = self.request.app["watcher"]
return watchers
@property
def sign(self) -> GPG:
@ -85,7 +86,8 @@ class BaseView(View, CorsViewMixin):
Returns:
Spawn: external process spawner instance
"""
return self.request.app[SpawnKey]
spawner: Spawn = self.request.app["spawn"]
return spawner
@property
def validator(self) -> Auth:
@ -95,7 +97,8 @@ class BaseView(View, CorsViewMixin):
Returns:
Auth: authorization service instance
"""
return self.request.app[AuthKey]
validator: Auth = self.request.app["validator"]
return validator
@classmethod
async def get_permission(cls, request: Request) -> UserAccess:

View File

@ -34,7 +34,6 @@ from ahriman.core.status.watcher import Watcher
from ahriman.models.repository_id import RepositoryId
from ahriman.web.apispec import setup_apispec
from ahriman.web.cors import setup_cors
from ahriman.web.keys import AuthKey, ConfigurationKey, SpawnKey, WatcherKey
from ahriman.web.middlewares.exception_handler import exception_handler
from ahriman.web.routes import setup_routes
@ -98,7 +97,7 @@ async def _on_startup(application: Application) -> None:
application.logger.info("server started")
try:
for watcher in application[WatcherKey].values():
for watcher in application["watcher"].values():
watcher.load()
except Exception:
message = "could not load packages"
@ -115,7 +114,7 @@ def run_server(application: Application) -> None:
"""
application.logger.info("start server")
configuration = application[ConfigurationKey]
configuration: Configuration = application["configuration"]
host = configuration.get("web", "host")
port = configuration.getint("web", "port")
unix_socket = _create_socket(configuration, application)
@ -157,7 +156,7 @@ def setup_server(configuration: Configuration, spawner: Spawn, repositories: lis
aiohttp_jinja2.setup(application, trim_blocks=True, lstrip_blocks=True, autoescape=True, loader=loader)
application.logger.info("setup configuration")
application[ConfigurationKey] = configuration
application["configuration"] = configuration
application.logger.info("setup watchers")
if not repositories:
@ -167,13 +166,13 @@ def setup_server(configuration: Configuration, spawner: Spawn, repositories: lis
for repository_id in repositories:
application.logger.info("load repository %s", repository_id)
watchers[repository_id] = Watcher(repository_id, database)
application[WatcherKey] = watchers
application["watcher"] = watchers
application.logger.info("setup process spawner")
application[SpawnKey] = spawner
application["spawn"] = spawner
application.logger.info("setup authorization")
validator = application[AuthKey] = Auth.load(configuration, database)
validator = application["validator"] = Auth.load(configuration, database)
if validator.enabled:
from ahriman.web.middlewares.auth_handler import setup_auth
setup_auth(application, configuration, validator)

View File

@ -272,12 +272,11 @@ def test_subparsers_package_add_option_variable_multiple(parser: argparse.Argume
def test_subparsers_package_changes(parser: argparse.ArgumentParser) -> None:
"""
package-changes command must imply action, exit code, lock, quiet, report and unsafe
package-changes command must imply action, lock, quiet, report and unsafe
"""
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-changes", "ahriman"])
assert args.action == Action.List
assert args.architecture == "x86_64"
assert not args.exit_code
assert args.lock is None
assert args.quiet
assert not args.report
@ -299,15 +298,6 @@ def test_subparsers_package_changes_remove(parser: argparse.ArgumentParser) -> N
assert args.unsafe
def test_subparsers_package_changes_remove_package_changes(parser: argparse.ArgumentParser) -> None:
"""
package-changes-remove must have same keys as package-changes
"""
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-changes-remove", "ahriman"])
reference_args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-changes", "ahriman"])
assert dir(args) == dir(reference_args)
def test_subparsers_package_remove_option_architecture(parser: argparse.ArgumentParser) -> None:
"""
package-remove command must correctly parse architecture list
@ -379,24 +369,13 @@ def test_subparsers_package_status_update_option_status(parser: argparse.Argumen
assert isinstance(args.status, BuildStatusEnum)
def test_subparsers_package_status_update_package_status_remove(parser: argparse.ArgumentParser) -> None:
"""
package-status-update must have same keys as package-status-remove
"""
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-status-update"])
reference_args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-status-remove", "ahriman"])
del args.status
assert dir(args) == dir(reference_args)
def test_subparsers_patch_add(parser: argparse.ArgumentParser) -> None:
"""
patch-add command must imply action, architecture list, exit code, lock, report and repository
patch-add command must imply action, architecture list, lock, report and repository
"""
args = parser.parse_args(["patch-add", "ahriman", "version"])
assert args.action == Action.Update
assert args.architecture == ""
assert not args.exit_code
assert args.lock is None
assert not args.report
assert args.repository == ""
@ -463,24 +442,13 @@ def test_subparsers_patch_list_option_variable_multiple(parser: argparse.Argumen
assert args.variable == ["var1", "var2"]
def test_subparsers_patch_list_patch_add(parser: argparse.ArgumentParser) -> None:
"""
patch-list must have same keys as patch-add
"""
args = parser.parse_args(["patch-list", "ahriman"])
reference_args = parser.parse_args(["patch-add", "ahriman", "version"])
del reference_args.patch
assert dir(args) == dir(reference_args)
def test_subparsers_patch_remove(parser: argparse.ArgumentParser) -> None:
"""
patch-remove command must imply action, architecture list, exit code, lock, report and repository
patch-remove command must imply action, architecture list, lock, report and repository
"""
args = parser.parse_args(["patch-remove", "ahriman"])
assert args.action == Action.Remove
assert args.architecture == ""
assert not args.exit_code
assert args.lock is None
assert not args.report
assert args.repository == ""
@ -518,24 +486,13 @@ def test_subparsers_patch_remove_option_variable_multiple(parser: argparse.Argum
assert args.variable == ["var1", "var2"]
def test_subparsers_patch_remove_patch_add(parser: argparse.ArgumentParser) -> None:
"""
patch-remove must have same keys as patch-add
"""
args = parser.parse_args(["patch-remove", "ahriman"])
reference_args = parser.parse_args(["patch-add", "ahriman", "version"])
del reference_args.patch
assert dir(args) == dir(reference_args)
def test_subparsers_patch_set_add(parser: argparse.ArgumentParser) -> None:
"""
patch-set-add command must imply action, architecture list, exit code, lock, report, repository and variable
patch-set-add command must imply action, architecture list, lock, report, repository and variable
"""
args = parser.parse_args(["patch-set-add", "ahriman"])
assert args.action == Action.Update
assert args.architecture == ""
assert not args.exit_code
assert args.lock is None
assert not args.report
assert args.repository == ""
@ -574,16 +531,6 @@ def test_subparsers_patch_set_add_option_track(parser: argparse.ArgumentParser)
assert args.track == ["*.diff", "*.patch", "*.py"]
def test_subparsers_patch_set_add_patch_add(parser: argparse.ArgumentParser) -> None:
"""
patch-set-add must have same keys as patch-add
"""
args = parser.parse_args(["patch-set-add", "ahriman"])
reference_args = parser.parse_args(["patch-add", "ahriman", "version"])
del reference_args.patch, args.track
assert dir(args) == dir(reference_args)
def test_subparsers_repo_backup(parser: argparse.ArgumentParser) -> None:
"""
repo-backup command must imply architecture list, lock, report, repository and unsafe
@ -614,14 +561,12 @@ def test_subparsers_repo_backup_option_repository(parser: argparse.ArgumentParse
def test_subparsers_repo_check(parser: argparse.ArgumentParser) -> None:
"""
repo-check command must imply aur, dependencies, dry-run, increment, local, manual and username
repo-check command must imply dependencies, dry-run, aur, manual and username
"""
args = parser.parse_args(["repo-check"])
assert args.aur
assert not args.dependencies
assert args.dry_run
assert not args.increment
assert args.local
assert args.aur
assert not args.manual
assert args.username is None
@ -658,15 +603,6 @@ def test_subparsers_repo_check_option_refresh(parser: argparse.ArgumentParser) -
assert args.refresh == 2
def test_subparsers_repo_check_repo_update(parser: argparse.ArgumentParser) -> None:
"""
repo-check must have same keys as repo-update
"""
args = parser.parse_args(["repo-check"])
reference_args = parser.parse_args(["repo-update"])
assert dir(args) == dir(reference_args)
def test_subparsers_repo_create_keyring(parser: argparse.ArgumentParser) -> None:
"""
repo-create-keyring command must imply trigger
@ -695,15 +631,6 @@ def test_subparsers_repo_create_keyring_option_repository(parser: argparse.Argum
assert args.repository == "repo"
def test_subparsers_repo_create_keyring_repo_triggers(parser: argparse.ArgumentParser) -> None:
"""
repo-create-keyring must have same keys as repo-triggers
"""
args = parser.parse_args(["repo-create-keyring"])
reference_args = parser.parse_args(["repo-triggers"])
assert dir(args) == dir(reference_args)
def test_subparsers_repo_create_mirrorlist(parser: argparse.ArgumentParser) -> None:
"""
repo-create-mirrorlist command must imply trigger
@ -732,15 +659,6 @@ def test_subparsers_repo_create_mirrorlist_option_repository(parser: argparse.Ar
assert args.repository == "repo"
def test_subparsers_repo_create_mirrorlist_repo_triggers(parser: argparse.ArgumentParser) -> None:
"""
repo-create-mirrorlist must have same keys as repo-triggers
"""
args = parser.parse_args(["repo-create-mirrorlist"])
reference_args = parser.parse_args(["repo-triggers"])
assert dir(args) == dir(reference_args)
def test_subparsers_repo_daemon(parser: argparse.ArgumentParser) -> None:
"""
repo-daemon command must imply exit code and package
@ -772,16 +690,6 @@ def test_subparsers_repo_daemon_option_interval(parser: argparse.ArgumentParser)
assert isinstance(args.interval, int)
def test_subparsers_repo_daemon_repo_update(parser: argparse.ArgumentParser) -> None:
"""
repo-create-keyring must have same keys as repo-triggers
"""
args = parser.parse_args(["repo-daemon"])
reference_args = parser.parse_args(["repo-update"])
del args.interval, args.partitions
assert dir(args) == dir(reference_args)
def test_subparsers_repo_rebuild_option_architecture(parser: argparse.ArgumentParser) -> None:
"""
repo-rebuild command must correctly parse architecture list
@ -874,15 +782,6 @@ def test_subparsers_repo_report_option_repository(parser: argparse.ArgumentParse
assert args.repository == "repo"
def test_subparsers_repo_report_repo_triggers(parser: argparse.ArgumentParser) -> None:
"""
repo-report must have same keys as repo-triggers
"""
args = parser.parse_args(["repo-report"])
reference_args = parser.parse_args(["repo-triggers"])
assert dir(args) == dir(reference_args)
def test_subparsers_repo_restore(parser: argparse.ArgumentParser) -> None:
"""
repo-restore command must imply architecture list, lock, report, repository and unsafe
@ -956,15 +855,6 @@ def test_subparsers_repo_status_update_option_status(parser: argparse.ArgumentPa
assert isinstance(args.status, BuildStatusEnum)
def test_subparsers_repo_status_update_package_status_update(parser: argparse.ArgumentParser) -> None:
"""
repo-status-update must have same keys as package-status-update
"""
args = parser.parse_args(["-a", "x86_64", "-r", "repo", "repo-status-update"])
reference_args = parser.parse_args(["-a", "x86_64", "-r", "repo", "package-status-update"])
assert dir(args) == dir(reference_args)
def test_subparsers_repo_sync(parser: argparse.ArgumentParser) -> None:
"""
repo-sync command must imply trigger
@ -993,15 +883,6 @@ def test_subparsers_repo_sync_option_repository(parser: argparse.ArgumentParser)
assert args.repository == "repo"
def test_subparsers_repo_sync_repo_triggers(parser: argparse.ArgumentParser) -> None:
"""
repo-sync must have same keys as repo-triggers
"""
args = parser.parse_args(["repo-sync"])
reference_args = parser.parse_args(["repo-triggers"])
assert dir(args) == dir(reference_args)
def test_subparsers_repo_tree(parser: argparse.ArgumentParser) -> None:
"""
repo-tree command must imply lock, quiet, report and unsafe
@ -1322,12 +1203,11 @@ def test_subparsers_service_tree_migrate(parser: argparse.ArgumentParser) -> Non
def test_subparsers_user_add(parser: argparse.ArgumentParser) -> None:
"""
user-add command must imply action, architecture, exit code, lock, quiet, report and repository
user-add command must imply action, architecture, lock, quiet, report and repository
"""
args = parser.parse_args(["user-add", "username"])
assert args.action == Action.Update
assert args.architecture == ""
assert not args.exit_code
assert args.lock is None
assert args.quiet
assert not args.report
@ -1398,24 +1278,13 @@ def test_subparsers_user_list_option_role(parser: argparse.ArgumentParser) -> No
assert isinstance(args.role, UserAccess)
def test_subparsers_user_list_user_add(parser: argparse.ArgumentParser) -> None:
"""
user-list must have same keys as user-add
"""
args = parser.parse_args(["user-list"])
reference_args = parser.parse_args(["user-add", "username"])
del reference_args.key, reference_args.packager, reference_args.password
assert dir(args) == dir(reference_args)
def test_subparsers_user_remove(parser: argparse.ArgumentParser) -> None:
"""
user-remove command must imply action, architecture, exit code, lock, quiet, report and repository
user-remove command must imply action, architecture, lock, quiet, report and repository
"""
args = parser.parse_args(["user-remove", "username"])
assert args.action == Action.Remove
assert args.architecture == ""
assert not args.exit_code
assert args.lock is None
assert args.quiet
assert not args.report
@ -1438,16 +1307,6 @@ def test_subparsers_user_remove_option_repository(parser: argparse.ArgumentParse
assert args.repository == ""
def test_subparsers_user_remove_user_add(parser: argparse.ArgumentParser) -> None:
"""
user-list must have same keys as user-add
"""
args = parser.parse_args(["user-remove", "username"])
reference_args = parser.parse_args(["user-add", "username"])
del reference_args.key, reference_args.packager, reference_args.password, reference_args.role
assert dir(args) == dir(reference_args)
def test_subparsers_web(parser: argparse.ArgumentParser) -> None:
"""
web command must imply architecture, report, repository and parser

View File

@ -16,7 +16,6 @@ from ahriman.core.configuration import Configuration
from ahriman.core.database import SQLite
from ahriman.core.spawn import Spawn
from ahriman.models.user import User
from ahriman.web.keys import AuthKey
from ahriman.web.web import setup_server
@ -160,7 +159,7 @@ def application_with_auth(configuration: Configuration, user: User, spawner: Spa
_, repository_id = configuration.check_loaded()
application = setup_server(configuration, spawner, [repository_id])
generated = user.hash_password(application[AuthKey].salt)
generated = user.hash_password(application["validator"].salt)
mocker.patch("ahriman.core.database.SQLite.user_get", return_value=generated)
return application
@ -246,5 +245,5 @@ def client_with_oauth_auth(application_with_auth: Application, event_loop: BaseE
TestClient: web client test instance
"""
mocker.patch("pathlib.Path.iterdir", return_value=[])
application_with_auth[AuthKey] = MagicMock(spec=OAuth)
application_with_auth["validator"] = MagicMock(spec=OAuth)
return event_loop.run_until_complete(aiohttp_client(application_with_auth))

View File

@ -12,7 +12,6 @@ from ahriman.core.configuration import Configuration
from ahriman.models.build_status import BuildStatusEnum
from ahriman.models.user import User
from ahriman.models.user_access import UserAccess
from ahriman.web.keys import AuthKey
from ahriman.web.middlewares.auth_handler import _AuthorizationPolicy, _auth_handler, _cookie_secret_key, setup_auth
@ -193,5 +192,5 @@ def test_setup_auth(application_with_auth: Application, configuration: Configura
"""
setup_mock = mocker.patch("aiohttp_security.setup")
application = setup_auth(application_with_auth, configuration, auth)
assert application.get(AuthKey) is not None
assert application.get("validator") is not None
setup_mock.assert_called_once_with(application_with_auth, pytest.helpers.anyvar(int), pytest.helpers.anyvar(int))

View File

@ -5,7 +5,6 @@ from pytest_mock import MockerFixture
from ahriman import __version__
from ahriman.web.apispec import _info, _security, _servers, setup_apispec
from ahriman.web.keys import ConfigurationKey
def test_info() -> None:
@ -37,7 +36,7 @@ def test_servers_address(application: Application) -> None:
"""
must generate servers definitions with address
"""
application[ConfigurationKey].set_option("web", "address", "https://example.com")
application["configuration"].set_option("web", "address", "https://example.com")
servers = _servers(application)
assert servers == [{"url": "https://example.com"}]

View File

@ -10,7 +10,6 @@ from ahriman.core.exceptions import InitializeError
from ahriman.core.log.filtered_access_logger import FilteredAccessLogger
from ahriman.core.spawn import Spawn
from ahriman.core.status.watcher import Watcher
from ahriman.web.keys import ConfigurationKey
from ahriman.web.web import _create_socket, _on_shutdown, _on_startup, run_server, setup_server
@ -19,14 +18,14 @@ async def test_create_socket(application: Application, mocker: MockerFixture) ->
must create socket
"""
path = "/run/ahriman.sock"
application[ConfigurationKey].set_option("web", "unix_socket", str(path))
application["configuration"].set_option("web", "unix_socket", str(path))
current_on_shutdown = len(application.on_shutdown)
bind_mock = mocker.patch("socket.socket.bind")
chmod_mock = mocker.patch("pathlib.Path.chmod")
unlink_mock = mocker.patch("pathlib.Path.unlink")
sock = _create_socket(application[ConfigurationKey], application)
sock = _create_socket(application["configuration"], application)
assert sock.family == socket.AF_UNIX
assert sock.type == socket.SOCK_STREAM
bind_mock.assert_called_once_with(str(path))
@ -42,7 +41,7 @@ def test_create_socket_empty(application: Application) -> None:
"""
must skip socket creation if not set by configuration
"""
assert _create_socket(application[ConfigurationKey], application) is None
assert _create_socket(application["configuration"], application) is None
def test_create_socket_safe(application: Application, mocker: MockerFixture) -> None:
@ -50,14 +49,14 @@ def test_create_socket_safe(application: Application, mocker: MockerFixture) ->
must create socket with default permission set
"""
path = "/run/ahriman.sock"
application[ConfigurationKey].set_option("web", "unix_socket", str(path))
application[ConfigurationKey].set_option("web", "unix_socket_unsafe", "no")
application["configuration"].set_option("web", "unix_socket", str(path))
application["configuration"].set_option("web", "unix_socket_unsafe", "no")
mocker.patch("socket.socket.bind")
mocker.patch("pathlib.Path.unlink")
chmod_mock = mocker.patch("pathlib.Path.chmod")
sock = _create_socket(application[ConfigurationKey], application)
sock = _create_socket(application["configuration"], application)
assert sock is not None
chmod_mock.assert_not_called()
@ -98,7 +97,7 @@ def test_run(application: Application, mocker: MockerFixture) -> None:
must run application
"""
port = 8080
application[ConfigurationKey].set_option("web", "port", str(port))
application["configuration"].set_option("web", "port", str(port))
run_application_mock = mocker.patch("ahriman.web.web.run_app")
run_server(application)
@ -113,7 +112,7 @@ def test_run_with_auth(application_with_auth: Application, mocker: MockerFixture
must run application with enabled authorization
"""
port = 8080
application_with_auth[ConfigurationKey].set_option("web", "port", str(port))
application_with_auth["configuration"].set_option("web", "port", str(port))
run_application_mock = mocker.patch("ahriman.web.web.run_app")
run_server(application_with_auth)
@ -128,12 +127,12 @@ def test_run_with_socket(application: Application, mocker: MockerFixture) -> Non
must run application
"""
port = 8080
application[ConfigurationKey].set_option("web", "port", str(port))
application["configuration"].set_option("web", "port", str(port))
socket_mock = mocker.patch("ahriman.web.web._create_socket", return_value=42)
run_application_mock = mocker.patch("ahriman.web.web.run_app")
run_server(application)
socket_mock.assert_called_once_with(application[ConfigurationKey], application)
socket_mock.assert_called_once_with(application["configuration"], application)
run_application_mock.assert_called_once_with(
application, host="127.0.0.1", port=port, sock=42, handle_signals=True,
access_log=pytest.helpers.anyvar(int), access_log_class=FilteredAccessLogger

View File

@ -9,7 +9,6 @@ from unittest.mock import AsyncMock
from ahriman.core.configuration import Configuration
from ahriman.models.repository_id import RepositoryId
from ahriman.models.user_access import UserAccess
from ahriman.web.keys import WatcherKey
from ahriman.web.views.base import BaseView
@ -173,9 +172,9 @@ def test_service(base: BaseView) -> None:
must return service for repository
"""
repository_id = RepositoryId("i686", "repo")
base.request.app[WatcherKey] = {
base.request.app["watcher"] = {
repository_id: watcher
for watcher in base.request.app[WatcherKey].values()
for watcher in base.request.app["watcher"].values()
}
assert base.service(repository_id) == base.services[repository_id]

View File

@ -5,7 +5,6 @@ from pytest_mock import MockerFixture
from ahriman.models.user import User
from ahriman.models.user_access import UserAccess
from ahriman.web.keys import AuthKey
from ahriman.web.views.v1.user.login import LoginView
@ -46,7 +45,7 @@ async def test_get_redirect_to_oauth(client_with_oauth_auth: TestClient) -> None
"""
must redirect to OAuth service provider in case if no code is supplied
"""
oauth = client_with_oauth_auth.app[AuthKey]
oauth = client_with_oauth_auth.app["validator"]
oauth.get_oauth_url.return_value = "http://localhost"
request_schema = pytest.helpers.schema_request(LoginView.get, location="querystring")
@ -61,7 +60,7 @@ async def test_get_redirect_to_oauth_empty_code(client_with_oauth_auth: TestClie
"""
must redirect to OAuth service provider in case if empty code is supplied
"""
oauth = client_with_oauth_auth.app[AuthKey]
oauth = client_with_oauth_auth.app["validator"]
oauth.get_oauth_url.return_value = "http://localhost"
request_schema = pytest.helpers.schema_request(LoginView.get, location="querystring")
@ -76,7 +75,7 @@ async def test_get(client_with_oauth_auth: TestClient, mocker: MockerFixture) ->
"""
must log in user correctly from OAuth
"""
oauth = client_with_oauth_auth.app[AuthKey]
oauth = client_with_oauth_auth.app["validator"]
oauth.get_oauth_username.return_value = "user"
oauth.known_username.return_value = True
oauth.enabled = False # lol
@ -99,7 +98,7 @@ async def test_get_unauthorized(client_with_oauth_auth: TestClient, mocker: Mock
"""
must return unauthorized from OAuth
"""
oauth = client_with_oauth_auth.app[AuthKey]
oauth = client_with_oauth_auth.app["validator"]
oauth.known_username.return_value = False
oauth.max_age = 60
remember_mock = mocker.patch("aiohttp_security.remember")