Skip to content

Conversation

@Yanni8
Copy link
Contributor

@Yanni8 Yanni8 commented Mar 12, 2025

No description provided.

@Yanni8 Yanni8 requested a review from defreng as a code owner March 12, 2025 15:52
@Yanni8 Yanni8 changed the title Add first version of template data fetch Implement fetch method, to populate template data on incarnation creation Mar 12, 2025
@Yanni8 Yanni8 self-assigned this Mar 12, 2025
@defreng defreng requested a review from TheEnzoMar March 14, 2025 16:41
def __init__(self, hoster: Hoster) -> None:
self.hoster = hoster

async def get_template_variables(self, template_repository: str, template_version: str) -> dict[str, str]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add some automated tests around this?

async with self.hoster.cloned_repository(template_repository, refspec=template_version) as repo:
template_config = TemplateConfig.from_path(repo.directory / "fengine.yaml")

return {k: v.get("default", "") for k, v in template_config.model_dump().get("variables", {}).items()}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the casting into a dict? We can have better type safety in the code by just doing

Suggested change
return {k: v.get("default", "") for k, v in template_config.model_dump().get("variables", {}).items()}
return {k: v.get("default", "") for k, v in template_config.variables.items()}

but then, also we have to be aware here that variables can be nested, complex objects. So this logic would have to be more recursive.

I would recommend adding functionality into the *VariableDefinition classes for getting an empty "example object" of that variable. This should then be easy to combine "up the tree" to ultimately get an "empty example" of a full template config.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just added a commit to this branch which added a mock_data() method on the TemplateConfig object - including a test for it :-) check it out!

defreng added 2 commits March 14, 2025 18:19
... to obtain an object with example values filled
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants