-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Add flag to follow symlinks when running opa build #6800
Add flag to follow symlinks when running opa build #6800
Conversation
32341ef
to
5de7d4b
Compare
✅ Deploy Preview for openpolicyagent ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
b58f28c
to
6ee5e4c
Compare
✅ Deploy Preview for openpolicyagent ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
8329087
to
6bd3b39
Compare
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.
Thank you! 😃
Just a couple of comments/questions.
loader/loader.go
Outdated
} | ||
|
||
// GetBundleDirectoryLoaderFS returns a bundle directory loader which can be used to load | ||
// files in the directory. | ||
func GetBundleDirectoryLoaderFS(fsys fs.FS, path string, filter Filter) (bundle.DirectoryLoader, bool, error) { | ||
func GetBundleDirectoryLoaderFS(fsys fs.FS, path string, filter Filter, followSymlinks bool) (bundle.DirectoryLoader, bool, error) { |
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.
This will be a breaking change for anyone using this public function directly, although probably unlikely. Given that we also add WithFollowSymlinks()
, couldn't callers simply use that on the returned value instead?
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.
great idea! I didn't think about the library usecase.
loader/loader.go
Outdated
@@ -188,6 +190,12 @@ func (fl *fileLoader) WithRegoVersion(version ast.RegoVersion) FileLoader { | |||
return fl | |||
} | |||
|
|||
// WithFollowSymLinks enables or disables following symlinks when loading files |
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.
// WithFollowSymLinks enables or disables following symlinks when loading files | |
// WithFollowSymlinks enables or disables following symlinks when loading files |
|
||
params := newBuildParams() | ||
params.outputFile = path.Join(rootDir, "test.tar.gz") | ||
params.bundleMode = true |
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 drop This? Reading in bundle-mode doesn't seem like a requirement.
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.
👍
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.
Hm, I think I might have lead you astray with this coment 🤔 .
If I add params.bundleMode = true
here, the test starts to fail.
But if I also add params.followSymlinks = true
, it succeeds again, clearly showing that your code is being exercised.
So we need to add
params.bundleMode = true
params.followSymlinks = true
@johanfylling thanks for the review! sorry it took me a while to respond to your feedback... I think I have it all covered here! Let me know if anything else is needed before I squash all this :) |
✅ Deploy Preview for openpolicyagent ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
a84fabf
to
568dc5d
Compare
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.
Thank you for the updates 🙂.
I think I misread the bundle-mode angle before.
Your tests look good, but it doesn't look like they're actually enabling params.followSymlinks = true
, so they're showing this is a current feature for non-bundle-mode builds. If we add params.bundleMode = true
to the tests, they start failing; and then adding params.followSymlinks = true
, TestBuildWithFollowSymlinks
will start succeeding again, showing that the your changes are necessary 👍 . The TestBuildWithFollowSymlinksEntireDir
test will keep failing, however.
568dc5d
to
cb2de1f
Compare
…undles Signed-off-by: Tyler Schade <[email protected]>
cb2de1f
to
3496456
Compare
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.
Great job! Thank you 😃
Why the changes in this PR are needed?
Per #6495, it is important to users using build systems like babel to allow
opa build
to include symlinked files in the bundle directory. Bazel and other build tools create sandboxes of symlinked files before building. As it stands today,opa build
only includes regular files and directories by default.What are the changes in this PR?
This PR adds a boolean flag,
--follow-symlinks
to theopa build
command to allow users to build directories with symlinked files, and have the contents of those symlinked files included in the built bundle.Notes to assist PR review:
I've included tests for the build command but would appreciate a critical eye as to any other areas that could use testing. Also, I've kept the symlink changes as constrained to the
build
features as possible, but there are many layers of method calls to get to the core filesystem loading logic, so any ideas for cleaning up this code is welcome.Further comments: