feature/users #1
							
								
								
									
										13
									
								
								config.go
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								config.go
									
									
									
									
									
								
							| @@ -10,10 +10,11 @@ import ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| type ServerConfig struct { | type ServerConfig struct { | ||||||
| 	LogLevel   string             `toml:"LogLevel"` | 	LogLevel      string             `toml:"LogLevel"` | ||||||
| 	URL        string             `toml:"URL"` | 	URL           string             `toml:"URL"` | ||||||
| 	ListenAddr string             `toml:"ListenAddr"` | 	ListenAddr    string             `toml:"ListenAddr"` | ||||||
| 	Store      *ServerStoreConfig `toml:"Store"` | 	SigningSecret string             `toml:"SigningSecret"` | ||||||
|  | 	Store         *ServerStoreConfig `toml:"Store"` | ||||||
| } | } | ||||||
|  |  | ||||||
| type ServerStoreConfig struct { | type ServerStoreConfig struct { | ||||||
| @@ -54,6 +55,10 @@ func (sc *ServerConfig) updateFromEnv() { | |||||||
| 		sc.ListenAddr = value | 		sc.ListenAddr = value | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	if value, ok := os.LookupEnv("GPASTE_SIGNINGSECRET"); ok { | ||||||
|  | 		sc.SigningSecret = value | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	if value, ok := os.LookupEnv("GPASTE_STORE_TYPE"); ok { | 	if value, ok := os.LookupEnv("GPASTE_STORE_TYPE"); ok { | ||||||
| 		sc.Store.Type = value | 		sc.Store.Type = value | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -16,6 +16,7 @@ func TestServerConfig(t *testing.T) { | |||||||
| LogLevel = "INFO" | LogLevel = "INFO" | ||||||
| URL = "http://paste.example.org" | URL = "http://paste.example.org" | ||||||
| ListenAddr = ":8080" | ListenAddr = ":8080" | ||||||
|  | SigningSecret = "abc999" | ||||||
|  |  | ||||||
| [Store] | [Store] | ||||||
| Type = "fs" | Type = "fs" | ||||||
| @@ -23,9 +24,10 @@ Type = "fs" | |||||||
| Dir = "/tmp" | Dir = "/tmp" | ||||||
| ` | ` | ||||||
| 		expected := &gpaste.ServerConfig{ | 		expected := &gpaste.ServerConfig{ | ||||||
| 			LogLevel:   "INFO", | 			LogLevel:      "INFO", | ||||||
| 			URL:        "http://paste.example.org", | 			URL:           "http://paste.example.org", | ||||||
| 			ListenAddr: ":8080", | 			ListenAddr:    ":8080", | ||||||
|  | 			SigningSecret: "abc999", | ||||||
| 			Store: &gpaste.ServerStoreConfig{ | 			Store: &gpaste.ServerStoreConfig{ | ||||||
| 				Type: "fs", | 				Type: "fs", | ||||||
| 				FS: &gpaste.ServerStoreFSStoreConfig{ | 				FS: &gpaste.ServerStoreFSStoreConfig{ | ||||||
| @@ -48,16 +50,18 @@ Dir = "/tmp" | |||||||
| 		clearEnv() | 		clearEnv() | ||||||
|  |  | ||||||
| 		var envMap map[string]string = map[string]string{ | 		var envMap map[string]string = map[string]string{ | ||||||
| 			"GPASTE_LOGLEVEL":     "DEBUG", | 			"GPASTE_LOGLEVEL":      "DEBUG", | ||||||
| 			"GPASTE_URL":          "http://gpaste.example.org", | 			"GPASTE_URL":           "http://gpaste.example.org", | ||||||
| 			"GPASTE_STORE_TYPE":   "fs", | 			"GPASTE_STORE_TYPE":    "fs", | ||||||
| 			"GPASTE_LISTENADDR":   ":8000", | 			"GPASTE_LISTENADDR":    ":8000", | ||||||
| 			"GPASTE_STORE_FS_DIR": "/tmp", | 			"GPASTE_SIGNINGSECRET": "test1345", | ||||||
|  | 			"GPASTE_STORE_FS_DIR":  "/tmp", | ||||||
| 		} | 		} | ||||||
| 		expected := &gpaste.ServerConfig{ | 		expected := &gpaste.ServerConfig{ | ||||||
| 			LogLevel:   "DEBUG", | 			LogLevel:      "DEBUG", | ||||||
| 			URL:        "http://gpaste.example.org", | 			URL:           "http://gpaste.example.org", | ||||||
| 			ListenAddr: ":8000", | 			ListenAddr:    ":8000", | ||||||
|  | 			SigningSecret: "test1345", | ||||||
| 			Store: &gpaste.ServerStoreConfig{ | 			Store: &gpaste.ServerStoreConfig{ | ||||||
| 				Type: "fs", | 				Type: "fs", | ||||||
| 				FS: &gpaste.ServerStoreFSStoreConfig{ | 				FS: &gpaste.ServerStoreFSStoreConfig{ | ||||||
|   | |||||||
							
								
								
									
										2
									
								
								http.go
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								http.go
									
									
									
									
									
								
							| @@ -30,7 +30,7 @@ func NewHTTPServer(cfg *ServerConfig) *HTTPServer { | |||||||
| 	} | 	} | ||||||
| 	srv.Files = NewMemoryFileStore() | 	srv.Files = NewMemoryFileStore() | ||||||
| 	srv.Users = NewMemoryUserStore() | 	srv.Users = NewMemoryUserStore() | ||||||
| 	srv.Auth = NewAuthService(srv.Users, []byte("test1235")) | 	srv.Auth = NewAuthService(srv.Users, []byte(srv.config.SigningSecret)) | ||||||
|  |  | ||||||
| 	r := chi.NewRouter() | 	r := chi.NewRouter() | ||||||
| 	r.Use(middleware.RealIP) | 	r.Use(middleware.RealIP) | ||||||
|   | |||||||
| @@ -15,6 +15,7 @@ import ( | |||||||
|  |  | ||||||
| func TestHandlers(t *testing.T) { | func TestHandlers(t *testing.T) { | ||||||
| 	cfg := &gpaste.ServerConfig{ | 	cfg := &gpaste.ServerConfig{ | ||||||
|  | 		SigningSecret: "abc123", | ||||||
| 		Store: &gpaste.ServerStoreConfig{ | 		Store: &gpaste.ServerStoreConfig{ | ||||||
| 			Type: "memory", | 			Type: "memory", | ||||||
| 		}, | 		}, | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user