module State
Represents a single public/private key pair for a given hostname.
Definitions
def self.path(env = ENV)
Where to store the key pair on the filesystem. This is a subdirectory of $XDG_STATE_HOME, or ~/.local/state/ when that's not defined.
Ensures that the directory to store the certificate exists. If the legacy directory (~/.localhost/) exists, it is moved into the new XDG Basedir compliant directory.
Signature
-
parameter
env
Hash
The environment to use for configuration.
Implementation
def self.path(env = ENV)
path = File.expand_path("localhost.rb", env.fetch("XDG_STATE_HOME", "~/.local/state"))
unless File.directory?(path)
FileUtils.mkdir_p(path, mode: 0700)
end
return path
end
def self.purge(env = ENV)
Delete the directory where the key pair is stored.
Signature
-
parameter
env
Hash
The environment to use for configuration.
Implementation
def self.purge(env = ENV)
path = self.path(env)
FileUtils.rm_rf(path)
end