summaryrefslogtreecommitdiff
path: root/system/tls
diff options
context:
space:
mode:
authorMiguel Angel Ajo <majopela@redhat.com>2019-12-29 18:36:08 +0100
committerMiguel Angel Ajo <majopela@redhat.com>2019-12-29 23:42:46 +0100
commit90a2ff959a958e8f7654f577e88e942378b0a7c2 (patch)
tree934b6d72979f0edf26f3c661b6b059b6d1753e37 /system/tls
parent45730ba5b4de56fed27f79f8c822bb59d41f7a38 (diff)
Allow data directories outside pwd
Running ponzu-cms inside a docker container, and maintaining data files in a volume (or several) was not possible with the previous directory schema without copying files or binaries to the volume. This commit adds several environment variables to allow the administrator to specify paths for directories while retaining backwards compatibility. - PONZU_DATA_DIR : is the directory where all the data and other directories will be stored, still the other directories can be controlled by the other env variables. - PONZU_TLS_DIR : is the directory to store devcerts and autocerts - PONZU_ADMINSTATIC_DIR : directory where the admin static files are served from. - PONZU_UPLOAD_DIR: upload files directory - PONZU_SEARCH_DIR: index directory for searches
Diffstat (limited to 'system/tls')
-rw-r--r--system/tls/devcerts.go10
-rw-r--r--system/tls/enable.go7
-rw-r--r--system/tls/enabledev.go11
3 files changed, 9 insertions, 19 deletions
diff --git a/system/tls/devcerts.go b/system/tls/devcerts.go
index 0554aa4..1dde4df 100644
--- a/system/tls/devcerts.go
+++ b/system/tls/devcerts.go
@@ -26,6 +26,8 @@ import (
"path/filepath"
"time"
+ "github.com/ponzu-cms/ponzu/system/cfg"
+
"github.com/ponzu-cms/ponzu/system/db"
)
@@ -112,12 +114,8 @@ func setupDev() {
}
// overwrite/create directory for devcerts
- pwd, err := os.Getwd()
- if err != nil {
- log.Fatalln("Couldn't find working directory to locate or save dev certificates:", err)
- }
- vendorTLSPath := filepath.Join(pwd, "cmd", "ponzu", "vendor", "github.com", "ponzu-cms", "ponzu", "system", "tls")
+ vendorTLSPath := cfg.TlsDir()
devcertsPath := filepath.Join(vendorTLSPath, "devcerts")
// clear all old certs if found
@@ -126,7 +124,7 @@ func setupDev() {
log.Fatalln("Failed to remove old files from dev certificate directory:", err)
}
- err = os.Mkdir(devcertsPath, os.ModeDir|os.ModePerm)
+ err = os.MkdirAll(devcertsPath, os.ModeDir|os.ModePerm)
if err != nil {
log.Fatalln("Failed to create directory to locate or save dev certificates:", err)
}
diff --git a/system/tls/enable.go b/system/tls/enable.go
index 9fc95f9..12d63bc 100644
--- a/system/tls/enable.go
+++ b/system/tls/enable.go
@@ -13,18 +13,15 @@ import (
"time"
"github.com/ponzu-cms/ponzu/system/db"
+ "github.com/ponzu-cms/ponzu/system/cfg"
"golang.org/x/crypto/acme/autocert"
)
// newManager attempts to locate or create the cert cache directory and the
// certs for TLS encryption and returns an autocert.Manager
func newManager() autocert.Manager {
- pwd, err := os.Getwd()
- if err != nil {
- log.Fatalln("Couldn't find working directory to locate or save certificates.")
- }
- cache := autocert.DirCache(filepath.Join(pwd, "system", "tls", "certs"))
+ cache := autocert.DirCache(filepath.Join(cfg.TlsDir(), "certs"))
if _, err := os.Stat(string(cache)); os.IsNotExist(err) {
err := os.MkdirAll(string(cache), os.ModePerm|os.ModeDir)
if err != nil {
diff --git a/system/tls/enabledev.go b/system/tls/enabledev.go
index 3550fc0..03bce42 100644
--- a/system/tls/enabledev.go
+++ b/system/tls/enabledev.go
@@ -3,8 +3,9 @@ package tls
import (
"log"
"net/http"
- "os"
"path/filepath"
+
+ "github.com/ponzu-cms/ponzu/system/cfg"
)
// EnableDev generates self-signed SSL certificates to use HTTPS & HTTP/2 while
@@ -15,13 +16,7 @@ import (
func EnableDev() {
setupDev()
- pwd, err := os.Getwd()
- if err != nil {
- log.Fatalln("Couldn't find working directory to activate dev certificates:", err)
- }
-
- vendorPath := filepath.Join(pwd, "cmd", "ponzu", "vendor", "github.com", "ponzu-cms", "ponzu", "system", "tls")
-
+ vendorPath := cfg.TlsDir()
cert := filepath.Join(vendorPath, "devcerts", "cert.pem")
key := filepath.Join(vendorPath, "devcerts", "key.pem")