Skip to content

Commit

Permalink
Add some sanity checking to the detected galaxy.yml file
Browse files Browse the repository at this point in the history
  • Loading branch information
Qalthos committed Dec 13, 2024
1 parent 4a60f6d commit 236e4b4
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/molecule/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import warnings

from pathlib import Path
from typing import TYPE_CHECKING, cast
from typing import TYPE_CHECKING
from uuid import uuid4

from ansible_compat.ports import cache, cached_property
Expand All @@ -38,7 +38,6 @@
from molecule.dependency import ansible_galaxy, shell
from molecule.model import schema_v3
from molecule.provisioner import ansible
from molecule.types import CollectionData
from molecule.util import boolean


Expand All @@ -49,7 +48,7 @@
from molecule.dependency.base import Base as Dependency
from molecule.driver.base import Driver
from molecule.state import State
from molecule.types import CommandArgs, ConfigData, MoleculeArgs
from molecule.types import CollectionData, CommandArgs, ConfigData, MoleculeArgs
from molecule.verifier.base import Verifier


Expand Down Expand Up @@ -270,12 +269,23 @@ def collection(self) -> CollectionData | None:
Returns:
A dictionary of information about the collection molecule is running inside, if any.
"""
if not self.collection_directory:
collection_directory = self.collection_directory
if not collection_directory:
return None

galaxy_file = self.collection_directory / "galaxy.yml"
galaxy_data = util.safe_load_file(galaxy_file)
return cast(CollectionData, galaxy_data)
galaxy_file = collection_directory / "galaxy.yml"
galaxy_data: CollectionData = util.safe_load_file(galaxy_file)

important_keys = {"name", "namespace"}
if missing_keys := important_keys.difference(galaxy_data.keys()):
LOG.warning(

Check warning on line 281 in src/molecule/config.py

View check run for this annotation

Codecov / codecov/patch

src/molecule/config.py#L281

Added line #L281 was not covered by tests
"The detected galaxy.yml file (%s) is incomplete, missing %s",
galaxy_file,
missing_keys,
)
return None

Check warning on line 286 in src/molecule/config.py

View check run for this annotation

Codecov / codecov/patch

src/molecule/config.py#L286

Added line #L286 was not covered by tests

return galaxy_data

@cached_property
def dependency(self) -> Dependency | None:
Expand Down

0 comments on commit 236e4b4

Please sign in to comment.