mirror of
https://github.com/Garmelon/PFERD.git
synced 2023-12-21 10:23:01 +01:00
Add CLI option for credential file auth to kit-ilias-web
This commit is contained in:
parent
9d5ec84b91
commit
1ce32d2f18
@ -24,6 +24,7 @@ ambiguous situations.
|
|||||||
|
|
||||||
### Added
|
### Added
|
||||||
- `credential-file` authenticator
|
- `credential-file` authenticator
|
||||||
|
- `--credential-file` option for `kit-ilias-web` command
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Date parsing now also works correctly in non-group exercises
|
- Date parsing now also works correctly in non-group exercises
|
||||||
|
@ -5,7 +5,7 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from .cli import PARSER, load_default_section
|
from .cli import PARSER, ParserLoadError, load_default_section
|
||||||
from .config import Config, ConfigDumpError, ConfigLoadError, ConfigOptionError
|
from .config import Config, ConfigDumpError, ConfigLoadError, ConfigOptionError
|
||||||
from .logging import log
|
from .logging import log
|
||||||
from .pferd import Pferd, PferdLoadError
|
from .pferd import Pferd, PferdLoadError
|
||||||
@ -36,6 +36,9 @@ def load_config(args: argparse.Namespace) -> Config:
|
|||||||
log.error(str(e))
|
log.error(str(e))
|
||||||
log.error_contd(e.reason)
|
log.error_contd(e.reason)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
except ParserLoadError as e:
|
||||||
|
log.error(str(e))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def configure_logging_from_args(args: argparse.Namespace) -> None:
|
def configure_logging_from_args(args: argparse.Namespace) -> None:
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
# isort: skip_file
|
# isort: skip_file
|
||||||
|
|
||||||
# The order of imports matters because each command module registers itself
|
# The order of imports matters because each command module registers itself
|
||||||
# with the parser from ".parser". Because of this, isort is disabled for this
|
# with the parser from ".parser" and the import order affects the order in
|
||||||
|
# which they appear in the help. Because of this, isort is disabled for this
|
||||||
# file. Also, since we're reexporting or just using the side effect of
|
# file. Also, since we're reexporting or just using the side effect of
|
||||||
# importing itself, we get a few linting warnings, which we're disabling as
|
# importing itself, we get a few linting warnings, which we're disabling as
|
||||||
# well.
|
# well.
|
||||||
|
|
||||||
from . import command_local # noqa: F401 imported but unused
|
from . import command_local # noqa: F401 imported but unused
|
||||||
from . import command_kit_ilias_web # noqa: F401 imported but unused
|
from . import command_kit_ilias_web # noqa: F401 imported but unused
|
||||||
from .parser import PARSER, load_default_section # noqa: F401 imported but unused
|
from .parser import PARSER, ParserLoadError, load_default_section # noqa: F401 imported but unused
|
||||||
|
@ -4,7 +4,8 @@ from pathlib import Path
|
|||||||
|
|
||||||
from ..crawl.ilias.file_templates import Links
|
from ..crawl.ilias.file_templates import Links
|
||||||
from ..logging import log
|
from ..logging import log
|
||||||
from .parser import CRAWLER_PARSER, SUBPARSERS, BooleanOptionalAction, load_crawler, show_value_error
|
from .parser import (CRAWLER_PARSER, SUBPARSERS, BooleanOptionalAction, ParserLoadError, load_crawler,
|
||||||
|
show_value_error)
|
||||||
|
|
||||||
SUBPARSER = SUBPARSERS.add_parser(
|
SUBPARSER = SUBPARSERS.add_parser(
|
||||||
"kit-ilias-web",
|
"kit-ilias-web",
|
||||||
@ -38,6 +39,12 @@ GROUP.add_argument(
|
|||||||
action=BooleanOptionalAction,
|
action=BooleanOptionalAction,
|
||||||
help="use the system keyring to store and retrieve passwords"
|
help="use the system keyring to store and retrieve passwords"
|
||||||
)
|
)
|
||||||
|
GROUP.add_argument(
|
||||||
|
"--credential-file",
|
||||||
|
type=Path,
|
||||||
|
metavar="PATH",
|
||||||
|
help="read username and password from a credential file"
|
||||||
|
)
|
||||||
GROUP.add_argument(
|
GROUP.add_argument(
|
||||||
"--links",
|
"--links",
|
||||||
type=show_value_error(Links.from_string),
|
type=show_value_error(Links.from_string),
|
||||||
@ -88,11 +95,19 @@ def load(
|
|||||||
|
|
||||||
parser["auth:ilias"] = {}
|
parser["auth:ilias"] = {}
|
||||||
auth_section = parser["auth:ilias"]
|
auth_section = parser["auth:ilias"]
|
||||||
|
if args.credential_file is not None:
|
||||||
|
if args.username is not None:
|
||||||
|
raise ParserLoadError("--credential-file and --username can't be used together")
|
||||||
|
if args.keyring:
|
||||||
|
raise ParserLoadError("--credential-file and --keyring can't be used together")
|
||||||
|
auth_section["type"] = "credential-file"
|
||||||
|
auth_section["path"] = str(args.credential_file)
|
||||||
|
elif args.keyring:
|
||||||
|
auth_section["type"] = "keyring"
|
||||||
|
else:
|
||||||
auth_section["type"] = "simple"
|
auth_section["type"] = "simple"
|
||||||
if args.username is not None:
|
if args.username is not None:
|
||||||
auth_section["username"] = args.username
|
auth_section["username"] = args.username
|
||||||
if args.keyring:
|
|
||||||
auth_section["type"] = "keyring"
|
|
||||||
|
|
||||||
|
|
||||||
SUBPARSER.set_defaults(command=load)
|
SUBPARSER.set_defaults(command=load)
|
||||||
|
@ -8,6 +8,10 @@ from ..output_dir import OnConflict, Redownload
|
|||||||
from ..version import NAME, VERSION
|
from ..version import NAME, VERSION
|
||||||
|
|
||||||
|
|
||||||
|
class ParserLoadError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# TODO Replace with argparse version when updating to 3.9?
|
# TODO Replace with argparse version when updating to 3.9?
|
||||||
class BooleanOptionalAction(argparse.Action):
|
class BooleanOptionalAction(argparse.Action):
|
||||||
def __init__(
|
def __init__(
|
||||||
|
Loading…
Reference in New Issue
Block a user