Module: LocalVault::Config
- Defined in:
- lib/localvault/config.rb
Overview
Global configuration — paths, default vault, API credentials.
Reads/writes ~/.localvault/config.yml (mode 0600). All directories are created with mode 0700. Override the root path with LOCALVAULT_HOME env var.
Constant Summary collapse
- CONFIG_FILE =
"config.yml"
Class Method Summary collapse
-
.api_url ⇒ String
Read the InventList API base URL.
-
.api_url=(url) ⇒ void
Set the InventList API base URL.
-
.config_path ⇒ String
Path to the global config file.
-
.default_vault ⇒ String
Name of the default vault.
-
.default_vault=(name) ⇒ void
Set the default vault name.
-
.ensure_directories! ⇒ void
Create the root, vaults, and keys directories if they don’t exist (mode 0700).
-
.inventlist_handle ⇒ String?
Read the InventList user handle.
-
.inventlist_handle=(h) ⇒ void
Set the InventList user handle.
-
.keys_path ⇒ String
Path to the directory containing identity keys.
-
.load ⇒ Hash
Load the config file as a hash.
-
.root_path ⇒ String
Root directory for all LocalVault data.
-
.save(data) ⇒ void
Write config data to disk (mode 0600).
-
.token ⇒ String?
Read the API authentication token.
-
.token=(t) ⇒ void
Set the API authentication token.
-
.vaults_path ⇒ String
Path to the directory containing all vaults.
Class Method Details
.api_url ⇒ String
Read the InventList API base URL.
128 129 130 |
# File 'lib/localvault/config.rb', line 128 def self.api_url load.fetch("api_url", "https://inventlist.com") end |
.api_url=(url) ⇒ void
This method returns an undefined value.
Set the InventList API base URL.
136 137 138 139 140 |
# File 'lib/localvault/config.rb', line 136 def self.api_url=(url) data = load data["api_url"] = url save(data) end |
.config_path ⇒ String
Path to the global config file.
29 30 31 |
# File 'lib/localvault/config.rb', line 29 def self.config_path File.join(root_path, CONFIG_FILE) end |
.default_vault ⇒ String
Name of the default vault.
68 69 70 |
# File 'lib/localvault/config.rb', line 68 def self.default_vault load.fetch("default_vault", "default") end |
.default_vault=(name) ⇒ void
This method returns an undefined value.
Set the default vault name.
76 77 78 79 80 |
# File 'lib/localvault/config.rb', line 76 def self.default_vault=(name) data = load data["default_vault"] = name save(data) end |
.ensure_directories! ⇒ void
This method returns an undefined value.
Create the root, vaults, and keys directories if they don’t exist (mode 0700).
85 86 87 88 89 |
# File 'lib/localvault/config.rb', line 85 def self.ensure_directories! FileUtils.mkdir_p(root_path, mode: 0o700) FileUtils.mkdir_p(vaults_path, mode: 0o700) FileUtils.mkdir_p(keys_path, mode: 0o700) end |
.inventlist_handle ⇒ String?
Read the InventList user handle.
111 112 113 |
# File 'lib/localvault/config.rb', line 111 def self.inventlist_handle load["inventlist_handle"] end |
.inventlist_handle=(h) ⇒ void
This method returns an undefined value.
Set the InventList user handle.
119 120 121 122 123 |
# File 'lib/localvault/config.rb', line 119 def self.inventlist_handle=(h) data = load data["inventlist_handle"] = h save(data) end |
.keys_path ⇒ String
Path to the directory containing identity keys.
43 44 45 |
# File 'lib/localvault/config.rb', line 43 def self.keys_path File.join(root_path, "keys") end |
.load ⇒ Hash
Load the config file as a hash.
50 51 52 53 |
# File 'lib/localvault/config.rb', line 50 def self.load return {} unless File.exist?(config_path) YAML.safe_load_file(config_path, permitted_classes: [Symbol]) || {} end |
.root_path ⇒ String
Root directory for all LocalVault data. Honors LOCALVAULT_HOME env var.
22 23 24 |
# File 'lib/localvault/config.rb', line 22 def self.root_path ENV.fetch("LOCALVAULT_HOME") { File.join(Dir.home, ".localvault") } end |
.save(data) ⇒ void
This method returns an undefined value.
Write config data to disk (mode 0600).
59 60 61 62 63 |
# File 'lib/localvault/config.rb', line 59 def self.save(data) FileUtils.mkdir_p(root_path, mode: 0o700) File.write(config_path, YAML.dump(data)) File.chmod(0o600, config_path) end |
.token ⇒ String?
Read the API authentication token.
94 95 96 |
# File 'lib/localvault/config.rb', line 94 def self.token load["token"] end |
.token=(t) ⇒ void
This method returns an undefined value.
Set the API authentication token.
102 103 104 105 106 |
# File 'lib/localvault/config.rb', line 102 def self.token=(t) data = load data["token"] = t save(data) end |
.vaults_path ⇒ String
Path to the directory containing all vaults.
36 37 38 |
# File 'lib/localvault/config.rb', line 36 def self.vaults_path File.join(root_path, "vaults") end |