Skip to content

Commit

Permalink
Merge pull request #52 from msutter/sort_hash_inspect_in_config_file
Browse files Browse the repository at this point in the history
As this template is writing a config file based on some hashes and ha…
  • Loading branch information
tobru committed Jan 22, 2016
2 parents 1bf5e8c + 8563e43 commit df82805
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
6 changes: 3 additions & 3 deletions spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
:lsbdistid => 'debian',
:lsbdistcodename => 'jessie',
}}
it { is_expected.to contain_file('/etc/gitlab/gitlab.rb') }

describe 'edition = ce' do
let(:params) { {:edition => 'ce'} }
it { is_expected.to contain_package('gitlab-ce').with_ensure('installed') }
Expand Down Expand Up @@ -155,8 +155,8 @@

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'\] = {"main"=>{"label"=>"LDAP", "host"=>"_your_ldap_server", "port"=>(")?389(")?, "uid"=>"sAMAccountName", "method"=>"plain", "bind_dn"=>"_the_full_dn_of_the_user_you_will_bind_with", "password"=>"_the_password_of_the_bind_user", "active_directory"=>true, "allow_username_or_email_login"=>false, "block_auto_created_users"=>false, "base"=>"", "user_filter"=>""}}$/)
.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\['ldap_servers'\] = {\"main\"=>{\"active_directory\"=>true, \"allow_username_or_email_login\"=>false, \"base\"=>\"\", \"bind_dn\"=>\"_the_full_dn_of_the_user_you_will_bind_with\", \"block_auto_created_users\"=>false, \"host\"=>\"_your_ldap_server\", \"label\"=>\"LDAP\", \"method\"=>\"plain\", \"password\"=>\"_the_password_of_the_bind_user\", \"port\"=>(")?389(")?, \"uid\"=>\"sAMAccountName\", \"user_filter\"=>\"\"}}$/)
.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 Down
16 changes: 14 additions & 2 deletions templates/gitlab.rb.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
## THIS CONFIGURATION IS MANAGED BY PUPPET
# for all possible paramters, see:
# https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/files/gitlab-config-template/gitlab.rb.template
<%- def decorate(v)
<%-
# As this template is writing a config file based on some hashes and hashes are not meant to be in a certain order,
# We need to ensure that the order of the keys are always outputed in the same order.
# Otherwise puppet will always update(change) the config file.
def sort_nested_hash_inspect(h)
if h.class.name == 'Hash'
"{" + h.sort.map{|key, value| "\"#{key}\"=>#{sort_nested_hash_inspect(value)}"}.join(", ") + "}"
else
h.inspect
end
end

def decorate(v)
if v =~ /\AYAML/
return v
elsif v.is_a?(String)
Expand All @@ -13,7 +25,7 @@
}
return "[#{temp.join(',')}]"
elsif v.is_a?(Hash)
return v.inspect
return sort_nested_hash_inspect(v)
else
return v
end
Expand Down

0 comments on commit df82805

Please sign in to comment.