Collect the username when data scouting data is submitted
This patch adds the username of the person that is submitting scouting
data.
I kind of amended the existing unit test to validate this feature by
injecting a fake username at the right places. It doesn't validate
actual HTTPS traffic, but it's good enough for now.
Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: I483cf30fd046965b23916b129a074906b586b096
diff --git a/scouting/webserver/requests/debug/debug.go b/scouting/webserver/requests/debug/debug.go
index 81be3d1..49b6f79 100644
--- a/scouting/webserver/requests/debug/debug.go
+++ b/scouting/webserver/requests/debug/debug.go
@@ -2,6 +2,7 @@
import (
"bytes"
+ "encoding/base64"
"errors"
"fmt"
"io"
@@ -16,6 +17,9 @@
"github.com/frc971/971-Robot-Code/scouting/webserver/requests/messages/submit_data_scouting_response"
)
+// The username to submit the various requests as.
+const DefaultUsername = "debug_cli"
+
// Use aliases to make the rest of the code more readable.
type SubmitDataScoutingResponseT = submit_data_scouting_response.SubmitDataScoutingResponseT
type RequestAllMatchesResponseT = request_all_matches_response.RequestAllMatchesResponseT
@@ -66,7 +70,16 @@
// Performs a POST request with the specified payload. The bytes that the
// server responds with are returned.
func performPost(url string, requestBytes []byte) ([]byte, error) {
- resp, err := http.Post(url, "application/octet-stream", bytes.NewReader(requestBytes))
+ req, err := http.NewRequest("POST", url, bytes.NewReader(requestBytes))
+ if err != nil {
+ log.Printf("Failed to create a new POST request to %s: %v", url, err)
+ return nil, err
+ }
+ req.Header.Add("Authorization", "Basic "+
+ base64.StdEncoding.EncodeToString([]byte(DefaultUsername+":")))
+
+ client := &http.Client{}
+ resp, err := client.Do(req)
if err != nil {
log.Printf("Failed to send POST request to %s: %v", url, err)
return nil, err