Skip to content

ark_action

ArkAction

Bases: ABC

Source code in ark_sdk_python/actions/ark_action.py
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
class ArkAction(ABC):
    def __init__(self):
        self._logger = get_logger(app=self.__class__.__name__)

    def _common_actions_configuration(self, parser: argparse.ArgumentParser) -> None:
        parser.add_argument('-r', '--raw', action='store_true', help='Whether to raw output')
        parser.add_argument('-s', '--silent', action='store_true', help='Silent execution, no interactiveness')
        parser.add_argument('-ao', '--allow-output', action='store_true', help='Allow stdout / stderr even when silent and not interactive')
        parser.add_argument('-v', '--verbose', action='store_true', help='Whether to verbose log')
        parser.add_argument('-ls', '--logger-style', choices=['default'], help='Which verbose logger style to use', default='default')
        parser.add_argument(
            '-ll',
            '--log-level',
            help='Log level to use while verbose',
            choices=['DEBUG', 'INFO', 'WARN', 'ERROR', 'CRITICAL'],
            default='INFO',
        )
        parser.add_argument(
            '-dcv', '--disable-cert-verification', action='store_true', help='Disables certificate verification on HTTPS calls, unsafe!'
        )
        parser.add_argument('-tc', '--trusted-cert', help='Certificate to use for HTTPS calls')

    def _common_actions_execution(self, args: argparse.Namespace) -> None:
        ArkSystemConfig.enable_color()
        ArkSystemConfig.enable_interactive()
        ArkSystemConfig.disable_verbose_logging()
        ArkSystemConfig.disallow_output()
        ArkSystemConfig.set_logger_style(args.logger_style)
        ArkSystemConfig.enable_certificate_verification()
        if args.raw:
            ArkSystemConfig.disable_color()
        if args.silent:
            ArkSystemConfig.disable_interactive()
        if args.verbose:
            ArkSystemConfig.enable_verbose_logging(args.log_level)
        if args.allow_output:
            ArkSystemConfig.allow_output()
        if args.disable_cert_verification:
            ArkSystemConfig.disable_certificate_verification()
        elif args.trusted_cert is not None:
            ArkSystemConfig.set_trusted_certificate(args.trusted_cert)
        self._logger = get_logger(app=self.__class__.__name__)
        if 'profile-name' in args:
            args.profile_name = ArkProfileLoader.deduce_profile_name(args.profile_name)
        if 'DEPLOY_ENV' not in os.environ:
            # Last fallback on deploy env
            os.environ['DEPLOY_ENV'] = 'prod'

    @abstractmethod
    def define_action(self, subparsers: argparse._SubParsersAction) -> None:
        """
        Defines the action as part of the specified subparsers group.

        Args:
            subparsers (argparse._SubParsersAction): _description_
        """

    @abstractmethod
    def run_action(self, args: argparse.Namespace) -> None:
        """
        Runs the actual action with the given arguments.

        Args:
            args (argparse.Namespace): _description_
        """

    @abstractmethod
    def can_run_action(self, action_name: str, args: argparse.Namespace) -> bool:
        """
        Checks whether the given action can be run with the specified arguments.

        Args:
            action_name (str): _description_
            args (argparse.Namespace): _description_

        Returns:
            bool: _description_
        """

can_run_action(action_name, args) abstractmethod

Checks whether the given action can be run with the specified arguments.

Parameters:

Name Type Description Default
action_name str

description

required
args Namespace

description

required

Returns:

Name Type Description
bool bool

description

Source code in ark_sdk_python/actions/ark_action.py
75
76
77
78
79
80
81
82
83
84
85
86
@abstractmethod
def can_run_action(self, action_name: str, args: argparse.Namespace) -> bool:
    """
    Checks whether the given action can be run with the specified arguments.

    Args:
        action_name (str): _description_
        args (argparse.Namespace): _description_

    Returns:
        bool: _description_
    """

define_action(subparsers) abstractmethod

Defines the action as part of the specified subparsers group.

Parameters:

Name Type Description Default
subparsers _SubParsersAction

description

required
Source code in ark_sdk_python/actions/ark_action.py
57
58
59
60
61
62
63
64
@abstractmethod
def define_action(self, subparsers: argparse._SubParsersAction) -> None:
    """
    Defines the action as part of the specified subparsers group.

    Args:
        subparsers (argparse._SubParsersAction): _description_
    """

run_action(args) abstractmethod

Runs the actual action with the given arguments.

Parameters:

Name Type Description Default
args Namespace

description

required
Source code in ark_sdk_python/actions/ark_action.py
66
67
68
69
70
71
72
73
@abstractmethod
def run_action(self, args: argparse.Namespace) -> None:
    """
    Runs the actual action with the given arguments.

    Args:
        args (argparse.Namespace): _description_
    """