Module: BeltConfig
- Defined in:
- lib/brainiac/handlers/shared/belt.rb
Overview
Configuration for Belt ephemeral environments. Stored in ~/.brainiac/basecamp.json under the "deploy" key.
Constant Summary collapse
- BRAINIAC_DIR =
ENV.fetch("BRAINIAC_DIR", File.join(Dir.home, ".brainiac"))
- BASECAMP_CONFIG_FILE =
File.join(BRAINIAC_DIR, "basecamp.json")
Class Method Summary collapse
-
.ephemeral_deploys_enabled? ⇒ Boolean
Check if ephemeral deploys are enabled globally.
-
.ephemeral_env?(env_name) ⇒ Boolean
Check if an environment is ephemeral.
-
.ephemeral_env_for_card(card_number) ⇒ String?
Find ephemeral environment by card number.
-
.ephemeral_env_for_epic(epic_number) ⇒ String?
Find ephemeral environment by epic number.
-
.ephemeral_env_info(env_name) ⇒ Hash?
Get ephemeral environment metadata.
-
.load_config ⇒ Hash
Load the basecamp config, caching for performance.
-
.mark_ephemeral_destroyed(env_name) ⇒ Object
Mark an ephemeral environment as destroyed.
-
.parent_env_for(project_key) ⇒ String?
Get the parent environment for a project (used as base for ephemeral envs).
-
.track_ephemeral_env(env_name, metadata = {}) ⇒ Object
Track an ephemeral environment in deployment state.
Class Method Details
.ephemeral_deploys_enabled? ⇒ Boolean
Check if ephemeral deploys are enabled globally.
100 101 102 103 104 105 |
# File 'lib/brainiac/handlers/shared/belt.rb', line 100 def ephemeral_deploys_enabled? config = load_config # Default to true if deploy section exists but enabled isn't specified deploy_config = config["deploy"] || {} deploy_config.fetch("ephemeral_enabled", true) end |
.ephemeral_env?(env_name) ⇒ Boolean
Check if an environment is ephemeral.
127 128 129 130 131 132 133 134 135 |
# File 'lib/brainiac/handlers/shared/belt.rb', line 127 def ephemeral_env?(env_name) state_file = File.join(BRAINIAC_DIR, "ephemeral_envs.json") return false unless File.exist?(state_file) state = JSON.parse(File.read(state_file)) state.key?(env_name) && state[env_name]["status"] == "active" rescue StandardError false end |
.ephemeral_env_for_card(card_number) ⇒ String?
Find ephemeral environment by card number.
170 171 172 |
# File 'lib/brainiac/handlers/shared/belt.rb', line 170 def ephemeral_env_for_card(card_number) "fizzy-#{card_number}" end |
.ephemeral_env_for_epic(epic_number) ⇒ String?
Find ephemeral environment by epic number.
177 178 179 |
# File 'lib/brainiac/handlers/shared/belt.rb', line 177 def ephemeral_env_for_epic(epic_number) "epic-#{epic_number}" end |
.ephemeral_env_info(env_name) ⇒ Hash?
Get ephemeral environment metadata.
140 141 142 143 144 145 146 147 148 |
# File 'lib/brainiac/handlers/shared/belt.rb', line 140 def ephemeral_env_info(env_name) state_file = File.join(BRAINIAC_DIR, "ephemeral_envs.json") return nil unless File.exist?(state_file) state = JSON.parse(File.read(state_file)) state[env_name] rescue StandardError nil end |
.load_config ⇒ Hash
Load the basecamp config, caching for performance.
79 80 81 82 83 84 85 86 |
# File 'lib/brainiac/handlers/shared/belt.rb', line 79 def load_config return {} unless File.exist?(BASECAMP_CONFIG_FILE) JSON.parse(File.read(BASECAMP_CONFIG_FILE)) rescue JSON::ParserError => e LOG.error "[Belt] Failed to parse basecamp.json: #{e.message}" if defined?(LOG) {} end |
.mark_ephemeral_destroyed(env_name) ⇒ Object
Mark an ephemeral environment as destroyed.
152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
# File 'lib/brainiac/handlers/shared/belt.rb', line 152 def mark_ephemeral_destroyed(env_name) state_file = File.join(BRAINIAC_DIR, "ephemeral_envs.json") return unless File.exist?(state_file) state = JSON.parse(File.read(state_file)) return unless state[env_name] state[env_name]["status"] = "destroyed" state[env_name]["destroyed_at"] = Time.now.iso8601 File.write(state_file, JSON.pretty_generate(state)) rescue StandardError => e LOG.error "[Belt] Failed to mark ephemeral env destroyed: #{e.message}" if defined?(LOG) end |
.parent_env_for(project_key) ⇒ String?
Get the parent environment for a project (used as base for ephemeral envs).
This is where belt g environment <name> <parent> copies settings from.
93 94 95 96 |
# File 'lib/brainiac/handlers/shared/belt.rb', line 93 def parent_env_for(project_key) config = load_config config.dig("deploy", "project_envs", project_key) end |
.track_ephemeral_env(env_name, metadata = {}) ⇒ Object
Track an ephemeral environment in deployment state.
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/brainiac/handlers/shared/belt.rb', line 110 def track_ephemeral_env(env_name, = {}) state_file = File.join(BRAINIAC_DIR, "ephemeral_envs.json") state = File.exist?(state_file) ? JSON.parse(File.read(state_file)) : {} state[env_name] = { "created_at" => Time.now.iso8601, "status" => "active" }.merge() File.write(state_file, JSON.pretty_generate(state)) rescue StandardError => e LOG.error "[Belt] Failed to track ephemeral env: #{e.message}" if defined?(LOG) end |