141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/jfrog/saas/log/collector.rb', line 141
def validate(config_file)
config_valid = true
config_file_yaml = YAML.load_file(config_file)
config_in_json = config_file_yaml.to_json
config_schema_file = File.open((File.join(File.dirname(__FILE__), 'config.template.schema.json')))
MessageUtils.instance.put_message(MessageUtils::VALIDATION_SCHEMA_FILE_DETAIL, { "param1": (File.join(File.dirname(__FILE__), 'config.template.schema.json')).to_s,
"#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_INFO,
"#{MessageUtils::SOLUTION}": MessageUtils::SOLUTION_OVERRIDE_INIT })
config_schema = JSON.parse(config_schema_file.read)
if !config_schema.nil? && !config_in_json.nil?
begin
JSON::Validator.validate!(config_schema, config_in_json)
jpd_url = (config_file_yaml['connection']['jpd_url']).to_s.strip
if jpd_whitelisted(jpd_url)
config_valid = true
else
MessageUtils.instance.put_message(MessageUtils::CONFIG_FILE_VALIDATION_FAILED_DETAILS, { "param1": "#{config_file.to_s} contains JPD URL which is not permitted",
"#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_ERROR,
"#{MessageUtils::SOLUTION}": MessageUtils::SOLUTION_OVERRIDE_TERMINATE })
config_valid = false
end
rescue JSON::Schema::ValidationError
MessageUtils.instance.put_message(MessageUtils::CONFIG_FILE_VALIDATION_FAILED_DETAILS, { "param1": $ERROR_INFO.message,
"#{MessageUtils::LOG_LEVEL}": CommonUtils::LOG_ERROR,
"#{MessageUtils::SOLUTION}": MessageUtils::SOLUTION_OVERRIDE_TERMINATE })
end
end
config_valid
end
|