about summary refs log tree commit diff
path: root/tools/nixery/server/config/config.go
diff options
context:
space:
mode:
authorVincent Ambo <tazjin@google.com>2019-10-27T17·33+0100
committerVincent Ambo <github@tazj.in>2019-10-28T21·31+0100
commite8fd6b67348610ff7bbd4585036567b9e56945b7 (patch)
treed90066bd2a8d35efbc655227432e0772faf3a616 /tools/nixery/server/config/config.go
parent20e0ca53cba796a67311360d7a21c0f7c8baf78a (diff)
refactor(server): Change setup to create new storage backends
Diffstat (limited to 'tools/nixery/server/config/config.go')
-rw-r--r--tools/nixery/server/config/config.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/tools/nixery/server/config/config.go b/tools/nixery/server/config/config.go
index ad6dff4043..6cc69fa1f5 100644
--- a/tools/nixery/server/config/config.go
+++ b/tools/nixery/server/config/config.go
@@ -37,6 +37,13 @@ func getConfig(key, desc, def string) string {
 	return value
 }
 
+// Backend represents the possible storage backend types
+type Backend int
+
+const (
+	GCS = iota
+)
+
 // Config holds the Nixery configuration options.
 type Config struct {
 	Port    string    // Port on which to launch HTTP server
@@ -44,6 +51,7 @@ type Config struct {
 	Timeout string    // Timeout for a single Nix builder (seconds)
 	WebDir  string    // Directory with static web assets
 	PopUrl  string    // URL to the Nix package popularity count
+	Backend Backend   // Storage backend to use for Nixery
 }
 
 func FromEnv() (Config, error) {
@@ -52,11 +60,22 @@ func FromEnv() (Config, error) {
 		return Config{}, err
 	}
 
+	var b Backend
+	switch os.Getenv("NIXERY_STORAGE_BACKEND") {
+	case "gcs":
+		b = GCS
+	default:
+		log.WithField("values", []string{
+			"gcs",
+		}).Fatal("NIXERY_STORAGE_BUCKET must be set to a supported value")
+	}
+
 	return Config{
 		Port:    getConfig("PORT", "HTTP port", ""),
 		Pkgs:    pkgs,
 		Timeout: getConfig("NIX_TIMEOUT", "Nix builder timeout", "60"),
 		WebDir:  getConfig("WEB_DIR", "Static web file dir", ""),
 		PopUrl:  os.Getenv("NIX_POPULARITY_URL"),
+		Backend: b,
 	}, nil
 }