gitlab_config 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72d6d03d55ccd88f54eadf815b61659bdad65fb6
4
- data.tar.gz: 560d18b385a93223df9f96de1f4e05f0690a5c4e
3
+ metadata.gz: 62e1f212b333bd9501445ed36e3c2bd547f1515a
4
+ data.tar.gz: 4caffbd0f2ba687452cf3d49e0fb64e755dab5ae
5
5
  SHA512:
6
- metadata.gz: 288d9ff7481ea99c08e7e1ccabaf90c296cf4d527956becc7a33635d2fe64d59a1ca62f7b15052ddc40b860746e2aa2cc2f5fa07bc90d311b0c3488c7be314b0
7
- data.tar.gz: 87901f2249b6ba9820c047adcce112c7b581acb7fc8b4acc50e645dd09d08fe845fcc233be084cd794d16fed7ab2b1d8b2e810eaef83293e5cb05bfe5e40974e
6
+ metadata.gz: f2cacee770a19b2723d7a9dffa3184b9d258d6e4a1e8330b327679c4caa0a2c3c23cc47b1f5af3ca2475ae34a6440de6b25e3f0f0dc2072261bbd6a53a594d2f
7
+ data.tar.gz: 94d051a2624bd7c0dc7afe7aa8ea3ff4d239e075e80c8418466b52635dc915b12488ed79152e6d04821a1c85293cde70775ae02e122308ec037ace2c68f249c9
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .byebug_history
@@ -20,4 +20,5 @@ Gem::Specification.new do |spec|
20
20
  spec.add_development_dependency "bundler", "~> 1.11"
21
21
  spec.add_development_dependency "rake", "~> 10.0"
22
22
  spec.add_development_dependency "rspec", "~> 3.0"
23
+ spec.add_development_dependency 'byebug'
23
24
  end
data/lib/gitlab_config.rb CHANGED
@@ -5,20 +5,18 @@ require 'gitlab_config/aws/iam_role'
5
5
  module GitlabConfig
6
6
  def self.load_configuration(options)
7
7
  if options.fetch(:source) == :s3 and options.has_key?(:iam_role)
8
- options = fetch_iam_parameters(options)
8
+ options = add_iam_configuration!(options)
9
9
  end
10
10
 
11
- yield Configuration.new.get_configuration(options)
11
+ yield Configuration.new(options).get_configuration
12
12
  end
13
13
 
14
- def self.fetch_iam_parameters(options)
14
+ def self.add_iam_configuration!(options)
15
15
  key = options.fetch(:key, nil)
16
16
  secret = options.fetch(:secret, nil)
17
17
 
18
18
  if key.nil? && secret.nil?
19
- iam = IamRole.new(options.fetch(:iam_role))
20
- options[:key] = iam.key
21
- options[:secret] = iam.secret
19
+ options[:iam] = IamRole.new(options.fetch(:iam_role))
22
20
  end
23
21
  options
24
22
  end
@@ -3,6 +3,10 @@ require 'json'
3
3
 
4
4
  module GitlabConfig
5
5
 
6
+ # Iam role is used to get the credentials for the node and use them in the configuration elsewhere
7
+ #
8
+ # In order to get the correct credentials it is necessary to call an AWS api that will return them. See:
9
+ # http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html
6
10
  class IamRole
7
11
 
8
12
  AWS_URL = 'http://169.254.169.254/latest/meta-data/iam/security-credentials'
@@ -5,25 +5,52 @@ module GitlabConfig
5
5
 
6
6
  class Configuration
7
7
 
8
- def get_configuration(options)
9
- source(options).get_configuration(options)
8
+ def initialize(options)
9
+ @options = options
10
+ end
11
+
12
+ def get_configuration
13
+ configuration = source.get_configuration(@options)
14
+
15
+ add_backup_credentials!(configuration) if configuration.respond_to? :fetch
16
+ configuration
10
17
  end
11
18
 
12
19
  private
13
20
 
14
21
  # Get the configuration class
15
- def source(options)
16
- case options.fetch(:source)
22
+ def source
23
+ case @options.fetch(:source)
17
24
  when :custom
18
- options.fetch(:config_source)
25
+ @options.fetch(:config_source)
19
26
  when :s3
20
- S3ConfigurationSource.new(options.fetch(:region), options.fetch(:key), options.fetch(:secret))
27
+ S3ConfigurationSource.new(@options.fetch(:region), iam)
21
28
  when :local
22
29
  LocalSource.new
23
30
  else
24
31
  raise 'Configuration source not set'
25
32
  end
33
+ end
34
+
35
+ def add_backup_credentials!(configuration)
36
+ gitlab_rails_config = configuration.fetch('gitlab_rails', {})
37
+ if gitlab_rails_config.fetch('backup_upload_connection', {}).fetch('provider', nil) == 'AWS'
38
+ if has_iam?
39
+ configuration['gitlab_rails']['backup_upload_connection']['aws_access_key_id'] = iam.key
40
+ configuration['gitlab_rails']['backup_upload_connection']['aws_secret_access_key'] = iam.secret
41
+ end
42
+ end
43
+ configuration
44
+ end
45
+
46
+ # Validate that the options hash has the iam object enabled
47
+ def has_iam?
48
+ iam = @options.fetch(:iam)
49
+ iam.respond_to?(:key) && iam.respond_to?(:secret)
50
+ end
26
51
 
52
+ def iam
53
+ @options.fetch(:iam)
27
54
  end
28
55
 
29
56
  end
@@ -7,10 +7,10 @@ module GitlabConfig
7
7
  #
8
8
  class S3ConfigurationSource
9
9
 
10
- attr_reader :region, :key, :secret
10
+ attr_reader :region, :iam
11
11
 
12
- def initialize(region, key, secret)
13
- @region, @key, @secret = region, key, secret
12
+ def initialize(region, iam)
13
+ @region, @iam = region, iam
14
14
  end
15
15
 
16
16
  # Get configuration will download the file read it
@@ -30,7 +30,7 @@ module GitlabConfig
30
30
  end
31
31
 
32
32
  def credentials
33
- Aws::Credentials.new(@key, @secret)
33
+ Aws::Credentials.new(@iam.key, @iam.secret)
34
34
  end
35
35
 
36
36
  end
@@ -1,3 +1,3 @@
1
1
  module GitlabConfig
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Tarry
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: byebug
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  description: The Gitlab configuration gem can be loaded in the gitlab.rb configuration
70
84
  file to allow dynamic properties to be loaded
71
85
  email: