Lego: .lego directory location

Created on 28 Nov 2019  路  4Comments  路  Source: go-acme/lego

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

arecli breaking-change enhancement

Most helpful comment

Why is that?

  • Processes invoking lego on existing installations would continue to use ./.lego.
  • Processes on new installations would create and subsequently use ~/.config/lego.
  • Automated processes should be configured to use --path.

Am I missing a use case?

All 4 comments

hello,

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

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

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

Why is that?

  • Processes invoking lego on existing installations would continue to use ./.lego.
  • Processes on new installations would create and subsequently use ~/.config/lego.
  • Automated processes should be configured to use --path.

Am I missing a use case?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

voltagex picture voltagex  路  3Comments

kop picture kop  路  5Comments

moomerman picture moomerman  路  4Comments

onlyjob picture onlyjob  路  3Comments

athanp picture athanp  路  3Comments