@@ -5,7 +5,8 @@ module Web
55 ##
66 # Environment validation for html2rss-web
77 # Handles validation of environment variables and configuration
8- module EnvironmentValidator
8+ module EnvironmentValidator # rubocop:disable Metrics/ModuleLength
9+ # rubocop:disable Metrics/ClassLength
910 class << self
1011 ##
1112 # Validate required environment variables on startup
@@ -28,6 +29,7 @@ def validate_production_security!
2829
2930 validate_secret_key!
3031 validate_account_configuration!
32+ validate_build_metadata!
3133 end
3234
3335 # @return [Boolean]
@@ -92,6 +94,15 @@ def validate_secret_key!
9294 exit 1
9395 end
9496
97+ # @return [void]
98+ def validate_build_metadata!
99+ return unless missing_build_metadata?
100+
101+ log_missing_build_metadata!
102+ warn_lines ( *missing_build_metadata_warning_lines )
103+ exit 1
104+ end
105+
95106 def validate_account_configuration!
96107 accounts = AccountManager . accounts
97108 weak_tokens = accounts . select { |acc | acc [ :token ] . length < 16 }
@@ -128,7 +139,34 @@ def handle_weak_account_tokens!(weak_tokens)
128139 )
129140 exit 1
130141 end
142+
143+ # @return [Boolean]
144+ def missing_build_metadata?
145+ build_metadata_values . any? ( &:empty? )
146+ end
147+
148+ # @return [Array<String>]
149+ def build_metadata_values
150+ %w[ BUILD_TAG GIT_SHA ] . map { |key | ENV . fetch ( key , '' ) . strip }
151+ end
152+
153+ # @return [void]
154+ def log_missing_build_metadata!
155+ SecurityLogger . log_config_validation_failure (
156+ 'build_metadata' ,
157+ 'Missing BUILD_TAG or GIT_SHA'
158+ )
159+ end
160+
161+ # @return [Array<String>]
162+ def missing_build_metadata_warning_lines
163+ [
164+ 'CRITICAL: Missing build metadata for production deployment!' ,
165+ 'Set BUILD_TAG to the release build tag and GIT_SHA to the deployed commit SHA.'
166+ ]
167+ end
131168 end
169+ # rubocop:enable Metrics/ClassLength
132170 end
133171 end
134172end
0 commit comments