byceps.cli.commands.import_roles   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 42
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0
wmc 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
A _import_roles() 0 6 1
A import_roles() 0 12 1
1
"""
2
byceps.cli.command.import_roles
3
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
4
5
Import roles and their assigned permissions from a TOML file.
6
7
:Copyright: 2014-2024 Jochen Kupperschmidt
8
:License: Revised BSD (see `LICENSE` file for details)
9
"""
10
11
from pathlib import Path
12
13
import click
14
from flask.cli import with_appcontext
15
16
from byceps.services.authz import impex_service
17
18
19
_DEFAULT_DATA_FILE = Path('scripts') / 'data' / 'roles.toml'
20
21
22
@click.command()
23
@click.option(
24
    '-f',
25
    '--file',
26
    'data_file',
27
    type=click.Path(exists=True, dir_okay=False, path_type=Path),
28
    default=_DEFAULT_DATA_FILE,
29
)
30
@with_appcontext
31
def import_roles(data_file: Path) -> None:
32
    """Import authorization roles."""
33
    _import_roles(data_file)
34
35
36
def _import_roles(data_file: Path) -> None:
37
    click.echo('Importing roles ... ', nl=False)
38
    role_counts = impex_service.import_roles(data_file)
39
    click.secho('done. ', fg='green', nl=False)
40
    click.secho(
41
        f'Imported {role_counts.imported} roles, '
42
        f'skipped {role_counts.skipped} roles.',
43
    )
44