Skip to content

Commit

Permalink
Use dict for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Shrews committed Sep 26, 2024
1 parent 42ea623 commit 8d072b2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 58 deletions.
60 changes: 26 additions & 34 deletions src/ansible_runner/config/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,6 @@ class BaseExecutionMode(Enum):
GENERIC_COMMANDS = 2


@dataclass
class _ArgField(dict):
required: bool = True

def __getattr__(self, attr):
return self[attr]


@dataclass
class BaseConfig:

Expand All @@ -78,32 +70,32 @@ class BaseConfig:
# No other config objects make use of positional parameters, so this should be fine.
#
# Example use case: RunnerConfig("/tmp/demo", playbook="main.yml", ...)
private_data_dir: str | None = field(metadata=_ArgField(), default=None)

artifact_dir: str | None = field(metadata=_ArgField(), default=None)
check_job_event_data: bool = field(metadata=_ArgField(), default=False)
container_auth_data: dict[str, str] | None = field(metadata=_ArgField(), default=None)
container_image: str = field(metadata=_ArgField(), default="")
container_options: list[str] | None = field(metadata=_ArgField(), default=None)
container_volume_mounts: list[str] | None = field(metadata=_ArgField(), default=None)
container_workdir: str | None = field(metadata=_ArgField(), default=None)
envvars: dict[str, Any] | None = field(metadata=_ArgField(), default=None)
fact_cache: str | None = field(metadata=_ArgField(), default=None)
fact_cache_type: str = field(metadata=_ArgField(), default='jsonfile')
host_cwd: str | None = field(metadata=_ArgField(), default=None)
ident: str | None = field(metadata=_ArgField(), default=None)
json_mode: bool = field(metadata=_ArgField(), default=False)
keepalive_seconds: int | None = field(metadata=_ArgField(), default=None)
passwords: dict[str, str] | None = field(metadata=_ArgField(), default=None)
process_isolation: bool = field(metadata=_ArgField(), default=False)
process_isolation_executable: str = field(metadata=_ArgField(), default=defaults.default_process_isolation_executable)
project_dir: str | None = field(metadata=_ArgField(), default=None)
quiet: bool = field(metadata=_ArgField(), default=False)
rotate_artifacts: int = field(metadata=_ArgField(), default=0)
settings: dict | None = field(metadata=_ArgField(), default=None)
ssh_key: str | None = field(metadata=_ArgField(), default=None)
suppress_env_files: bool = field(metadata=_ArgField(), default=False)
timeout: int | None = field(metadata=_ArgField(), default=None)
private_data_dir: str | None = field(metadata={}, default=None)

artifact_dir: str | None = field(metadata={}, default=None)
check_job_event_data: bool = field(metadata={}, default=False)
container_auth_data: dict[str, str] | None = field(metadata={}, default=None)
container_image: str = field(metadata={}, default="")
container_options: list[str] | None = field(metadata={}, default=None)
container_volume_mounts: list[str] | None = field(metadata={}, default=None)
container_workdir: str | None = field(metadata={}, default=None)
envvars: dict[str, Any] | None = field(metadata={}, default=None)
fact_cache: str | None = field(metadata={}, default=None)
fact_cache_type: str = field(metadata={}, default='jsonfile')
host_cwd: str | None = field(metadata={}, default=None)
ident: str | None = field(metadata={}, default=None)
json_mode: bool = field(metadata={}, default=False)
keepalive_seconds: int | None = field(metadata={}, default=None)
passwords: dict[str, str] | None = field(metadata={}, default=None)
process_isolation: bool = field(metadata={}, default=False)
process_isolation_executable: str = field(metadata={}, default=defaults.default_process_isolation_executable)
project_dir: str | None = field(metadata={}, default=None)
quiet: bool = field(metadata={}, default=False)
rotate_artifacts: int = field(metadata={}, default=0)
settings: dict | None = field(metadata={}, default=None)
ssh_key: str | None = field(metadata={}, default=None)
suppress_env_files: bool = field(metadata={}, default=False)
timeout: int | None = field(metadata={}, default=None)

