Skip to content

Commit 861ab17

Browse files
author
Diogo De Santana Jacome
committed
add readme
1 parent d9d6eb2 commit 861ab17

4 files changed

Lines changed: 30 additions & 16 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919

2020
# Go workspace file
2121
go.work
22-
go.sum
22+
go.sum
23+
response.json

Readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
VeracodeAPi
2+
===========
3+
4+
<img src="https://i.pinimg.com/originals/7e/2a/eb/7e2aeb1567e91bfc2404cecca6aceecd.gif" />

pkg/apiRequest/apiRequest.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
11
package apirequest
22

3-
import(
4-
"net/http"
5-
"net/url"
3+
import (
4+
"bytes"
65
"github.com/Didjacome/hmac-veracode/hmac"
76
"io"
7+
"net/http"
8+
"net/url"
89
"os"
9-
"bytes"
10+
"log"
1011
)
1112

12-
func ApiRequest(apiKeyID, apiKeySecret, apiUrl, httpMethod string) string {
13+
func ApiRequest(apiKeyID, apiKeySecret, apiUrl, httpMethod string) (string) {
1314
parsedUrl, err := url.Parse(apiUrl)
1415
if err != nil {
15-
panic(err)
16+
log.Fatalf("Error for Url Parse: %v", err)
1617
}
1718

1819
client := &http.Client{}
1920

2021
req, err := http.NewRequest(httpMethod, parsedUrl.String(), nil)
2122
if err != nil {
22-
panic(err)
23+
log.Fatalf("Error creating Request: %v", err)
2324
}
2425

2526
authorizationHeader, err := hmac.CalculateAuthorizationHeader(parsedUrl, httpMethod, apiKeyID, apiKeySecret)
2627
if err != nil {
27-
panic(err)
28+
log.Fatalf("Error for calculating hmac: %v", err)
2829
}
2930

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

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

45-
4646
file, err := os.Create("response.json")
4747
if err != nil {
4848
panic(err)

pkg/load/load.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package load
22

33
import (
4-
"strings"
54
"github.com/Didjacome/varacode-api/schemas"
65
"github.com/spf13/viper"
6+
"log"
7+
"strings"
78
)
9+
810
var config *schemas.Veracode
911

1012
func Load() error {
@@ -14,10 +16,18 @@ func Load() error {
1416
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
1517
viper.AutomaticEnv()
1618

19+
keys := []string{"Credetial.apiKeyID", "Credetial.apiKeySecret", "Credetial.apiUrl"}
20+
1721
err := viper.ReadInConfig()
1822
if err != nil {
19-
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
20-
return err
23+
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
24+
for _, key := range keys {
25+
if !viper.IsSet(key) {
26+
log.Fatalf("Error: %v \n Environment Not Foud: %v", err, key)
27+
}
28+
}
29+
} else {
30+
log.Fatalf("Error: %v", err)
2131
}
2232
}
2333

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

32-
return err
42+
return nil
3343
}
3444

35-
3645
func GetApiCredetial() schemas.Auth {
3746
return config.ApiCredetial
3847
}

0 commit comments

Comments
 (0)