Remove global paths and default to CWD/.lego for storage. Overridable through --path.

This commit is contained in:
xenolf 2015-06-12 23:34:49 +02:00
parent 84c2bceade
commit 805cef4dd6
6 changed files with 14 additions and 49 deletions

2
.gitignore vendored
View file

@ -1 +1,3 @@
lego.exe
lego
.lego

33
cli.go
View file

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

View file

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

View file

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

View file

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

View file

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