-
Notifications
You must be signed in to change notification settings - Fork 7
Implement fetch method, to populate template data on incarnation creation #517
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
27bc023
60df3bd
f073ae9
749cf04
be34f80
7bf4b83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| from fastapi import APIRouter, Depends | ||
|
|
||
| from foxops.dependencies import get_template_service | ||
| from foxops.services.template import TemplateService | ||
|
|
||
| router = APIRouter(prefix="/api/templates", tags=["template"]) | ||
|
|
||
|
|
||
| @router.get("/variables") | ||
| async def get_template_variables( | ||
| template_repository: str, | ||
| template_version: str, | ||
| template_service: TemplateService = Depends(get_template_service), | ||
| ): | ||
| return await template_service.get_template_variables(template_repository, template_version) |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,13 @@ | ||||||
| from foxops.engine.models.template_config import TemplateConfig | ||||||
| from foxops.hosters import Hoster | ||||||
|
|
||||||
|
|
||||||
| class TemplateService: | ||||||
| def __init__(self, hoster: Hoster) -> None: | ||||||
| self.hoster = hoster | ||||||
|
|
||||||
| async def get_template_variables(self, template_repository: str, template_version: str) -> dict[str, str]: | ||||||
| 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()} | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just added a commit to this branch which added a |
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { api } from './api' | ||
|
|
||
| export const template = { | ||
| getDefaultVariables: async (templateRepository: string, templateVersion: string) => { | ||
| const data = await api.get<undefined, Record<string, string>>(`/templates/variables?template_repository=${templateRepository}&template_version=${templateVersion}`) | ||
| return data | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
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?