Skip to content
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

Support nested manifests and relative paths #216

Merged
merged 1 commit into from Aug 1, 2022
Merged

Conversation

roekatz
Copy link
Contributor

@roekatz roekatz commented Feb 24, 2022

No description provided.

packages/opal-common/opal_common/git/bundle_maker.py Outdated Show resolved Hide resolved
packages/opal-common/opal_common/git/bundle_maker.py Outdated Show resolved Hide resolved
packages/opal-common/opal_common/git/bundle_maker.py Outdated Show resolved Hide resolved
# Path is relative to current directory, make it absolute
path_entry = dir.path / path_entry
if not viewer.exists(path_entry):
logger.warning(f"Path '{path_entry}' does not exist")
Copy link
Contributor

Choose a reason for hiding this comment

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

These log entries will become hard to understand/debug if we're dealing with a large, complex set of deeply-nested manifests. It would be better if it included the full path of how we got here, from the root manifest.

packages/opal-common/opal_common/git/bundle_maker.py Outdated Show resolved Hide resolved
packages/opal-common/opal_common/git/commit_viewer.py Outdated Show resolved Hide resolved
"""
filterable_gen = filterable_gen or self.nodes
path = Path(path) # Works even if path is already Path
nodes = filterable_gen(lambda n: n.path == path)
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like itertools.filterfalse will help you here -- maybe it can replace this whole method.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how filterfalse would help me, but filter actually helps.
My code there was unnecessarily complex - I've fixed it and I believe it's much more readable now (with a small price of having a slightly duplicated [line of] code - but I think it's justifiable)

packages/opal-common/opal_common/git/commit_viewer.py Outdated Show resolved Hide resolved
repo: Repo = local_repo
root = Path(repo.working_tree_dir)

# Create multiple recursive .manifest files
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is great, but we also need some tests for failure cases. What happens when a manifest points to another manifest that doesn't exist? What if the manifest is binary instead of utf-8 text? What if the manifest is a symbolic link? What if we have a manifest cycle?

repo: Repo = local_repo
root = Path(repo.working_tree_dir)

# Create multiple recursive .manifest files
Copy link
Contributor

Choose a reason for hiding this comment

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

This test is great, but we also need some tests for failure cases. What happens when a manifest points to another manifest that doesn't exist? What if the manifest is binary instead of utf-8 text? What if the manifest is a symbolic link? What if we have a manifest cycle?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Points to another manifest that doesn't exist - That's actually tested now (pointing to 'some' dir which is empty)
  2. Manifest cycle - That's not really possible because paths are always interpreted relatively to .manifest's dir. But I'm adding a test for that with multiple hacking attempts (including "..").
  3. Binary/utf-8 - I've just added a test for testing my own changes, if that's an issue than it's not new. I'll see if it's easy to add one.
  4. Symbolic link - Same point as 3.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

More about symlinks:
I would say symlinks are probably fine if they point inside the repo.
If they point outside it is problematic.
We probably want to ignore symlinks altogether, just to be sure.
Also pay attention that the .manifest only generates the list by which the bundle files are sorted,
the main danger are data.json / *.rego symlinks pointing outside the repo (which can be used to fetch arbitrary files from server).

I'll check if that's an issue - and open a ticket for it if so (since that's outside the scope of that PR anyway)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. in second thought the file always holds binary data. When using textual mode in python ("r" rather than "rb") it uses utf-8 by default to decode them.
    If someone would use a different encoding for his manifest file - it would be equivalent of having non existing paths within the manifest.
    But I feel like expecting "utf-8" is totally expected... What exactly do you think the behavior should be?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I haven't been able to use our current Repo object in order to commit symlinks (gave it 2 minutes). I've opened a ticket in linear for making sure we don't handle symlinks. Other than that I feel like that's a bit out of scope for merging this PR :)

@roekatz roekatz force-pushed the rk/enhance_manifests branch 5 times, most recently from fe24faf to 4f9da4d Compare July 26, 2022 15:02
Copy link
Contributor

@singingwolfboy singingwolfboy left a comment

Choose a reason for hiding this comment

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

One minor suggestion, but otherwise this looks ready to go!

packages/opal-common/opal_common/git/commit_viewer.py Outdated Show resolved Hide resolved
Nested menifests: minor CR fix

Co-authored-by: David Baumgold <db@permit.io>
@roekatz roekatz merged commit 739501d into master Aug 1, 2022
@roekatz roekatz deleted the rk/enhance_manifests branch August 1, 2022 13:26
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.

Manifest file should include relative paths rather than absolute Support nested manifest files
2 participants