Skip to content

Commit

Permalink
fix: Check file format when uploading artifacts
Browse files Browse the repository at this point in the history
Changelog: Title
Ticket: MEN-7860
Signed-off-by: Bahaa Aldeen Ghazal <[email protected]>
  • Loading branch information
bahaa-ghazal committed Dec 23, 2024
1 parent a4ba53f commit 2121f28
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions client/deployments/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package deployments

import (
"archive/tar"
"bytes"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -296,6 +297,24 @@ func (c *Client) DirectUpload(
return errors.Wrap(err, "Cannot read artifact file stats")
}

tr := tar.NewReader(artifact)
versionH, err := tr.Next()
if err != nil {
return errors.Wrap(err, "Cannot find artifact")
} else if versionH.Name != "version" {
return errors.New("Invalid artifact format")
}
v := struct {
Format string `json:"format"`
}{}
err = json.NewDecoder(tr).Decode(&v)
if err != nil || v.Format != "mender" {
return errors.New("Invalid artifact format")
}
_, err = artifact.Seek(0, io.SeekStart)
if err != nil || v.Format != "mender" {
return err
}
var req *http.Request
if !noProgress {
// create progress bar
Expand Down Expand Up @@ -367,6 +386,24 @@ func (c *Client) UploadArtifact(
return errors.Wrap(err, "Cannot read artifact file stats")
}

tr := tar.NewReader(artifact)
versionH, err := tr.Next()
if err != nil {
return errors.Wrap(err, "Cannot find artifact")
} else if versionH.Name != "version" {
return errors.New("Invalid artifact format")
}
v := struct {
Format string `json:"format"`
}{}
err = json.NewDecoder(tr).Decode(&v)
if err != nil || v.Format != "mender" {
return errors.New("Invalid artifact format")
}
_, err = artifact.Seek(0, io.SeekStart)
if err != nil || v.Format != "mender" {
return err
}
// create pipe
pR, pW := io.Pipe()

Expand Down

0 comments on commit 2121f28

Please sign in to comment.