Skip to content

Commit

Permalink
fix: Add content to handle multiple downloads
Browse files Browse the repository at this point in the history
Signed-off-by: Heck, Jerod <jerod.heck@lmco.com>
  • Loading branch information
jhlmco committed Dec 10, 2023
1 parent 941f943 commit 8cbaed0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go-ossf-slsa3-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
- name: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release && cat release.env >> $GITHUB_STATE && cat release.env >> $GITHUB_OUTPUT
run: npx semantic-release
outputs:
version: ${{ steps.release.outputs.version }}

Expand Down
4 changes: 3 additions & 1 deletion .releaserc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ plugins:
- - "@semantic-release/exec"
- generateNotesCmd: |
echo VERSION=${nextRelease.version} > release.env
echo "::set-output name=version::${nextRelease.version}"
cat release.env >> $GITHUB_STATE
cat release.env >> $GITHUB_OUTPUT
echo $GITHUB_OUTPUT
- - "@semantic-release/git"
- message: |-
Expand Down
20 changes: 20 additions & 0 deletions internal/utils/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package utils
import (
"net"
"net/http"
"os"
"time"

"golang.org/x/net/http2"
Expand Down Expand Up @@ -43,3 +44,22 @@ func NewHTTPClientWithSettings(httpSettings HTTPClientSettings) (*http.Client, e
}
return &client, err
}

func GetFileContentType(ouput *os.File) (string, error) {

// to sniff the content type only the first
// 512 bytes are used.

buf := make([]byte, 512)

_, err := ouput.Read(buf)

if err != nil {
return "", err
}

// the function that actually does the trick
contentType := http.DetectContentType(buf)

return contentType, nil
}
14 changes: 14 additions & 0 deletions pkg/fetch/fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,19 @@ func fetchRequest(path string, file string, username string, password string) er
os.Exit(1)
}

filenameP, err = os.Open(filenameP.Name())

if err != nil {
panic(err)
}

defer filenameP.Close()

contentType, err := utils.GetFileContentType(filenameP)
if err != nil {
panic(err)
}
fmt.Println("Content Type of file is: " + contentType)

return nil
}

0 comments on commit 8cbaed0

Please sign in to comment.