Specify file with username:password rather than specifying the username:password directly on the command line.
diff --git a/api/api.go b/api/api.go
index 6289bef..5cca4d8 100644
--- a/api/api.go
+++ b/api/api.go
@@ -22,11 +22,13 @@
"encoding/base64"
"errors"
"fmt"
+ "io/ioutil"
"log"
"math/rand"
"net/http"
"sort"
"strconv"
+ "strings"
"time"
"github.com/golang/protobuf/jsonpb"
@@ -56,14 +58,23 @@
// InitHTTPConnection creates and returns a new HTTPConnection object
// with a given server address and username/password.
-func InitHTTPConnection(serverAddr string, usernamePassword string) *HTTPConnection {
+func InitHTTPConnection(serverAddr string, credentialsFile string) (*HTTPConnection, error) {
+ usernamePassword := ""
+ if credentialsFile != "" {
+ // Set up username/password.
+ data, err := ioutil.ReadFile(credentialsFile)
+ if err != nil {
+ return nil, err
+ }
+ usernamePassword = strings.Replace(string(data), "\n", "", -1)
+ }
return &HTTPConnection{
client: &http.Client{Timeout: time.Duration(1 * time.Second)},
credentials: "Basic " + base64.StdEncoding.EncodeToString([]byte(usernamePassword)),
marshaler: &jsonpb.Marshaler{OrigName: true},
// TODO(wsilberm): Use https
baseURL: "http://" + serverAddr,
- }
+ }, nil
}
func (h HTTPConnection) getURL(rpcName string) string {
diff --git a/testclient/main.go b/testclient/main.go
index eabfbef..b7610e2 100644
--- a/testclient/main.go
+++ b/testclient/main.go
@@ -34,7 +34,7 @@
var (
serverAddr = flag.String("server_addr", "example.com:80", "Your http server's address in the format of host:port")
- usernamePassword = flag.String("username_password", "", "(eg 'username:password') credentials for your server. Leave blank to bypass authentication.")
+ credentialsFile = flag.String("credentials_file", "", "File containing credentials for your server. Leave blank to bypass authentication.")
testSlots = flag.Int("num_test_slots", 10, "Maximum number of slots to test from availability_feed. Slots will be selected randomly")
allFlows = flag.Bool("all_tests", false, "Whether to test all endpoints.")
healthFlow = flag.Bool("health_check_test", false, "Whether to test the Health endpoint.")
@@ -171,7 +171,10 @@
defer f.Close()
log.SetOutput(f)
- conn := api.InitHTTPConnection(*serverAddr, *usernamePassword)
+ conn, err := api.InitHTTPConnection(*serverAddr, *credentialsFile)
+ if err != nil {
+ log.Fatalf("Failed to init http connection %v", err)
+ }
// Health check doesn't affect the cancel booking flow so we let it through.
if *cancelAllBookings && (*allFlows || *checkFlow || *bookFlow || *listFlow || *statusFlow || *rescheduleFlow) {