_CONTAINER_ENGINES = ('docker', 'podman')

Expand Down
48 changes: 24 additions & 24 deletions src/ansible_runner/config/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from dataclasses import dataclass, field

from ansible_runner import output
from ansible_runner.config._base import _ArgField, BaseConfig, BaseExecutionMode
from ansible_runner.config._base import BaseConfig, BaseExecutionMode
from ansible_runner.exceptions import ConfigurationError
from ansible_runner.output import debug
from ansible_runner.utils import register_for_cleanup
Expand Down Expand Up @@ -67,29 +67,29 @@ class RunnerConfig(BaseConfig):
"""

# 'binary' comes from the --binary CLI opt for an alternative ansible command path
binary: str | None = field(metadata=_ArgField(), default=None)
cmdline: str | None = field(metadata=_ArgField(), default=None)
directory_isolation_base_path: str | None = field(metadata=_ArgField(), default=None)
extravars: dict | None = field(metadata=_ArgField(), default=None)
forks: int | None = field(metadata=_ArgField(), default=None)
host_pattern: str | None = field(metadata=_ArgField(), default=None)
inventory: str | dict | list | None = field(metadata=_ArgField(), default=None)
limit: str | None = field(metadata=_ArgField(), default=None)
module: str | None = field(metadata=_ArgField(), default=None)
module_args: str | None = field(metadata=_ArgField(), default=None)
omit_event_data: bool = field(metadata=_ArgField(), default=False)
only_failed_event_data: bool = field(metadata=_ArgField(), default=False)
playbook: str | None = field(metadata=_ArgField(), default=None)
process_isolation_hide_paths: str | list | None = field(metadata=_ArgField(), default=None)
process_isolation_ro_paths: str | list | None = field(metadata=_ArgField(), default=None)
process_isolation_show_paths: str | list | None = field(metadata=_ArgField(), default=None)
process_isolation_path: str | None = field(metadata=_ArgField(), default=None)
roles_path: str | None = field(metadata=_ArgField(), default=None)
skip_tags: str | None = field(metadata=_ArgField(), default=None)
suppress_ansible_output: bool = field(metadata=_ArgField(), default=False)
suppress_output_file: bool = field(metadata=_ArgField(), default=False)
tags: str | None = field(metadata=_ArgField(), default=None)
verbosity: int | None = field(metadata=_ArgField(), default=None)
binary: str | None = field(metadata={}, default=None)
cmdline: str | None = field(metadata={}, default=None)
directory_isolation_base_path: str | None = field(metadata={}, default=None)
extravars: dict | None = field(metadata={}, default=None)
forks: int | None = field(metadata={}, default=None)
host_pattern: str | None = field(metadata={}, default=None)
inventory: str | dict | list | None = field(metadata={}, default=None)
limit: str | None = field(metadata={}, default=None)
module: str | None = field(metadata={}, default=None)
module_args: str | None = field(metadata={}, default=None)
omit_event_data: bool = field(metadata={}, default=False)
only_failed_event_data: bool = field(metadata={}, default=False)
playbook: str | None = field(metadata={}, default=None)
process_isolation_hide_paths: str | list | None = field(metadata={}, default=None)
process_isolation_ro_paths: str | list | None = field(metadata={}, default=None)
process_isolation_show_paths: str | list | None = field(metadata={}, default=None)
process_isolation_path: str | None = field(metadata={}, default=None)
roles_path: str | None = field(metadata={}, default=None)
skip_tags: str | None = field(metadata={}, default=None)
suppress_ansible_output: bool = field(metadata={}, default=False)
suppress_output_file: bool = field(metadata={}, default=False)
tags: str | None = field(metadata={}, default=None)
verbosity: int | None = field(metadata={}, default=None)

def __post_init__(self) -> None:
# NOTE: Cannot call base class __init__() here as that causes some recursion madness.
Expand Down

0 comments on commit 8d072b2

Please sign in to comment.