-
Notifications
You must be signed in to change notification settings - Fork 6
Add infrahubctl menu load
command to load menu items from a file
#73
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
Conversation
a6103f9
to
356bfb2
Compare
Codecov ReportAttention: Patch coverage is
@@ Coverage Diff @@
## develop #73 +/- ##
==========================================
Coverage ? 43.30%
==========================================
Files ? 74
Lines ? 6844
Branches ? 1353
==========================================
Hits ? 2964
Misses ? 3611
Partials ? 269
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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.
LGTM. Added some comments which is mostly me just thinking out loud.
infrahub_sdk/ctl/object.py
Outdated
for file in files: | ||
file.validate_content() | ||
if not file.spec.kind: | ||
raise FileNotValidError(name=str(file.location), message="kind must be specified.") |
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 have this happen within .validate_content() instead?
return data | ||
|
||
@classmethod | ||
async def create_node( |
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.
In what way has this been used? I think it might be fine to create the menu but I'm wondering if we need to rethink the structure for other object types where the object we create is related to other objects. If those objects doesn't yet exist I think we'd need to create them first before creating the "base" object. Should be doable by looking at the relationships and which side if any is mandatory. Though it would also be nice if we could just feed everything to the backend as a "fix this in a single transaction" type of way. Not a blocker here and it could be that I don't completely understand how this gets used but I see some situations where it seems problematic now depending on how the relationships are defined.
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.
Yes I fully agree, this is not the final implementation
My end goal is to be able to create all these objects in memory and to have a engine that will know in which order they need to be created based on the schema.
This is very similar to what we need to build better generators.
_spec: Optional[InfrahubObjectFileData] = None | ||
|
||
@property | ||
def spec(self) -> InfrahubObjectFileData: |
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.
Just thinking out loud here if we're later adding a spec property to other object types and want to look at the spec for a generic InfrahubFile
object it might get problematic if we always need to override the returned data in a different way for each given subclass (in this case ObjectFile
which would return an InfrahubObjectFileData
. Depending on what we do in the future it might not be a problem, alternatively we could look at generics and see if we could fix it with that.
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.
Agreed, not a fan of this implementation as well, happy to consider a better/cleaner solution in the future
pass | ||
|
||
@classmethod | ||
def load_from_disk(cls, paths: list[Path]) -> list[Self]: |
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.
We currently read most of the data from disk as a sync function, i.e. the jinja2 templates when used from within the git-agent and also even the loading of .infrahub.yml files. I see this being used within the git-agents as well. Even though we don't have the file loaders as async now I'm wondering if this should be an async function from the start, or if we just introduce a new one that is async once we actually read the files from disk in an async way.
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.
Since it's sync for now, my vote is to keep it as a sync function but it would be good to start using anyio.Path
to properly support Async for all disk access. I'll open an issue to track that
This PR adds a new cli command
infrahubctl menu load
to load menu items from one or multiple filesThe menu file need to have the following format.
in Summary
data
must be compatible withCoreMenuItem
kind
is provided, the path will be automatically generated to/objects/<kind>
More than just the menu
Because, it felt silly to create yet another specific command for the menu, I tried to make it as generic as possible.
With a tiny difference, this format should work for all type of objects in the near future.
I've also added the command
infrahubctl object load
(hidden for now) to explore this feature.I was able to successfully load this file with
location
data but more work is required to properly support all types of relationships