gitlab_config 0.1.0 → 0.2.1

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: 3d9513ffeb159990ac5b0f56d1d0df3f37ae07b3
4
- data.tar.gz: 4aaeddd2a0fdee74e78cd75446f6f8271993d7aa
3
+ metadata.gz: 72d6d03d55ccd88f54eadf815b61659bdad65fb6
4
+ data.tar.gz: 560d18b385a93223df9f96de1f4e05f0690a5c4e
5
5
  SHA512:
6
- metadata.gz: 818cb0b5404d94bcedbcea401779ff0754c3442d013e81aa429ddc2c554febcd5729acefecf1750cc98d559497d2a33d7fe403413b3865f319c3e91ab5d518d6
7
- data.tar.gz: 7f2de74ee6cf3f877c8dcac8ceab77cd5215fd075839afdcd4bff9511e5cef4699b32056be40eebc2fb854f8f997e96c7d6eb1af5160df250841e3f221144a5e
6
+ metadata.gz: 288d9ff7481ea99c08e7e1ccabaf90c296cf4d527956becc7a33635d2fe64d59a1ca62f7b15052ddc40b860746e2aa2cc2f5fa07bc90d311b0c3488c7be314b0
7
+ data.tar.gz: 87901f2249b6ba9820c047adcce112c7b581acb7fc8b4acc50e645dd09d08fe845fcc233be084cd794d16fed7ab2b1d8b2e810eaef83293e5cb05bfe5e40974e
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in gitlab_config.gemspec
3
+ # Specify your gem's dependencies in gitlab_config_spec.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -1,36 +1 @@
1
- # GitlabConfig
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gitlab_config`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'gitlab_config'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install gitlab_config
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gitlab_config. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
-
1
+ # Gitlab Config
@@ -4,14 +4,14 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'gitlab_config/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "gitlab_config"
7
+ spec.name = 'gitlab_config'
8
8
  spec.version = GitlabConfig::VERSION
9
9
  spec.authors = ["Andrew Tarry"]
10
10
  spec.email = ["andrew@andrewtarry.com"]
11
11
 
12
12
  spec.summary = %q{Load Gitlab configuration files from anywhere}
13
13
  spec.description = %q{The Gitlab configuration gem can be loaded in the gitlab.rb configuration file to allow dynamic properties to be loaded}
14
- #spec.homepage = "TODO: Put your gem's website or public repo URL here."
14
+ spec.homepage = 'https://github.com/bjss/gitlab_config_gem'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
17
  spec.require_paths = ["lib"]
@@ -0,0 +1,37 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ module GitlabConfig
5
+
6
+ class IamRole
7
+
8
+ AWS_URL = 'http://169.254.169.254/latest/meta-data/iam/security-credentials'
9
+
10
+ def initialize(role)
11
+ @role = role
12
+ end
13
+
14
+ def key
15
+ get_credentials if @key.nil?
16
+ @key
17
+ end
18
+
19
+ def secret
20
+ get_credentials if @secret.nil?
21
+ @secret
22
+ end
23
+
24
+ private
25
+
26
+ def get_credentials
27
+ uri = URI("#{AWS_URL}/#{@role}")
28
+ res = Net::HTTP.get_response(uri)
29
+ body = JSON.parse(res.body)
30
+
31
+ @key = body.fetch('AccessKeyId')
32
+ @secret = body.fethc('AccessKeyId')
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -1,4 +1,5 @@
1
- require "gitlab_config/source/s3"
1
+ require 'gitlab_config/source/s3'
2
+ require 'gitlab_config/source/local'
2
3
 
3
4
  module GitlabConfig
4
5
 
@@ -10,10 +11,15 @@ module GitlabConfig
10
11
 
11
12
  private
12
13
 
14
+ # Get the configuration class
13
15
  def source(options)
14
16
  case options.fetch(:source)
17
+ when :custom
18
+ options.fetch(:config_source)
15
19
  when :s3
16
20
  S3ConfigurationSource.new(options.fetch(:region), options.fetch(:key), options.fetch(:secret))
21
+ when :local
22
+ LocalSource.new
17
23
  else
18
24
  raise 'Configuration source not set'
19
25
  end
@@ -0,0 +1,12 @@
1
+ module GitlabConfig
2
+
3
+ # Read the configuration from a file in the local file system
4
+ #
5
+ class LocalSource
6
+
7
+ def get_configuration(options)
8
+ YAML.load_file(options.fetch(:file))
9
+ end
10
+
11
+ end
12
+ end
@@ -1,16 +1,25 @@
1
1
  require 'yaml'
2
+ require 'aws-sdk'
2
3
 
3
4
  module GitlabConfig
5
+
6
+ # Read the configuration from a file in an s3 bucket
7
+ #
4
8
  class S3ConfigurationSource
5
9
 
10
+ attr_reader :region, :key, :secret
11
+
6
12
  def initialize(region, key, secret)
7
13
  @region, @key, @secret = region, key, secret
8
14
  end
9
15
 
16
+ # Get configuration will download the file read it
10
17
  def get_configuration(options)
11
- download_path = "/tmp/#{file}"
18
+ download_path = "/tmp/#{options.fetch(:file)}"
19
+
12
20
  object = Aws::S3::Object.new(options.fetch(:bucket), options.fetch(:file), client: client)
13
21
  object.get(response_target: download_path)
22
+
14
23
  YAML.load_file(download_path)
15
24
  end
16
25
 
@@ -1,3 +1,3 @@
1
1
  module GitlabConfig
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.1"
3
3
  end
data/lib/gitlab_config.rb CHANGED
@@ -1,8 +1,25 @@
1
- require "gitlab_config/version"
1
+ require 'gitlab_config/version'
2
2
  require 'gitlab_config/configuration'
3
+ require 'gitlab_config/aws/iam_role'
3
4
 
4
5
  module GitlabConfig
5
6
  def self.load_configuration(options)
7
+ if options.fetch(:source) == :s3 and options.has_key?(:iam_role)
8
+ options = fetch_iam_parameters(options)
9
+ end
10
+
6
11
  yield Configuration.new.get_configuration(options)
7
12
  end
13
+
14
+ def self.fetch_iam_parameters(options)
15
+ key = options.fetch(:key, nil)
16
+ secret = options.fetch(:secret, nil)
17
+
18
+ if key.nil? && secret.nil?
19
+ iam = IamRole.new(options.fetch(:iam_role))
20
+ options[:key] = iam.key
21
+ options[:secret] = iam.secret
22
+ end
23
+ options
24
+ end
8
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Tarry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-02 00:00:00.000000000 Z
11
+ date: 2016-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -84,10 +84,12 @@ files:
84
84
  - Rakefile
85
85
  - gitlab_config.gemspec
86
86
  - lib/gitlab_config.rb
87
+ - lib/gitlab_config/aws/iam_role.rb
87
88
  - lib/gitlab_config/configuration.rb
89
+ - lib/gitlab_config/source/local.rb
88
90
  - lib/gitlab_config/source/s3.rb
89
91
  - lib/gitlab_config/version.rb
90
- homepage:
92
+ homepage: https://github.com/bjss/gitlab_config_gem
91
93
  licenses: []
92
94
  metadata: {}
93
95
  post_install_message: