-
Notifications
You must be signed in to change notification settings - Fork 171
Feature/allow remote href blobs #683
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
Closed
Closed
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6a42280
Updating add-blob command and related components to allow HREF.
a2geek 25338d3
Updating blobs command to show HREF.
a2geek 568081e
Adding sync-blobs to use HREF when blobstore not specified.
a2geek a06a564
Omitting empty HREF's in blob listing.
a2geek e680e89
Forcing blobstore ID to be "-" since it doesn't apply for HREF downlo…
a2geek 8f41766
Adding --validate-blob-origin to create-release to re-download from s…
a2geek afa1d22
Adding a simple message to BlobsDirReporter.
a2geek 6d95f6b
Merge remote-tracking branch 'upstream/main' into feature/allow-remot…
a2geek bead4e8
Updates to ignore deferred closes.
a2geek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ package releasedir | |
| import ( | ||
| "fmt" | ||
| "io" | ||
| "net/http" | ||
| "os" | ||
| "path/filepath" | ||
| "sort" | ||
|
|
@@ -47,6 +48,7 @@ type fsBlobsDirSchema_Blob struct { | |
|
|
||
| BlobstoreID string `yaml:"object_id,omitempty"` | ||
| SHA1 string `yaml:"sha"` | ||
| HREF string `yaml:"href,omitempty"` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this change has been refocused on the notion of validating Blob origin, I would propose we change This would allow additional URI types to be added in the future. |
||
| } | ||
|
|
||
| func NewFSBlobsDir( | ||
|
|
@@ -106,6 +108,7 @@ func (d FSBlobsDir) Blobs() ([]Blob, error) { | |
| Size: rec.Size, | ||
| BlobstoreID: rec.BlobstoreID, | ||
| SHA1: rec.SHA1, | ||
| HREF: rec.HREF, | ||
| }) | ||
| } | ||
|
|
||
|
|
@@ -139,10 +142,11 @@ func (d FSBlobsDir) SyncBlobs(parallel int) error { | |
|
|
||
| var tasks []func() error | ||
| for _, blob := range blobs { | ||
| blob := blob | ||
| tasks = append(tasks, func() error { | ||
| if len(blob.BlobstoreID) > 0 { | ||
| return d.downloadBlob(blob) | ||
| } else if len(blob.HREF) > 0 { | ||
| return d.downloadBlobFromHref(blob) | ||
| } | ||
|
|
||
| return nil | ||
|
|
@@ -157,6 +161,53 @@ func (d FSBlobsDir) SyncBlobs(parallel int) error { | |
| return nil | ||
| } | ||
|
|
||
| func (d FSBlobsDir) ValidateBlobsFromOrigin() error { | ||
| blobs, err := d.Blobs() | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| for _, blob := range blobs { | ||
| blobID := blob.BlobstoreID | ||
| if blobID == "" { | ||
| blobID = "-" | ||
| } | ||
|
|
||
| if len(blob.HREF) > 0 { | ||
| digest, err := boshcrypto.ParseMultipleDigest(blob.SHA1) | ||
| if err != nil { | ||
| return bosherr.WrapErrorf( | ||
| err, "Generating multi digest for blob with path '%s' with digest string '%s'", blob.Path, blob.SHA1) | ||
| } | ||
|
|
||
| d.reporter.BlobDownloadStarted(blob.Path, blob.Size, blobID, blob.SHA1) | ||
|
|
||
| tempFile, err := d.downloadBlobHrefToTempFile(blob) | ||
| if err != nil { | ||
| d.reporter.BlobDownloadFinished(blob.Path, blobID, err) | ||
| return bosherr.WrapErrorf(err, "Downloading blob from '%s'", blob.HREF) | ||
| } | ||
|
|
||
| file, err := d.fs.OpenFile(tempFile.Name(), os.O_RDONLY, 0) | ||
| if err != nil { | ||
| d.reporter.BlobDownloadFinished(blob.Path, blobID, err) | ||
| return err | ||
| } | ||
| defer file.Close() //nolint:errcheck | ||
|
|
||
| if err := digest.Verify(file); err != nil { | ||
| d.reporter.BlobDownloadFinished(blob.Path, blobID, err) | ||
| return bosherr.WrapErrorf(err, "Validating SHA for '%s'", blob.HREF) | ||
| } | ||
|
|
||
| d.reporter.BlobDownloadFinished(blob.Path, blobID, nil) | ||
| } else { | ||
| d.reporter.BlobDownloadMessage(blob.Path, blobID, "skipped") | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (d FSBlobsDir) removeUnknownBlobs(blobs []Blob) error { | ||
| files, err := d.fs.RecursiveGlob(filepath.Join(d.dirPath, "**/*")) | ||
| if err != nil { | ||
|
|
@@ -192,7 +243,7 @@ func (d FSBlobsDir) removeUnknownBlobs(blobs []Blob) error { | |
| return nil | ||
| } | ||
|
|
||
| func (d FSBlobsDir) TrackBlob(path string, src io.ReadCloser) (Blob, error) { | ||
| func (d FSBlobsDir) TrackBlob(path string, src io.ReadCloser, href string) (Blob, error) { | ||
| tempFile, err := d.fs.TempFile("track-blob") | ||
| if err != nil { | ||
| return Blob{}, bosherr.WrapErrorf(err, "Creating temp blob") | ||
|
|
@@ -235,7 +286,7 @@ func (d FSBlobsDir) TrackBlob(path string, src io.ReadCloser) (Blob, error) { | |
| idx = len(blobs) - 1 | ||
| } | ||
|
|
||
| blobs[idx] = Blob{Path: path, Size: fileInfo.Size(), SHA1: sha1} | ||
| blobs[idx] = Blob{Path: path, Size: fileInfo.Size(), SHA1: sha1, HREF: href} | ||
|
|
||
| tempFile.Close() //nolint:errcheck | ||
|
|
||
|
|
@@ -355,6 +406,64 @@ func (d FSBlobsDir) downloadBlob(blob Blob) error { | |
| return d.moveBlobLocally(path, dstPath) | ||
| } | ||
|
|
||
| func (d FSBlobsDir) downloadBlobFromHref(blob Blob) error { | ||
| dstPath := filepath.Join(d.dirPath, blob.Path) | ||
|
|
||
| digest, err := boshcrypto.ParseMultipleDigest(blob.SHA1) | ||
| if err != nil { | ||
| return bosherr.WrapErrorf( | ||
| err, "Generating multi digest for blob with path '%s' with digest string '%s'", blob.Path, blob.SHA1) | ||
| } | ||
|
|
||
| if d.checkBlobExistence(dstPath, digest) { | ||
| return nil | ||
| } | ||
|
|
||
| blobID := blob.BlobstoreID | ||
| if blobID == "" { | ||
| blobID = "-" | ||
| } | ||
|
|
||
| d.reporter.BlobDownloadStarted(blob.Path, blob.Size, blobID, blob.SHA1) | ||
|
|
||
| tempFile, err := d.downloadBlobHrefToTempFile(blob) | ||
| if err != nil { | ||
| d.reporter.BlobDownloadFinished(blob.Path, "-", err) | ||
| return bosherr.WrapErrorf(err, "Downloading blob from '%s'", blob.HREF) | ||
| } | ||
|
|
||
| d.reporter.BlobDownloadFinished(blob.Path, blobID, nil) | ||
|
|
||
| return d.moveBlobLocally(tempFile.Name(), dstPath) | ||
| } | ||
|
|
||
| func (d FSBlobsDir) downloadBlobHrefToTempFile(blob Blob) (boshsys.File, error) { | ||
| resp, err := http.Get(blob.HREF) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer resp.Body.Close() //nolint:errcheck | ||
|
|
||
| tempFile, err := d.fs.TempFile("track-blob") | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer tempFile.Close() //nolint:errcheck | ||
|
|
||
| _, err = io.Copy(tempFile, resp.Body) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| file, err := d.fs.OpenFile(tempFile.Name(), os.O_RDONLY, 0) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| defer file.Close() //nolint:errcheck | ||
|
|
||
| return tempFile, nil | ||
| } | ||
|
|
||
| func (d FSBlobsDir) uploadBlob(blob Blob) (string, error) { | ||
| var blobID string | ||
|
|
||
|
|
@@ -395,6 +504,7 @@ func (d FSBlobsDir) save(blobs []Blob) error { | |
| Size: blob.Size, | ||
| BlobstoreID: blob.BlobstoreID, | ||
| SHA1: blob.SHA1, | ||
| HREF: blob.HREF, | ||
| } | ||
| } | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Rather than handling the HREF ->
Fileconversion here, I think it would make more sense eitherTrackBlob()to takeopt.ArgsPathitself, and handle writing the remote file intotempFile(https://github.com/cloudfoundry/bosh-cli/pull/683/files?diff=unified&w=1#diff-17144e6602ffb3d080986c8a0843436cd75cd11990789e6ba43d64ad98e9ed41L195)--hrefor--uri) that indicates that a remote file is being added--uriflag passed this would be stored for later verificationThere 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.
If
TrackBlob()is handling the fetching, perhaps a better interface would be to pass aBlob{}struct explicitly and allow that function to fill insha2andsize?