Add signing secret to config

This commit is contained in:
Torjus Håkestad 2022-01-19 22:28:08 +01:00
parent e1ed7cce66
commit 5ffef4f6ad
4 changed files with 26 additions and 16 deletions

View File

@ -13,6 +13,7 @@ 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"`
SigningSecret string `toml:"SigningSecret"`
Store *ServerStoreConfig `toml:"Store"` Store *ServerStoreConfig `toml:"Store"`
} }
@ -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
} }

View File

@ -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"
@ -26,6 +27,7 @@ Dir = "/tmp"
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{
@ -52,12 +54,14 @@ Dir = "/tmp"
"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_SIGNINGSECRET": "test1345",
"GPASTE_STORE_FS_DIR": "/tmp", "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{

View File

@ -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)

View File

@ -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",
}, },