forked from brian1917/vcodeHMAC
-
Notifications
You must be signed in to change notification settings - Fork 1
/
generateHMAC.go
49 lines (42 loc) · 1.45 KB
/
generateHMAC.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Package vcodeHMAC creates an authorization header for accessing Veracode APIs using an API ID and Key.
package vcodeHMAC
// GenerateAuthHeader takes the location of your credentials file, the HTTP Method, and URL and returns the header value to be used for Authorization
func GenerateAuthHeader(credsFile, httpMethod, url string) (string, error) {
credentials, err := getCredentials(credsFile, "default")
if err != nil {
return "", err
}
host, err := getHost(url)
if err != nil {
return "", err
}
params, err := getPathParams(url)
if err != nil {
return "", err
}
headerValue, err := generateHeader(host, params, httpMethod, credentials[0], credentials[1], defaultAuthScheme)
if err != nil {
return "", err
}
return headerValue, nil
}
// GenerateAuthHeader takes the location of your credentials file, the HTTP Method, and URL and returns the header value to be used for Authorization
func GenerateAuthHeaderForProfile(credsFile, httpMethod, url string, profile string) (string, error) {
credentials, err := getCredentials(credsFile, profile)
if err != nil {
return "", err
}
host, err := getHost(url)
if err != nil {
return "", err
}
params, err := getPathParams(url)
if err != nil {
return "", err
}
headerValue, err := generateHeader(host, params, httpMethod, credentials[0], credentials[1], defaultAuthScheme)
if err != nil {
return "", err
}
return headerValue, nil
}