Skip to content

Commit

Permalink
Fix numbers and quoting in gitlab.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
David Gubler committed Apr 3, 2017
1 parent 39145e6 commit d5b089c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
4 changes: 2 additions & 2 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
it { is_expected.to contain_file('/etc/gitlab/gitlab.rb') \
.with_content(/^\s*gitlab_rails\['ldap_enabled'\] = true$/)
.with_content(/^\s*gitlab_rails\['ldap_servers'\] = YAML.load <<-EOS\n main:\n active_directory: true\n allow_username_or_email_login: false\n base: \"\"\n bind_dn: \"_the_full_dn_of_the_user_you_will_bind_with\"\n block_auto_created_users: false\n host: \"_your_ldap_server\"\n label: LDAP\n method: plain\n password: \"_the_password_of_the_bind_user\"\n port: \"?389\"?\n uid: sAMAccountName\n user_filter: \"\"\nEOS\n/m)
.with_content(/^\s*gitlab_rails\['omniauth_providers'\] = \[{\"name\"=>\"google_oauth2\", \"app_id\"=>\"YOUR APP ID\", \"app_secret\"=>\"YOUR APP SECRET\", \"args\"=>{\"access_type\"=>\"offline\", \"approval_prompt\"=>\"\"}}\]$/)
.with_content(/^\s*gitlab_rails\['omniauth_providers'\] = \[{\"app_id\"=>\"YOUR APP ID\", \"app_secret\"=>\"YOUR APP SECRET\", \"args\"=>{\"access_type\"=>\"offline\", \"approval_prompt\"=>\"\"}, \"name\"=>\"google_oauth2\"}\]$/)
}
end
describe 'gitlab_git_http_server with hash value' do
Expand All @@ -234,7 +234,7 @@
}}}

it { is_expected.to contain_file('/etc/gitlab/gitlab.rb') \
.with_content(/^\s*gitlab_rails\['backup_path'\] = \'\/opt\/gitlab_backup\'$/)
.with_content(/^\s*gitlab_rails\['backup_path'\] = "\/opt\/gitlab_backup"$/)
}
end
describe 'rack_attack_git_basic_auth with Numbers and Strings' do
Expand Down
34 changes: 13 additions & 21 deletions templates/gitlab.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,20 @@ def sort_hash_by_key(hash, deep=true, &block)
end
end

def numify(obj)
if obj.is_a?(String)
Integer(obj) rescue Float(obj) rescue obj
elsif obj.is_a?(Array)
obj.map { |item| numify(item) }
elsif obj.is_a?(Hash)
sort_hash_by_key(obj.merge(obj) { |_, v| numify(v) })
else
obj
end
end

def decorate(v)
if v =~ /\AYAML/
return v
elsif v =~ /^[\d]+$/
return Integer(v)
elsif v.is_a?(String)
return "'#{v}'"
elsif v.is_a?(Array)
temp = []
v.each { |elem|
temp.push(decorate(elem))
}
return v
elsif v.is_a?(Hash)
temp = {}
v.each { |k, val|
temp[k] = val
}
return sort_hash_by_key(temp)
else
return v
end
numify(v).inspect
end
-%>

Expand Down

0 comments on commit d5b089c

Please sign in to comment.