envoku 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f39cc37ce741e045daf7913c44c7dd96c36fabb
4
+ data.tar.gz: 3461cd1dc93448897c09bcb9c0cf204186beaac1
5
+ SHA512:
6
+ metadata.gz: f9f54a52452e96f561ec0528d12e96c95c455181b459685529ae04876dc3a5affa267c76f6090599ecdf098ac8c05d4816c12183b624b2ccfaeb4b96cc7e296b
7
+ data.tar.gz: aa46e0265014179c0d2a2d63b0ba8f52f2941e242810ebee5fb71b9c9deef1adacb56f6a917b3fa7816762b11c16ad3175b907f68e3e688315ddb5fddb51c0c0
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.gem
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
@@ -0,0 +1,8 @@
1
+ require 'codecov'
2
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
3
+ SimpleCov::Formatter::HTMLFormatter,
4
+ SimpleCov::Formatter::Codecov,
5
+ ]
6
+ SimpleCov.start do
7
+ add_filter 'spec'
8
+ end
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in envoku.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Marc Qualie
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ # Envoku
2
+
3
+ [![Circle CI](https://circleci.com/gh/marcqualie/envoku-ruby/tree/master.svg?style=svg)](https://circleci.com/gh/marcqualie/envoku-ruby/tree/master)
4
+ [![codecov.io](https://codecov.io/github/marcqualie/envoku-ruby/coverage.svg?branch=master)](https://codecov.io/github/marcqualie/envoku-ruby?branch=master)
5
+
6
+ Configuration storage that can be loaded into your application transparently at boot-time.
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'envoku'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install envoku
24
+
25
+
26
+ ## Usage
27
+
28
+ When Envoku is loaded it automatically uses Dotenv in the background to preload and other configuration mechanisms you may have to make transitioning seamless.
29
+
30
+ ### Rails
31
+
32
+ Envoku automatically pre-loads itself during `before_configuration` phase so no configuration is required.
33
+
34
+ ### Plain ruby
35
+
36
+ Run the following code before you need access to the environment variables
37
+
38
+ ```
39
+ Envoku.load
40
+ ```
41
+
42
+
43
+ ## Development
44
+
45
+ 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.
46
+
47
+ 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).
48
+
49
+
50
+ ## Contributing
51
+
52
+ Bug reports and pull requests are welcome on GitHub at https://github.com/marcqualie/envoku-ruby.
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "envoku"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,9 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.2.3
4
+
5
+ dependencies:
6
+ cache_directories:
7
+ - vendor/bundle
8
+ pre:
9
+ - gem install bundler:1.10.6
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'envoku/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "envoku"
8
+ spec.version = Envoku::VERSION
9
+ spec.authors = ["Marc Qualie"]
10
+ spec.email = ["marc@marcqualie.com"]
11
+ spec.licenses = ['MIT']
12
+
13
+ spec.summary = "Store environment variables securely on S3 away from your application"
14
+ spec.homepage = "https://envoku.com"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "dotenv", "~> 2.1"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.11"
24
+ spec.add_development_dependency "codecov", "~> 0.1.4"
25
+ spec.add_development_dependency "rake", "~> 10.5"
26
+ spec.add_development_dependency "rspec", "~> 3.4"
27
+ end
@@ -0,0 +1,13 @@
1
+ require "envoku/version"
2
+ require "envoku/adapters/s3"
3
+ require "envoku/rails" if defined? Rails
4
+
5
+ module Envoku
6
+
7
+ module_function
8
+
9
+ def load options = {}
10
+ instance = Envoku::Adapters::S3.new options
11
+ instance.load
12
+ end
13
+ end
@@ -0,0 +1,4 @@
1
+ module Envoku
2
+ module Adapters
3
+ end
4
+ end
@@ -0,0 +1,75 @@
1
+ require 'dotenv'
2
+ require 'envoku/adapters'
3
+ require 'fileutils'
4
+ require 'net/http'
5
+ require 'ostruct'
6
+ require 'securerandom'
7
+ require 'base64'
8
+
9
+ module Envoku
10
+ module Adapters
11
+ class S3
12
+
13
+ attr_reader :options
14
+
15
+ def initialize custom_options = {}
16
+ default_options = {
17
+ filename: nil,
18
+ bucket_name: nil,
19
+ access_key_id: nil,
20
+ secret_access_key: nil,
21
+ }
22
+ @options = OpenStruct.new default_options.merge(custom_options)
23
+ @local_file_name = "/tmp/envoku-#{SecureRandom.hex 16}.env"
24
+ end
25
+
26
+ def load
27
+ Dotenv.load
28
+ apply_environment_options
29
+ return unless options.bucket_name && options.filename && options.access_key_id && options.secret_access_key
30
+ FileUtils.rm @local_file_name if File.exists? @local_file_name
31
+ return unless clone_s3_file
32
+ Dotenv.load @local_file_name
33
+ FileUtils.rm @local_file_name
34
+ ENV['ENVOKU_REFRESHED_AT'] = Time.now.to_s
35
+ end
36
+
37
+ private
38
+
39
+ def clone_s3_file
40
+ s3_direct_url = "https://#{options.bucket_name}.s3.amazonaws.com/#{options.filename}"
41
+ s3_resource = "/#{options.bucket_name}/#{options.filename}"
42
+ s3_expires_at = Time.now + 300
43
+ signature_payload = "GET\n\n\n#{s3_expires_at.to_i}\n#{s3_resource}"
44
+ digest = OpenSSL::Digest.new 'sha1'
45
+ hmac = OpenSSL::HMAC.digest digest, options.secret_access_key, signature_payload
46
+ query_params = [
47
+ "AWSAccessKeyId=#{options.access_key_id}",
48
+ "Expires=#{s3_expires_at.to_i}",
49
+ "Signature=#{CGI.escape Base64.encode64(hmac).strip}"
50
+ ]
51
+ s3_signed_uri = URI.parse "#{s3_direct_url}?#{query_params.join('&')}"
52
+ s3_response = Net::HTTP.get_response s3_signed_uri
53
+ if s3_response.is_a? Net::HTTPSuccess
54
+ File.write @local_file_name, s3_response.body
55
+ end
56
+ end
57
+
58
+ def apply_environment_options
59
+ if ENV['ENVOKU_URL']
60
+ envoku_uri = URI.parse(ENV['ENVOKU_URL'])
61
+ return nil unless envoku_uri.host && envoku_uri.path && envoku_uri.user && envoku_uri.password
62
+ @options.filename ||= envoku_uri.path[1..-1]
63
+ @options.bucket_name ||= envoku_uri.host
64
+ @options.access_key_id ||= envoku_uri.user
65
+ @options.secret_access_key ||= envoku_uri.password
66
+ else
67
+ @options.filename ||= ENV['ENVOKU_FILENAME']
68
+ @options.bucket_name ||= ENV['ENVOKU_BUCKET']
69
+ @options.access_key_id ||= ENV['ENVOKU_ACCESS_KEY_ID'] || ENV['AWS_ACCESS_KEY_ID']
70
+ @options.secret_access_key ||= ENV['ENVOKU_SECRET_ACCESS_KEY'] || ENV['AWS_SECRET_ACCESS_KEY']
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,22 @@
1
+ require "envoku"
2
+
3
+ module Envoku
4
+ # Envoku Railtie for using Envoku to load environment before application is loaded
5
+ class Railtie < Rails::Railtie
6
+ config.before_configuration { load }
7
+
8
+ # Public: Load Envoku
9
+ #
10
+ # This will get called during the `before_configuration` callback, but you
11
+ # can manually call `Envoku::Railtie.load` if you needed it sooner.
12
+ def load
13
+ Envoku.load
14
+ end
15
+
16
+ # Rails uses `#method_missing` to delegate all class methods to the
17
+ # instance, which means `Kernel#load` gets called here. We don't want that.
18
+ def self.load
19
+ instance.load
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,3 @@
1
+ module Envoku
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: envoku
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Marc Qualie
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-02-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dotenv
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.11'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.11'
41
+ - !ruby/object:Gem::Dependency
42
+ name: codecov
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.4
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.4
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.5'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ description:
84
+ email:
85
+ - marc@marcqualie.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".simplecov"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - circle.yml
101
+ - envoku.gemspec
102
+ - lib/envoku.rb
103
+ - lib/envoku/adapters.rb
104
+ - lib/envoku/adapters/s3.rb
105
+ - lib/envoku/rails.rb
106
+ - lib/envoku/version.rb
107
+ homepage: https://envoku.com
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.5.1
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Store environment variables securely on S3 away from your application
131
+ test_files: []