Skip to content

Commit

Permalink
Merge pull request #21 from jyejare/conf_optional
Browse files Browse the repository at this point in the history
Conf directiory as CLI option and more updates
  • Loading branch information
jyejare authored Jun 26, 2024
2 parents 4a783b9 + 8263bce commit d39ea9f
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
7 changes: 5 additions & 2 deletions candore/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,19 @@
@click.option("--version", is_flag=True, help="Installed version of candore")
@click.option("--settings-file", "-s", default=None, help="Settings file path")
@click.option("--components-file", "-c", default=None, help="Components file path")
@click.option("--conf-dir", default=None, help="Conf directory contain configuration files")
@click.pass_context
def candore(ctx, version, settings_file, components_file):
def candore(ctx, version, settings_file, components_file, conf_dir):
if version:
import pkg_resources

ver = pkg_resources.get_distribution("candore").version
click.echo(f"Version: {ver}")
candore_obj = Candore(
settings=candore_settings(
option_settings_file=settings_file, option_components_file=components_file
option_settings_file=settings_file,
option_components_file=components_file,
conf_dir=conf_dir
)
)
ctx.__dict__["candore"] = candore_obj
Expand Down
10 changes: 8 additions & 2 deletions candore/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
CURRENT_DIRECTORY = Path().resolve()


def candore_settings(option_settings_file=None, option_components_file=None):
def candore_settings(option_settings_file=None, option_components_file=None, conf_dir=None):
settings_file = (
PurePath(option_settings_file)
if option_settings_file
Expand All @@ -18,12 +18,18 @@ def candore_settings(option_settings_file=None, option_components_file=None):
if option_components_file
else PurePath(CURRENT_DIRECTORY, "components.yaml")
)
if conf_dir:
a_conf_dir = PurePath(conf_dir)
if not Path(a_conf_dir).exists():
raise OSError(f'The conf directory path {a_conf_dir} does not exists')
else:
a_conf_dir = PurePath('conf/')
# Initialize and Configure Settings
settings = Dynaconf(
core_loaders=["YAML"],
envvar_prefix="CANDORE",
settings_files=[settings_file, components_file],
preload=["conf/*.yaml"],
preload=[f"{a_conf_dir}/*.yaml"],
envless_mode=True,
lowercase_read=True,
)
Expand Down
2 changes: 1 addition & 1 deletion candore/modules/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ async def extract_all_entities(self):

async def extract_all_rpms(self):
"""Extracts all installed RPMs from server"""
with Session() as ssh_client:
with Session(settings=self.settings) as ssh_client:
rpms = ssh_client.execute('rpm -qa').stdout
rpms = rpms.splitlines()
name_version_pattern = rf'{self.settings.rpms.regex_pattern}'
Expand Down
8 changes: 4 additions & 4 deletions candore/modules/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

class Session:

def __init__(self):
self.settings = candore_settings()
self.hostname = urlparse(self.settings.candore.base_url).hostname
self.username = self.settings.candore.ssh.username or 'root'
def __init__(self, settings=None):
self.settings = settings
self.hostname = urlparse(settings.candore.base_url).hostname
self.username = settings.candore.ssh.username or 'root'

@cached_property
def auth(self):
Expand Down

0 comments on commit d39ea9f

Please sign in to comment.