Commit 064023e49718558286de994411609ff25aecbc81

Authored by Luciano Prestes
Committed by Thiago Ribeiro
1 parent 9b82b2e5

Create noosfero-admin and get this private_token

Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Signed-off-by: Thiago Ribeiro <thiagitosouza@gmail.com>
cookbooks/colab/recipes/default.rb
... ... @@ -96,20 +96,52 @@ execute &#39;create-admin-token-gitlab&#39; do
96 96 user 'git'
97 97 end
98 98  
  99 +execute 'create-admin-token-noosfero' do
  100 + user = "admin-noosfero"
  101 + email = "admin-noosfero@example.com"
  102 + password = SecureRandom.random_number.to_s
  103 +
  104 + command "bundle exec rails c production <<EOF
  105 + user = User.create(login: \'#{user}\', email: \'#{email}\', password: \'#{password}\', password_confirmation: \'#{password}\')
  106 + user.activate
  107 + user.generate_private_token_if_not_exist
  108 + Environment.default.add_admin user.person
  109 + exit
  110 + "
  111 +
  112 + user_exist = lambda do
  113 + Dir.chdir '/usr/lib/noosfero' do
  114 + `RAILS_ENV=production bundle exec rails runner \"puts User.find_by_identifier(\'admin-noosdero\').nil?\"`.strip
  115 + end
  116 + end
  117 +
  118 + not_if {user_exist.call == "false"}
  119 +
  120 + cwd '/usr/lib/noosfero'
  121 + user 'noosfero'
  122 +end
  123 +
99 124 template '/etc/colab/settings.d/01-apps.yaml' do
100 125 owner 'root'
101 126 group 'colab'
102 127 mode 0640
103 128 notifies :restart, 'service[colab]'
104 129  
105   - get_private_token = lambda do
  130 + get_gitlab_private_token = lambda do
106 131 Dir.chdir '/usr/lib/gitlab' do
107 132 `sudo -u git RAILS_ENV=production bundle exec rails runner \"puts User.find_by_name(\'admin-gitlab\').private_token\"`.strip
108 133 end
109 134 end
110 135  
  136 + get_noosfero_private_token = lambda do
  137 + Dir.chdir '/usr/lib/noosfero' do
  138 + `sudo -u noosfero RAILS_ENV=production bundle exec rails runner \"puts User.find_by_name(\'admin-noosfero\').private_token\"`.strip
  139 + end
  140 + end
  141 +
111 142 variables(
112   - :get_private_token => get_private_token
  143 + :get_gitlab_private_token => get_gitlab_private_token,
  144 + :get_noosfero_private_token => get_noosfero_private_token
113 145 )
114 146 end
115 147  
... ...
cookbooks/colab/templates/01-apps.yaml.erb
... ... @@ -2,6 +2,7 @@
2 2 PROXIED_APPS:
3 3 gitlab:
4 4 upstream: 'http://<%= node['peers']['integration'] %>:81/gitlab/'
5   - private_token: '<%= @get_private_token.call %>'
  5 + private_token: '<%= @get_gitlab_private_token.call %>'
6 6 noosfero:
7 7 upstream: 'http://<%= node['peers']['social'] %>:80/social/'
  8 + private_token: '<%= @get_noosfero_private_token.call %>'
... ...