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

VAULT-25848 replace mholt/archiver with native go calls #27228

Merged
merged 9 commits into from
May 27, 2024

Conversation

VioletHynes
Copy link
Contributor

@VioletHynes VioletHynes commented May 24, 2024

This removes the mholt/archiver dependency, and replaces it in the only place where it's used (debug) with native Go calls instead. This passed with the old and new tests.

As far as I can tell, everything works the same. I've added the backport labels as I think I'll need to backport this due to this dependency being flagged as having a vulnerability.

@github-actions github-actions bot added the hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed label May 24, 2024
}

// We set ignoreUnexpectedHeaders to true as replication_status.json is only sometimes
// produced. Relying on it being or not being there wuld be racy.
Copy link
Contributor Author

@VioletHynes VioletHynes May 24, 2024

Choose a reason for hiding this comment

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

Note that this was true both before and after my change. In other words, if you add the new test code with the old production code, it still exhibits this behaviour. I'm not entirely sure why, but I'm glad it's consistent, at least. Sometimes it's there, sometimes it's not.

Copy link

github-actions bot commented May 24, 2024

CI Results:
All Go tests succeeded! ✅

@VioletHynes VioletHynes marked this pull request as ready for review May 24, 2024 18:12
@@ -374,7 +375,7 @@ func (c *DebugCommand) generateIndex() error {
}

// Write out file
if err := ioutil.WriteFile(filepath.Join(c.flagOutput, "index.json"), bytes, 0o600); err != nil {
if err := os.WriteFile(filepath.Join(c.flagOutput, "index.json"), bytes, 0o600); err != nil {

Choose a reason for hiding this comment

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

😸

command/debug.go Outdated
}

// addFileToTar takes a file at filePath and adds it to the tar
// being written to by tarWriter, alongside its header. T

Choose a reason for hiding this comment

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

Suggested change
// being written to by tarWriter, alongside its header. T
// being written to by tarWriter, alongside its header.

Choose a reason for hiding this comment

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

BTW lovely comments 😎

command/debug.go Outdated
func addFileToTar(sourceDir, filePath string, tarWriter *tar.Writer) error {
file, err := os.Open(filePath)
if err != nil {
return fmt.Errorf("failed to open file %q: %s", filePath, err)
Copy link

@peteski22 peteski22 May 24, 2024

Choose a reason for hiding this comment

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

Is it worth using %w for the err in these fmt.Errorf calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I can tell, %v and %s should be equivalent for errs -- is there a reason you think %v might be preferred?

Choose a reason for hiding this comment

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

Sorry, I mean't %w but went and confusingly typed %v.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, good shout. I always forget about that one since it only sometimes works (only for Errorf). Definitely should be used here. Will update!

Copy link

github-actions bot commented May 24, 2024

Build Results:
All builds succeeded! ✅

command/debug_test.go Outdated Show resolved Hide resolved
Copy link

@peteski22 peteski22 left a comment

Choose a reason for hiding this comment

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

Very nice! That's the way to show the outdated dependency who's boss. 😄

❓ is there ever a case in archiveToTgz where we error and would need to clean up a file we'd already created?

....ziiiiiip

@VioletHynes VioletHynes merged commit 44673eb into main May 27, 2024
83 checks passed
@VioletHynes VioletHynes deleted the violethynes/VAULT-25848 branch May 27, 2024 20:28
VioletHynes added a commit that referenced this pull request May 28, 2024
* VAULT-25848 update product code to remove mholt/archiver dependency

* VAULT-25848 replace tests, still WIP while I figure out if there's a bug caught by TestDebugCommand_PartialPermissions

* VAULT-25848 actually remove the dep

* VAULT-25848 add headers for directories, improve test

* Comment cleanup

* Typo

* Use %w

* Typo
VioletHynes added a commit that referenced this pull request Jun 3, 2024
)

* VAULT-25848 update product code to remove mholt/archiver dependency

* VAULT-25848 replace tests, still WIP while I figure out if there's a bug caught by TestDebugCommand_PartialPermissions

* VAULT-25848 actually remove the dep

* VAULT-25848 add headers for directories, improve test

* Comment cleanup

* Typo

* Use %w

* Typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/ent/1.15.x+ent Changes are backported to 1.15.x+ent backport/1.17.x hashicorp-contributed-pr If the PR is HashiCorp (i.e. not-community) contributed pr/no-changelog pr/no-milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants