From 805cef4dd68fb3b65d3fcb5a54dd15a546c6afec Mon Sep 17 00:00:00 2001 From: xenolf Date: Fri, 12 Jun 2015 23:34:49 +0200 Subject: [PATCH] Remove global paths and default to CWD/.lego for storage. Overridable through --path. --- .gitignore | 2 ++ cli.go | 33 ++++++++++----------------------- cli_handlers.go | 2 +- configuration.go | 2 +- path_unix.go | 11 ----------- path_windows.go | 13 ------------- 6 files changed, 14 insertions(+), 49 deletions(-) delete mode 100644 path_unix.go delete mode 100644 path_windows.go diff --git a/.gitignore b/.gitignore index 31e1e36d..e7e52772 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ lego.exe +lego +.lego diff --git a/cli.go b/cli.go index acccb33b..2314634a 100644 --- a/cli.go +++ b/cli.go @@ -3,6 +3,7 @@ package main import ( "log" "os" + "path" "github.com/codegangsta/cli" ) @@ -25,6 +26,12 @@ func main() { app.Usage = "Let's encrypt client to go!" app.Version = "0.0.1" + cwd, err := os.Getwd() + if err != nil { + logger().Fatal("Could not determine current working directory. Please pass --path.") + } + defaultPath := path.Join(cwd, ".lego") + app.Commands = []cli.Command{ { Name: "run", @@ -109,29 +116,9 @@ func main() { Usage: "Skip the end user license agreement screen.", }, cli.StringFlag{ - Name: "config-dir", - Value: configDir, - Usage: "Configuration directory.", - }, - cli.StringFlag{ - Name: "work-dir", - Value: workDir, - Usage: "Working directory.", - }, - cli.StringFlag{ - Name: "backup-dir", - Value: backupDir, - Usage: "Configuration backups directory.", - }, - cli.StringFlag{ - Name: "key-dir", - Value: keyDir, - Usage: "Keys storage.", - }, - cli.StringFlag{ - Name: "cert-dir", - Value: certDir, - Usage: "Certificates storage.", + Name: "path", + Usage: "Directory to use for storing the data", + Value: defaultPath, }, } diff --git a/cli_handlers.go b/cli_handlers.go index ba637885..a07db368 100644 --- a/cli_handlers.go +++ b/cli_handlers.go @@ -17,7 +17,7 @@ func checkFolder(path string) error { } func run(c *cli.Context) { - err := checkFolder(c.GlobalString("config-dir")) + err := checkFolder(c.GlobalString("path")) if err != nil { logger().Fatalf("Cound not check/create path: %v", err) } diff --git a/configuration.go b/configuration.go index 75760ea1..b22a2ae2 100644 --- a/configuration.go +++ b/configuration.go @@ -34,7 +34,7 @@ func (c *Configuration) ServerPath() string { // AccountsPath returns the OS dependent path to the // local accounts for a specific CA func (c *Configuration) AccountsPath() string { - return path.Join(c.context.GlobalString("config-dir"), "accounts", c.ServerPath()) + return path.Join(c.context.GlobalString("path"), "accounts", c.ServerPath()) } // AccountPath returns the OS dependent path to a particular account diff --git a/path_unix.go b/path_unix.go deleted file mode 100644 index dedb388f..00000000 --- a/path_unix.go +++ /dev/null @@ -1,11 +0,0 @@ -// +build !windows - -package main - -var ( - configDir = "/etc/letsencrypt" - workDir = "/var/lib/letsencrypt" - backupDir = "/var/lib/letsencrypt/backups" - keyDir = "/etc/letsencrypt/keys" - certDir = "/etc/letsencrypt/certs" -) diff --git a/path_windows.go b/path_windows.go deleted file mode 100644 index 77c95b40..00000000 --- a/path_windows.go +++ /dev/null @@ -1,13 +0,0 @@ -// +build !linux - -package main - -import "os" - -var ( - configDir = os.ExpandEnv("${PROGRAMDATA}\\letsencrypt") - workDir = os.ExpandEnv("${PROGRAMDATA}\\letsencrypt") - backupDir = os.ExpandEnv("${PROGRAMDATA}\\letsencrypt\\backups") - keyDir = os.ExpandEnv("${PROGRAMDATA}\\letsencrypt\\keys") - certDir = os.ExpandEnv("${PROGRAMDATA}\\letsencrypt\\certs") -)