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

feat: use MkdirAll by OS(#19301) #19323

Merged
merged 8 commits into from
Aug 4, 2024

Conversation

thisishwan2
Copy link
Contributor

Hello. This is a PR for issue #19301

I created an implementation to run MkdirAll by os. And I abstracted it. In hydratorhelper, I modified it to use an implementation that fits os.
Please let me know if there is anything wrong!

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Toolchain Guide
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

@thisishwan2 thisishwan2 requested a review from a team as a code owner July 31, 2024 17:45

// MkdirAllProvider is an interface for creating directories.
type MkdirAllProvider interface {
MkdirAll(path string, perm os.FileMode) error
Copy link
Member

Choose a reason for hiding this comment

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

I think the interface we need is func MkdirAll(root, unsafePath string, mode int) error. The Linux implementation will just pass through the args to securejoin.MkdirAll. The non-Linux implementation will run securejoin.SecureJoin(root, unsafePath) and then run os.MkdirAll.

Copy link
Contributor Author

@thisishwan2 thisishwan2 Jul 31, 2024

Choose a reason for hiding this comment

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

Is it correct to change the part mentioned in the issue as follows??

before

fullHydratePath, err = securejoin.SecureJoin(h.dirPath, hydratePath) 
 if err != nil { 
 	return fmt.Errorf("failed to construct hydrate path: %w", err) 
 } 
 // TODO: consider switching to securejoin.MkdirAll: https://github.com/cyphar/filepath-securejoin?tab=readme-ov-file#mkdirall 
 err = os.MkdirAll(fullHydratePath, os.ModePerm) 

after

err = MkdirAll(rootPath, hydratePath, os.ModePerm)

@thisishwan2 thisishwan2 requested a review from a team as a code owner August 1, 2024 03:37
@thisishwan2
Copy link
Contributor Author

@crenshaw-dev As you said, I modified the implementation.
securejoin.MkdirAll(in linux) and securejoin.securejoin (root, issuePath) and os.MkdirAll(in default) are implemented in their respective implementations
To use the fullHydratePath variable in future codes,
fullHydratePath, err = mkdirAllProvider.MkdirAll (rootPath, hydratePath, os.ModePerm) Modified hydratorhelper.go code in form.

Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

This looks nearly perfect! A few requests:

  1. Can we eliminate the structs and just have a plain function called SecureMkdirAll? I tried locally, looks like the struct isn't necessary.
  2. Can you add super basic unit tests for both implementations?

@thisishwan2
Copy link
Contributor Author

Great!
I think it's unnecessary to erase the interface mkdir_provider.go while erasing the structure, so I'll erase it together.

Signed-off-by: Michael Crenshaw <[email protected]>
Copy link
Member

@crenshaw-dev crenshaw-dev left a comment

Choose a reason for hiding this comment

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

Thank you!!

@crenshaw-dev crenshaw-dev merged commit c7cf4bb into argoproj:hydrator Aug 4, 2024
5 of 8 checks passed
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.

2 participants