Skip to content

Commit

Permalink
add user-agent
Browse files Browse the repository at this point in the history
Signed-off-by: Karl Piplies <[email protected]>
  • Loading branch information
karlpip authored and mebel123 committed Jul 31, 2024
1 parent 0fb59d4 commit 48343e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion conf/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ import (
"github.com/jinzhu/configor"
)

const DefaultApiVersion = "v1"
const (
DefaultApiVersion = "v1"
CLIVersion = "v0.7"
)

var Config = struct {
ProjectToken string `default:""`
Expand All @@ -24,6 +27,10 @@ var Config = struct {
Host string `default:""`
}{}

func UserAgent() string {
return "disclosure-cli / " + CLIVersion
}

func LoadConfig(configFileLocation string) {
if _, err := os.Stat(configFileLocation); errors.Is(err, os.ErrNotExist) {
fmt.Println("No config file available in location. Proceeding to check environment variables.")
Expand Down
Binary file modified disclosure-cli
Binary file not shown.
4 changes: 4 additions & 0 deletions pkg/helper/apiRequests.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ func SbomUploadFormData(url string, completeFilename string, tag string) string
req.Header.Set("accept", "application/json")
req.Header.Set("Content-Type", m.FormDataContentType())
req.Header.Set("Authorization", "DISCO"+" "+conf.Config.ProjectToken)
req.Header.Set("User-Agent", conf.UserAgent())

resp, err := client.Do(req)
if err != nil {
Expand Down Expand Up @@ -96,6 +97,7 @@ func DiscoApiPost(url string, v interface{}) string {
req.Header.Set("accept", "application/json")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "DISCO"+" "+conf.Config.ProjectToken)
req.Header.Set("User-Agent", conf.UserAgent())
resp, err := client.Do(req)
if err != nil {
fmt.Println("Error on requesting url " + url)
Expand Down Expand Up @@ -136,6 +138,7 @@ func DiscoApiPut(url string, v interface{}) string {
req.Header.Set("accept", "application/json")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Authorization", "DISCO"+" "+conf.Config.ProjectToken)
req.Header.Set("User-Agent", conf.UserAgent())
resp, err := client.Do(req)
if err != nil {
fmt.Printf("\n Error on requesting url %s \n Error: %s", url, err.Error())
Expand Down Expand Up @@ -168,6 +171,7 @@ func DiscoApiGet(url string) string {

req.Header.Set("accept", "application/json")
req.Header.Set("Authorization", "DISCO"+" "+conf.Config.ProjectToken)
req.Header.Set("User-Agent", conf.UserAgent())
resp, err := client.Do(req)
if err != nil {
fmt.Printf("\n Error on requesting url %s \n Error: %s ", url, err.Error())
Expand Down

0 comments on commit 48343e4

Please sign in to comment.