go-acme / lego

Let's Encrypt/ACME client and library written in Go
https://go-acme.github.io/lego/
MIT License
7.87k stars 1.01k forks source link

.lego directory location #1016

Open Threnklyn opened 4 years ago

Threnklyn commented 4 years ago

Hello, I noticed the lego directory containing accounts and certificates get saved at the current working directory. This might introduce inconsistency depending on the location you run it. Saving the directory under $HOME like many other programs might be favorable. Regards

ldez commented 4 years ago

hello,

I understand your point, it's a breaking change so we will not introduce it quickly.

dmke commented 4 years ago

Could we change the mechanism for determining the path location to prefer $PWD/.lego, and if that doesn't exist fallback to $HOME/.lego (or actually $XDG_CONFIG_HOME/lego on Linux)? This way existing installations would continue to work. Of course, --path still takes precedence.

In full, the code would look like this:

def default_path
  # $PWD/.lego
  if (local = Pathname.new(__dir__).join(".lego")).exist?
    return local
  end

  # Linux: ${XDG_CONFIG_HOME:-$HOME/config}/lego
  home = Pathname.new ENV.fetch("HOME")
  if Etc.uname[:sysname] == "Linux"
    xdg = ENV.fetch("XDG_CONFIG_HOME", home.join(".config")))
    return Pathname.new(xdg).join("lego")
  end

  # Windows: %AppData%\Roaming\lego
  if Etc.uname[:sysname] == "Windows"
    return Pathname.new(ENV.fetch("APPDATA")).join("Roaming/lego")
  end

  # other: $HOME/.lego
  home.join(".lego")
end

(This is pseudo-code in Ruby, the actual implementation could make use of appropriate build tags and e.g. implement the Linux-specific code in config_dir_linux.go to get rid of runtime conditionals.)

ldez commented 4 years ago

Currently the ./.lego folder is created if this folder don't exist, so a fallback it's not possible without breaking the current behavior.

dmke commented 4 years ago

Why is that?

Am I missing a use case?