Commit 812b7e11 authored by DJ Mountney's avatar DJ Mountney

Add exception handling for psych errors

For validating the contents passed to ldap write
parent 9a98dba1
......@@ -76,8 +76,15 @@ module Gitlab
end
def validate_contents(contents)
config = YAML.safe_load(contents, permitted_classes: [Symbol])
puts "WARNING: Content was not a valid LDAP secret yml file." if config.nil? || !config.is_a?(Hash)
begin
config = YAML.safe_load(contents, permitted_classes: [Symbol])
error_contents = "Did not include any key-value pairs" unless config.is_a?(Hash)
rescue Psych::Exception => e
error_contents = e.message
end
puts "WARNING: Content was not a valid LDAP secret yml file. #{error_contents}" if error_contents
contents
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment