Commit 759e31b2b8f51e8e61b7c1c13a58ca975f185461

Authored by Jacob Vosmaer
2 parents 5a3db584 96055e7f

Merge branch 'rename_library' into 'master'

Rename Library

Fixes #24
files/gitlab-cookbooks/gitlab/libraries/chef_server.rb
... ... @@ -1,85 +0,0 @@
1   -#
2   -# Copyright:: Copyright (c) 2012 Opscode, Inc.
3   -# License:: Apache License, Version 2.0
4   -#
5   -# Licensed under the Apache License, Version 2.0 (the "License");
6   -# you may not use this file except in compliance with the License.
7   -# You may obtain a copy of the License at
8   -#
9   -# http://www.apache.org/licenses/LICENSE-2.0
10   -#
11   -# Unless required by applicable law or agreed to in writing, software
12   -# distributed under the License is distributed on an "AS IS" BASIS,
13   -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   -# See the License for the specific language governing permissions and
15   -# limitations under the License.
16   -#
17   -
18   -require 'mixlib/config'
19   -require 'chef/mash'
20   -require 'chef/json_compat'
21   -require 'chef/mixin/deep_merge'
22   -require 'securerandom'
23   -
24   -module GitLab
25   - extend(Mixlib::Config)
26   -
27   - bootstrap Mash.new
28   - postgresql Mash.new
29   - redis Mash.new
30   - node nil
31   -
32   - class << self
33   -
34   - # guards against creating secrets on non-bootstrap node
35   - def generate_hex(chars)
36   - SecureRandom.hex(chars)
37   - end
38   -
39   - def generate_secrets(node_name)
40   - existing_secrets ||= Hash.new
41   - if File.exists?("/etc/gitlab/gitlab-secrets.json")
42   - existing_secrets = Chef::JSONCompat.from_json(File.read("/etc/gitlab/gitlab-secrets.json"))
43   - end
44   - existing_secrets.each do |k, v|
45   - v.each do |pk, p|
46   - GitLab[k][pk] = p
47   - end
48   - end
49   -
50   - GitLab['postgresql']['sql_password'] ||= generate_hex(50)
51   -
52   - if File.directory?("/etc/gitlab")
53   - File.open("/etc/gitlab/gitlab-secrets.json", "w") do |f|
54   - f.puts(
55   - Chef::JSONCompat.to_json_pretty({
56   - 'postgresql' => {
57   - 'sql_password' => GitLab['postgresql']['sql_password'],
58   - },
59   - })
60   - )
61   - system("chmod 0600 /etc/gitlab/gitlab-secrets.json")
62   - end
63   - end
64   - end
65   -
66   - def generate_hash
67   - results = { "gitlab" => {} }
68   - [
69   - "bootstrap",
70   - "redis",
71   - "postgresql"
72   - ].each do |key|
73   - rkey = key.gsub('_', '-')
74   - results['gitlab'][rkey] = GitLab[key]
75   - end
76   -
77   - results
78   - end
79   -
80   - def generate_config(node_name)
81   - generate_secrets(node_name)
82   - generate_hash
83   - end
84   - end
85   -end
files/gitlab-cookbooks/gitlab/libraries/gitlab.rb 0 → 100644
... ... @@ -0,0 +1,85 @@
  1 +#
  2 +# Copyright:: Copyright (c) 2012 Opscode, Inc.
  3 +# License:: Apache License, Version 2.0
  4 +#
  5 +# Licensed under the Apache License, Version 2.0 (the "License");
  6 +# you may not use this file except in compliance with the License.
  7 +# You may obtain a copy of the License at
  8 +#
  9 +# http://www.apache.org/licenses/LICENSE-2.0
  10 +#
  11 +# Unless required by applicable law or agreed to in writing, software
  12 +# distributed under the License is distributed on an "AS IS" BASIS,
  13 +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14 +# See the License for the specific language governing permissions and
  15 +# limitations under the License.
  16 +#
  17 +
  18 +require 'mixlib/config'
  19 +require 'chef/mash'
  20 +require 'chef/json_compat'
  21 +require 'chef/mixin/deep_merge'
  22 +require 'securerandom'
  23 +
  24 +module Gitlab
  25 + extend(Mixlib::Config)
  26 +
  27 + bootstrap Mash.new
  28 + postgresql Mash.new
  29 + redis Mash.new
  30 + node nil
  31 +
  32 + class << self
  33 +
  34 + # guards against creating secrets on non-bootstrap node
  35 + def generate_hex(chars)
  36 + SecureRandom.hex(chars)
  37 + end
  38 +
  39 + def generate_secrets(node_name)
  40 + existing_secrets ||= Hash.new
  41 + if File.exists?("/etc/gitlab/gitlab-secrets.json")
  42 + existing_secrets = Chef::JSONCompat.from_json(File.read("/etc/gitlab/gitlab-secrets.json"))
  43 + end
  44 + existing_secrets.each do |k, v|
  45 + v.each do |pk, p|
  46 + Gitlab[k][pk] = p
  47 + end
  48 + end
  49 +
  50 + Gitlab['postgresql']['sql_password'] ||= generate_hex(50)
  51 +
  52 + if File.directory?("/etc/gitlab")
  53 + File.open("/etc/gitlab/gitlab-secrets.json", "w") do |f|
  54 + f.puts(
  55 + Chef::JSONCompat.to_json_pretty({
  56 + 'postgresql' => {
  57 + 'sql_password' => Gitlab['postgresql']['sql_password'],
  58 + },
  59 + })
  60 + )
  61 + system("chmod 0600 /etc/gitlab/gitlab-secrets.json")
  62 + end
  63 + end
  64 + end
  65 +
  66 + def generate_hash
  67 + results = { "gitlab" => {} }
  68 + [
  69 + "bootstrap",
  70 + "redis",
  71 + "postgresql"
  72 + ].each do |key|
  73 + rkey = key.gsub('_', '-')
  74 + results['gitlab'][rkey] = Gitlab[key]
  75 + end
  76 +
  77 + results
  78 + end
  79 +
  80 + def generate_config(node_name)
  81 + generate_secrets(node_name)
  82 + generate_hash
  83 + end
  84 + end
  85 +end
... ...
files/gitlab-cookbooks/gitlab/recipes/default.rb
... ... @@ -26,11 +26,11 @@ directory &quot;/etc/gitlab&quot; do
26 26 action :nothing
27 27 end.run_action(:create)
28 28  
29   -GitLab[:node] = node
  29 +Gitlab[:node] = node
30 30 if File.exists?("/etc/gitlab/gitlab.rb")
31   - GitLab.from_file("/etc/gitlab/gitlab.rb")
  31 + Gitlab.from_file("/etc/gitlab/gitlab.rb")
32 32 end
33   -node.consume_attributes(GitLab.generate_config(node['fqdn']))
  33 +node.consume_attributes(Gitlab.generate_config(node['fqdn']))
34 34  
35 35 if File.exists?("/var/opt/gitlab/bootstrapped")
36 36 node.set['gitlab']['bootstrap']['enable'] = false
... ...