diff --git a/lib/jenkins_api_client/client.rb b/lib/jenkins_api_client/client.rb index 53be5e4d..b9edcdaa 100644 --- a/lib/jenkins_api_client/client.rb +++ b/lib/jenkins_api_client/client.rb @@ -100,6 +100,7 @@ class Client # @raise [ArgumentError] when required options are not provided. # def initialize(args) + args = symbolize_keys(args) args.each do |key, value| if value && VALID_PARAMS.include?(key.to_s) instance_variable_set("@#{key}", value) @@ -683,6 +684,25 @@ def refresh_crumbs(force_refresh = false) end end + # Private method. Converts keys passed in as strings into symbols. + # + # @param hash [Hash] Hash containing arguments to login to jenkins. + # + def symbolize_keys(hash) + hash.inject({}){|result, (key, value)| + new_key = case key + when String then key.to_sym + else key + end + new_value = case value + when Hash then symbolize_keys(value) + else value + end + result[new_key] = new_value + result + } + end + # Private method that handles the exception and raises with proper error # message with the type of exception and returns the required values if no # exceptions are raised. diff --git a/scripts/login_with_irb.rb b/scripts/login_with_irb.rb index aff8f0cc..a4c51304 100644 --- a/scripts/login_with_irb.rb +++ b/scripts/login_with_irb.rb @@ -38,8 +38,9 @@ def get_from_stdin(prompt, mask = false) end begin - client_opts = YAML.load_file(File.expand_path(config_file)) - unless client_opts.has_key?(:username) + client_opts = Hash[YAML.load_file(File.expand_path(config_file)).map { | (k,v) | [k.to_sym, v]} ] + + unless client_opts.has_key?(:username) client_opts[:username] = prompt_for_username() end unless client_opts.has_key?(:password) or client_opts.has_key?(:password_base64)