Skip to content

Commit

Permalink
add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
Diogo De Santana Jacome committed Dec 21, 2023
1 parent d9d6eb2 commit 861ab17
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@

# Go workspace file
go.work
go.sum
go.sum
response.json
4 changes: 4 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
VeracodeAPi
===========

<img src="https://i.pinimg.com/originals/7e/2a/eb/7e2aeb1567e91bfc2404cecca6aceecd.gif" />
20 changes: 10 additions & 10 deletions pkg/apiRequest/apiRequest.go
Original file line number Diff line number Diff line change
@@ -1,37 +1,38 @@
package apirequest

import(
"net/http"
"net/url"
import (
"bytes"
"github.com/Didjacome/hmac-veracode/hmac"
"io"
"net/http"
"net/url"
"os"
"bytes"
"log"
)

func ApiRequest(apiKeyID, apiKeySecret, apiUrl, httpMethod string) string {
func ApiRequest(apiKeyID, apiKeySecret, apiUrl, httpMethod string) (string) {
parsedUrl, err := url.Parse(apiUrl)
if err != nil {
panic(err)
log.Fatalf("Error for Url Parse: %v", err)
}

client := &http.Client{}

req, err := http.NewRequest(httpMethod, parsedUrl.String(), nil)
if err != nil {
panic(err)
log.Fatalf("Error creating Request: %v", err)
}

authorizationHeader, err := hmac.CalculateAuthorizationHeader(parsedUrl, httpMethod, apiKeyID, apiKeySecret)
if err != nil {
panic(err)
log.Fatalf("Error for calculating hmac: %v", err)
}

req.Header.Add("Authorization", authorizationHeader)

resp, err := client.Do(req)
if err != nil {
panic(err)
log.Fatalf("api response error validate your credentials or uri: %v", err)
}
if resp.StatusCode != http.StatusOK {
panic("Expected status 200. Status was: " + resp.Status)
Expand All @@ -42,7 +43,6 @@ func ApiRequest(apiKeyID, apiKeySecret, apiUrl, httpMethod string) string {
panic(err)
}


file, err := os.Create("response.json")
if err != nil {
panic(err)
Expand Down
19 changes: 14 additions & 5 deletions pkg/load/load.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package load

import (
"strings"
"github.com/Didjacome/varacode-api/schemas"
"github.com/spf13/viper"
"log"
"strings"
)

var config *schemas.Veracode

func Load() error {
Expand All @@ -14,10 +16,18 @@ func Load() error {
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.AutomaticEnv()

keys := []string{"Credetial.apiKeyID", "Credetial.apiKeySecret", "Credetial.apiUrl"}

err := viper.ReadInConfig()
if err != nil {
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
return err
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
for _, key := range keys {
if !viper.IsSet(key) {
log.Fatalf("Error: %v \n Environment Not Foud: %v", err, key)
}
}
} else {
log.Fatalf("Error: %v", err)
}
}

Expand All @@ -29,10 +39,9 @@ func Load() error {
ApiUrl: viper.GetString("Credetial.apiUrl"),
}

return err
return nil
}


func GetApiCredetial() schemas.Auth {
return config.ApiCredetial
}

0 comments on commit 861ab17

Please sign in to comment.