Allow users to run the scouting app with HTTPS/LDAP

I find myself needing to experiment with getting the username from the
LDAP login that happens in our HTTPS version of the scouting app. This
patch exposes a new `//scouting:https` target to let me do just that.

This patch also updates the README to let other folks know how to run
it under HTTPS/LDAP.

Signed-off-by: Philipp Schrader <philipp.schrader@gmail.com>
Change-Id: Ib9f4b8626cb9adfe178ded2b43677d1dcd30da4f
diff --git a/scouting/BUILD b/scouting/BUILD
index 0c2c641..2a2d0ba 100644
--- a/scouting/BUILD
+++ b/scouting/BUILD
@@ -1,4 +1,5 @@
 load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
+load("//tools/build_rules:apache.bzl", "apache_wrapper")
 load("//tools/build_rules:js.bzl", "protractor_ts_test", "turn_files_into_runfiles")
 
 go_binary(
@@ -44,3 +45,8 @@
     on_prepare = ":scouting_test.protractor.on-prepare.js",
     server = "//scouting/testing:scouting_test_servers",
 )
+
+apache_wrapper(
+    name = "https",
+    binary = ":scouting",
+)
diff --git a/scouting/README.md b/scouting/README.md
index 7789c8f..28fdc26 100644
--- a/scouting/README.md
+++ b/scouting/README.md
@@ -43,3 +43,24 @@
 where `1234` is the port that your instance of the webserver is using.
 `<build_server>` is the SSH Host entry in your `~/.ssh/config` file for the
 build server.
+
+You can then visit <http://localhost:1234/> to look at the webserver.
+
+
+Running the webserver with HTTPS
+--------------------------------------------------------------------------------
+You can test HTTPS and LDAP interation by running the webserver in a slightly
+different way.
+
+    $ bazel run //scouting:https -- --testdb_port 2345 --https_port 3456
+
+The `--testdb_port` value must match the port you selected when running the
+database.
+
+The `--https_port` value is the port at which the webserver is available via
+HTTPS. See the documentation in
+[`tools/build_rules/apache.bzl`](tools/build_rules/apache.bzl) for more
+information. The documentation tells you how to set up an `ldap.json`
+configuration.
+
+You can then visit <https://localhost:3456/> to look at the webserver.
diff --git a/scouting/webserver/main.go b/scouting/webserver/main.go
index a4d549a..8f4298b 100644
--- a/scouting/webserver/main.go
+++ b/scouting/webserver/main.go
@@ -9,6 +9,7 @@
 	"log"
 	"os"
 	"os/signal"
+	"strconv"
 	"syscall"
 	"time"
 
@@ -39,8 +40,23 @@
 	return &config, nil
 }
 
+// Gets the default port to use for the webserver. If wrapped by
+// apache_wrapper(), we use the port dictated by the wrapper.
+func getDefaultPort() int {
+	port_str := os.Getenv("APACHE_WRAPPED_PORT")
+	if port_str != "" {
+		port, err := strconv.Atoi(port_str)
+		if err != nil {
+			log.Fatalf("Failed to parse \"%s\" as integer: %v", port_str, err)
+		}
+		return port
+	}
+
+	return 8080
+}
+
 func main() {
-	portPtr := flag.Int("port", 8080, "The port number to bind to.")
+	portPtr := flag.Int("port", getDefaultPort(), "The port number to bind to.")
 	dirPtr := flag.String("directory", ".", "The directory to serve at /.")
 	dbConfigPtr := flag.String("db_config", "",
 		"The postgres database JSON config. It needs the following keys: "+