-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #239 from bugsnag/integrity_header
Add integrity header, change to command pattern in test app
- Loading branch information
Showing
10 changed files
with
180 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"time" | ||
) | ||
|
||
const DEFAULT_MAZE_ADDRESS = "http://localhost:9339" | ||
|
||
type Command struct { | ||
Action string `json:"action,omitempty"` | ||
ScenarioName string `json:"scenario_name,omitempty"` | ||
APIKey string `json:"api_key,omitempty"` | ||
NotifyEndpoint string `json:"notify_endpoint,omitempty"` | ||
SessionsEndpoint string `json:"sessions_endpoint,omitempty"` | ||
UUID string `json:"uuid,omitempty"` | ||
RunUUID string `json:"run_uuid,omitempty"` | ||
} | ||
|
||
func GetCommand(mazeAddress string) Command { | ||
var command Command | ||
mazeURL := fmt.Sprintf("%+v/command", mazeAddress) | ||
client := http.Client{Timeout: 2 * time.Second} | ||
res, err := client.Get(mazeURL) | ||
if err != nil { | ||
fmt.Printf("[Bugsnag] Error while receiving command: %+v\n", err) | ||
return command | ||
} | ||
|
||
if res != nil { | ||
err = json.NewDecoder(res.Body).Decode(&command) | ||
res.Body.Close() | ||
if err != nil { | ||
fmt.Printf("[Bugsnag] Error while decoding command: %+v\n", err) | ||
return command | ||
} | ||
} | ||
|
||
return command | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,7 @@ | ||
require 'fileutils' | ||
require 'socket' | ||
require 'timeout' | ||
|
||
testBuildFolder = 'features/fixtures/testbuild' | ||
|
||
FileUtils.rm_rf(testBuildFolder) | ||
Dir.mkdir testBuildFolder | ||
|
||
# Copy the existing dir | ||
`find . -name '*.go' -o -name 'go.sum' -o -name 'go.mod' \ | ||
-not -path "./examples/*" \ | ||
-not -path "./testutil/*" \ | ||
-not -path "./v2/testutil/*" \ | ||
-not -path "./features/*" \ | ||
-not -name '*_test.go' | cpio -pdm #{testBuildFolder}` | ||
Before do | ||
$address = nil | ||
$api_key = "166f5ad3590596f9aa8d601ea89af845" | ||
steps %( | ||
When I configure the base endpoint | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
package headers | ||
|
||
import "time" | ||
import ( | ||
"fmt" | ||
"time" | ||
) | ||
|
||
// PrefixedHeaders returns a map of Content-Type and the 'Bugsnag-' headers for | ||
// API key, payload version, and the time at which the request is being sent. | ||
func PrefixedHeaders(apiKey, payloadVersion, sha1 string) map[string]string { | ||
integrityHeader := fmt.Sprintf("sha1 %v", sha1) | ||
|
||
//PrefixedHeaders returns a map of Content-Type and the 'Bugsnag-' headers for | ||
//API key, payload version, and the time at which the request is being sent. | ||
func PrefixedHeaders(apiKey, payloadVersion string) map[string]string { | ||
return map[string]string{ | ||
"Content-Type": "application/json", | ||
"Bugsnag-Api-Key": apiKey, | ||
"Bugsnag-Payload-Version": payloadVersion, | ||
"Bugsnag-Sent-At": time.Now().UTC().Format(time.RFC3339), | ||
"Bugsnag-Integrity": integrityHeader, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.