heroku_external_db 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +42 -0
- data/.rvmrc +1 -0
- data/Gemfile +3 -15
- data/Gemfile.lock +90 -75
- data/LICENSE.txt +2 -0
- data/README.rdoc +118 -5
- data/Rakefile +1 -30
- data/configure +3 -0
- data/heroku_external_db.gemspec +18 -71
- data/lib/heroku_external_db.rb +26 -10
- data/spec/heroku_external_db_spec.rb +42 -7
- metadata +47 -45
data/.gitignore
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# rcov generated
|
2
|
+
coverage
|
3
|
+
|
4
|
+
# rdoc generated
|
5
|
+
rdoc
|
6
|
+
|
7
|
+
# yard generated
|
8
|
+
doc
|
9
|
+
.yardoc
|
10
|
+
|
11
|
+
# bundler
|
12
|
+
.bundle
|
13
|
+
|
14
|
+
# jeweler generated
|
15
|
+
pkg
|
16
|
+
|
17
|
+
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
|
18
|
+
#
|
19
|
+
# * Create a file at ~/.gitignore
|
20
|
+
# * Include files you want ignored
|
21
|
+
# * Run: git config --global core.excludesfile ~/.gitignore
|
22
|
+
#
|
23
|
+
# After doing this, these files will be ignored in all your git projects,
|
24
|
+
# saving you from having to 'pollute' every project you touch with them
|
25
|
+
#
|
26
|
+
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
|
27
|
+
#
|
28
|
+
# For MacOS:
|
29
|
+
#
|
30
|
+
#.DS_Store
|
31
|
+
#
|
32
|
+
# For TextMate
|
33
|
+
#*.tmproj
|
34
|
+
#tmtags
|
35
|
+
#
|
36
|
+
# For emacs:
|
37
|
+
#*~
|
38
|
+
#\#*
|
39
|
+
#.\#*
|
40
|
+
#
|
41
|
+
# For vim:
|
42
|
+
#*.swp
|
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2-p180@heroku_external_db --create
|
data/Gemfile
CHANGED
@@ -1,16 +1,4 @@
|
|
1
|
-
source
|
2
|
-
# Add dependencies required to use your gem here.
|
3
|
-
# Example:
|
4
|
-
# gem "activesupport", ">= 2.3.5"
|
1
|
+
source 'http://rubygems.org'
|
5
2
|
|
6
|
-
#
|
7
|
-
|
8
|
-
group :development do
|
9
|
-
gem "shoulda", ">= 0"
|
10
|
-
gem "bundler", "~> 1.0.0"
|
11
|
-
gem "jeweler", "~> 1.5.2"
|
12
|
-
gem "rspec", ">= 2.4.0"
|
13
|
-
gem "rcov"
|
14
|
-
gem "mocha"
|
15
|
-
gem "rails", "~> 3.0.0"
|
16
|
-
end
|
3
|
+
# Specify your gem's dependencies in heroku_external_db.gemspec
|
4
|
+
gemspec
|
data/Gemfile.lock
CHANGED
@@ -1,96 +1,111 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
heroku_external_db (1.0.2)
|
5
|
+
|
1
6
|
GEM
|
2
7
|
remote: http://rubygems.org/
|
3
8
|
specs:
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
rack (~> 1.
|
15
|
-
rack-mount (~> 0.
|
16
|
-
rack-test (~> 0.
|
17
|
-
|
18
|
-
activemodel (3.
|
19
|
-
activesupport (= 3.
|
20
|
-
builder (~>
|
21
|
-
i18n (~> 0.
|
22
|
-
activerecord (3.
|
23
|
-
activemodel (= 3.
|
24
|
-
activesupport (= 3.
|
25
|
-
arel (~>
|
26
|
-
tzinfo (~> 0.3.
|
27
|
-
activeresource (3.
|
28
|
-
activemodel (= 3.
|
29
|
-
activesupport (= 3.
|
30
|
-
activesupport (3.
|
31
|
-
|
32
|
-
|
33
|
-
builder (
|
34
|
-
diff-lcs (1.1.
|
35
|
-
erubis (2.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
bundler (~> 1.0.0)
|
41
|
-
git (>= 1.2.5)
|
42
|
-
rake
|
43
|
-
mail (2.2.15)
|
44
|
-
activesupport (>= 2.3.6)
|
9
|
+
actionmailer (3.1.3)
|
10
|
+
actionpack (= 3.1.3)
|
11
|
+
mail (~> 2.3.0)
|
12
|
+
actionpack (3.1.3)
|
13
|
+
activemodel (= 3.1.3)
|
14
|
+
activesupport (= 3.1.3)
|
15
|
+
builder (~> 3.0.0)
|
16
|
+
erubis (~> 2.7.0)
|
17
|
+
i18n (~> 0.6)
|
18
|
+
rack (~> 1.3.5)
|
19
|
+
rack-cache (~> 1.1)
|
20
|
+
rack-mount (~> 0.8.2)
|
21
|
+
rack-test (~> 0.6.1)
|
22
|
+
sprockets (~> 2.0.3)
|
23
|
+
activemodel (3.1.3)
|
24
|
+
activesupport (= 3.1.3)
|
25
|
+
builder (~> 3.0.0)
|
26
|
+
i18n (~> 0.6)
|
27
|
+
activerecord (3.1.3)
|
28
|
+
activemodel (= 3.1.3)
|
29
|
+
activesupport (= 3.1.3)
|
30
|
+
arel (~> 2.2.1)
|
31
|
+
tzinfo (~> 0.3.29)
|
32
|
+
activeresource (3.1.3)
|
33
|
+
activemodel (= 3.1.3)
|
34
|
+
activesupport (= 3.1.3)
|
35
|
+
activesupport (3.1.3)
|
36
|
+
multi_json (~> 1.0)
|
37
|
+
arel (2.2.1)
|
38
|
+
builder (3.0.0)
|
39
|
+
diff-lcs (1.1.3)
|
40
|
+
erubis (2.7.0)
|
41
|
+
hike (1.2.1)
|
42
|
+
i18n (0.6.0)
|
43
|
+
json (1.6.1)
|
44
|
+
mail (2.3.0)
|
45
45
|
i18n (>= 0.4.0)
|
46
46
|
mime-types (~> 1.16)
|
47
47
|
treetop (~> 1.4.8)
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
metaclass (0.0.1)
|
49
|
+
mime-types (1.17.2)
|
50
|
+
mocha (0.10.0)
|
51
|
+
metaclass (~> 0.0.1)
|
52
|
+
multi_json (1.0.3)
|
53
|
+
polyglot (0.3.3)
|
54
|
+
rack (1.3.5)
|
55
|
+
rack-cache (1.1)
|
56
|
+
rack (>= 0.4)
|
57
|
+
rack-mount (0.8.3)
|
54
58
|
rack (>= 1.0.0)
|
55
|
-
rack-
|
59
|
+
rack-ssl (1.3.2)
|
60
|
+
rack
|
61
|
+
rack-test (0.6.1)
|
56
62
|
rack (>= 1.0)
|
57
|
-
rails (3.
|
58
|
-
actionmailer (= 3.
|
59
|
-
actionpack (= 3.
|
60
|
-
activerecord (= 3.
|
61
|
-
activeresource (= 3.
|
62
|
-
activesupport (= 3.
|
63
|
-
bundler (~> 1.0
|
64
|
-
railties (= 3.
|
65
|
-
railties (3.
|
66
|
-
actionpack (= 3.
|
67
|
-
activesupport (= 3.
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
rspec
|
77
|
-
|
63
|
+
rails (3.1.3)
|
64
|
+
actionmailer (= 3.1.3)
|
65
|
+
actionpack (= 3.1.3)
|
66
|
+
activerecord (= 3.1.3)
|
67
|
+
activeresource (= 3.1.3)
|
68
|
+
activesupport (= 3.1.3)
|
69
|
+
bundler (~> 1.0)
|
70
|
+
railties (= 3.1.3)
|
71
|
+
railties (3.1.3)
|
72
|
+
actionpack (= 3.1.3)
|
73
|
+
activesupport (= 3.1.3)
|
74
|
+
rack-ssl (~> 1.3.2)
|
75
|
+
rake (>= 0.8.7)
|
76
|
+
rdoc (~> 3.4)
|
77
|
+
thor (~> 0.14.6)
|
78
|
+
rake (0.9.2.2)
|
79
|
+
rcov (0.9.11)
|
80
|
+
rdoc (3.11)
|
81
|
+
json (~> 1.4)
|
82
|
+
rspec (2.7.0)
|
83
|
+
rspec-core (~> 2.7.0)
|
84
|
+
rspec-expectations (~> 2.7.0)
|
85
|
+
rspec-mocks (~> 2.7.0)
|
86
|
+
rspec-core (2.7.1)
|
87
|
+
rspec-expectations (2.7.0)
|
78
88
|
diff-lcs (~> 1.1.2)
|
79
|
-
rspec-mocks (2.
|
89
|
+
rspec-mocks (2.7.0)
|
80
90
|
shoulda (2.11.3)
|
91
|
+
sprockets (2.0.3)
|
92
|
+
hike (~> 1.2)
|
93
|
+
rack (~> 1.0)
|
94
|
+
tilt (~> 1.1, != 1.3.0)
|
81
95
|
thor (0.14.6)
|
82
|
-
|
96
|
+
tilt (1.3.3)
|
97
|
+
treetop (1.4.10)
|
98
|
+
polyglot
|
83
99
|
polyglot (>= 0.3.1)
|
84
|
-
tzinfo (0.3.
|
100
|
+
tzinfo (0.3.31)
|
85
101
|
|
86
102
|
PLATFORMS
|
87
103
|
ruby
|
88
104
|
|
89
105
|
DEPENDENCIES
|
90
|
-
|
91
|
-
jeweler (~> 1.5.2)
|
106
|
+
heroku_external_db!
|
92
107
|
mocha
|
93
|
-
rails (
|
108
|
+
rails (>= 3.0.0)
|
94
109
|
rcov
|
95
110
|
rspec (>= 2.4.0)
|
96
111
|
shoulda
|
data/LICENSE.txt
CHANGED
data/README.rdoc
CHANGED
@@ -6,18 +6,128 @@ Allows you to easily set up one or more external databases in Rails applications
|
|
6
6
|
* You want to share a database between applications and aren't on the Heroku dedicated database plan.
|
7
7
|
* You want to host your application database somewhere besides Heroku, and run the app using Heroku dynos.
|
8
8
|
|
9
|
-
==
|
9
|
+
== Installation
|
10
10
|
|
11
11
|
Add the following to your Gemfile:
|
12
12
|
|
13
13
|
gem 'heroku_external_db'
|
14
|
+
# Or with the version number (easily found at https://rubygems.org/gems/heroku_external_db)
|
15
|
+
gem 'heroku_external_db', '~> x.y.z'
|
14
16
|
|
15
17
|
Then run:
|
16
18
|
|
17
19
|
bundle install
|
18
20
|
rails generate heroku_external_db:generator
|
19
21
|
|
20
|
-
This will set up a default initializer in your app's config/initializers/heroku_external_db.rb
|
22
|
+
This will set up a default initializer in your app's +config/initializers/heroku_external_db.rb+.
|
23
|
+
|
24
|
+
NOTE: If the generator does not work on your setup, you can copy the initializer by hand.
|
25
|
+
|
26
|
+
== Tutorial
|
27
|
+
|
28
|
+
The generator makes the assumption that you're happy with using +EXTERNAL_DATABASE_URL+ and (optionally) +EXTERNAL_DATABASE_CA+ as your environment variables and that you want to use the external database as your main production DB. If that's not true, please edit the initializer as needed.
|
29
|
+
|
30
|
+
=== Example: MySQL with a CA Certificate
|
31
|
+
|
32
|
+
In this example, we are setting up a connection to an external MySQL server using the default initializer.
|
33
|
+
|
34
|
+
What we have:
|
35
|
+
|
36
|
+
* A CA certificate called +ca-cert.pem+
|
37
|
+
* A database is available at mysql://username:password@server/dbname (where +username+, +password+, +server+, and +dbname+ are the appropriate values for our server)
|
38
|
+
* Other security, e.g. firewalls. Please make sure to open the appropriate ports and grant the necessary access for your database to be available externally. Further discussion is outside the scope of this document, but for accessing EC2, you might start at http://devcenter.heroku.com/articles/external-services.
|
39
|
+
|
40
|
+
First, we configure Heroku with the appropriate environment variables:
|
41
|
+
|
42
|
+
# You may have to specify the app name or remote name here via --app or --remote, respectively
|
43
|
+
heroku config:add EXTERNAL_DATABASE_CA='ca-cert.pem'
|
44
|
+
heroku config:add EXTERNAL_DATABASE_URL='mysql://username:password@server/dbname'
|
45
|
+
|
46
|
+
By default, +heroku_external_db+ looks for the CA cert in +config/ca+, so we need to commit it:
|
47
|
+
|
48
|
+
mkdir -p config/ca
|
49
|
+
cp path/to/ca-cert.pem config/ca
|
50
|
+
git add config/ca
|
51
|
+
git commit -v # Using -v since we want to make sure the contents are what we expect (e.g. not a private key)
|
52
|
+
|
53
|
+
Additionally, we need the +mysql+ gem in our Gemfile since we are setting up a MySQL server:
|
54
|
+
|
55
|
+
echo "gem 'mysql', '~> 2.8.1'" >> Gemfile
|
56
|
+
bundle install # Need Gemfile.lock too
|
57
|
+
|
58
|
+
Keep in mind that Heroku installs its own +database.yml+ for Rails apps and we have to install +pg+ as well. Unfortunately, shared databases are mandatory (but are free).
|
59
|
+
|
60
|
+
$ heroku addons:remove shared-database:5mb
|
61
|
+
-----> Removing shared-database:5mb from our-app... failed
|
62
|
+
! Shared databases cannot be removed
|
63
|
+
|
64
|
+
PostgreSQL may still be useful to you if, for example, you want to have feature toggles in a local database, but the main data kept externally. However in our case, it also means all developers will need MySQL and PostgreSQL running locally, which is unfortunate.
|
65
|
+
|
66
|
+
One workaround is only installing +pg+ in production:
|
67
|
+
|
68
|
+
# File: Gemfile
|
69
|
+
|
70
|
+
# *Only* needed on production.
|
71
|
+
group :production do
|
72
|
+
gem 'pg', '~> 0.11.0' # Regardless of whether you plan to use the database or not, Heroku requires you have 'pg' installed.
|
73
|
+
end
|
74
|
+
|
75
|
+
Then +bundle+ like so:
|
76
|
+
|
77
|
+
$ bundle install --without production
|
78
|
+
|
79
|
+
With our gems updated, commit:
|
80
|
+
|
81
|
+
git commit -av # Commit Gemfile and Gemfile.lock
|
82
|
+
|
83
|
+
Another option may be overriding +database.yml+ somehow, although it would add complexity. For more info, please see http://stackoverflow.com/questions/4204724/strategies-for-overriding-database-yml.
|
84
|
+
|
85
|
+
With our dependencies out of the way, we can move on to testing the connection.
|
86
|
+
|
87
|
+
If you are making a new application, you may wish to have a simple MVC for testing that the connection works. E.g., for a blog style application with posts do:
|
88
|
+
|
89
|
+
rails generate scaffold post
|
90
|
+
# NOTE you probably want to change the default "Post.all" to "Post.limit(5)" or something similar
|
91
|
+
git add .
|
92
|
+
git commit # ...
|
93
|
+
# Don't forget to set a default route, etc.
|
94
|
+
|
95
|
+
With all these changes committed, we can deploy to our Heroku app:
|
96
|
+
|
97
|
+
git push heroku master # Your remote may be different
|
98
|
+
|
99
|
+
Now, since we are connecting to an existing database, we don't need to run any migrations. (Keep in mind that when sharing a database, it is best to have one authoritative source for migrations to live.) If in your situation you're creating a new database, you may need to do that, run migrations, seed the database, etc at this point.
|
100
|
+
|
101
|
+
Open http://our-app.heroku.com and we should see our data. If you happen to run into a problem, please check the logs first:
|
102
|
+
|
103
|
+
heroku logs --tail # Again, you may need to specify an app
|
104
|
+
|
105
|
+
If you are having a problem, a good starting point is double checking your passwords, usernames, security settings, etc.
|
106
|
+
|
107
|
+
=== Example: MySQL with X.509
|
108
|
+
|
109
|
+
The process is very much the same as the above example, except two extra environment variables and files are required. Below are the extra steps.
|
110
|
+
|
111
|
+
What we have:
|
112
|
+
|
113
|
+
* A CA certificate called +ca-cert.pem+
|
114
|
+
* A client certificate called +client-cert.pem+
|
115
|
+
* A client key called +client-key.pem+
|
116
|
+
|
117
|
+
First, we configure Heroku with the appropriate environment variables:
|
118
|
+
|
119
|
+
heroku config:add EXTERNAL_DATABASE_CA='ca-cert.pem'
|
120
|
+
heroku config:add EXTERNAL_DATABASE_CERT='client-cert.pem'
|
121
|
+
heroku config:add EXTERNAL_DATABASE_KEY='client-key.pem'
|
122
|
+
|
123
|
+
By default, +heroku_external_db+ looks for the files in +config/ca+, so we need to commit them:
|
124
|
+
|
125
|
+
mkdir -p config/ca
|
126
|
+
cp path/to/ca-cert.pem path/to/client-cert.pem path/to/client-key.pem config/ca
|
127
|
+
git add config/ca
|
128
|
+
git commit
|
129
|
+
|
130
|
+
The rest of the process is the same as in "MySQL with a CA Certificate".
|
21
131
|
|
22
132
|
== Contributing to heroku_external_db
|
23
133
|
|
@@ -29,8 +139,11 @@ This will set up a default initializer in your app's config/initializers/heroku_
|
|
29
139
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
30
140
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
31
141
|
|
32
|
-
|
142
|
+
=== Setting up Environment and Running Specs
|
33
143
|
|
34
|
-
|
35
|
-
|
144
|
+
./configure
|
145
|
+
rake
|
146
|
+
|
147
|
+
== Copyright
|
36
148
|
|
149
|
+
Copyright (c) 2011 Nat Budin. See LICENSE.txt for further details.
|
data/Rakefile
CHANGED
@@ -1,36 +1,7 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'bundler'
|
3
|
-
begin
|
4
|
-
Bundler.setup(:default, :development)
|
5
|
-
rescue Bundler::BundlerError => e
|
6
|
-
$stderr.puts e.message
|
7
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
-
exit e.status_code
|
9
|
-
end
|
2
|
+
require 'bundler/gem_tasks'
|
10
3
|
require 'rake'
|
11
4
|
|
12
|
-
require 'jeweler'
|
13
|
-
Jeweler::Tasks.new do |gem|
|
14
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
-
gem.name = "heroku_external_db"
|
16
|
-
gem.homepage = "http://github.com/nbudin/heroku_external_db"
|
17
|
-
gem.license = "MIT"
|
18
|
-
gem.summary = %Q{Makes it easy to connect Heroku apps to external databases}
|
19
|
-
gem.description = <<-DESC
|
20
|
-
heroku_external_db lets you specify multiple databases using Heroku-style DATABASE_URL parameters, wire
|
21
|
-
them up to different ActiveRecord configurations, and automatically configure it from the Rails
|
22
|
-
environment. It also adds support for the :sslca configuration parameter so you can talk to external
|
23
|
-
MySQL servers over SSL.
|
24
|
-
DESC
|
25
|
-
gem.email = "natbudin@gmail.com"
|
26
|
-
gem.authors = ["Nat Budin"]
|
27
|
-
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
28
|
-
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
29
|
-
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
30
|
-
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
31
|
-
end
|
32
|
-
Jeweler::RubygemsDotOrgTasks.new
|
33
|
-
|
34
5
|
require "rspec/core/rake_task"
|
35
6
|
desc "Run all examples"
|
36
7
|
RSpec::Core::RakeTask.new(:spec) do |t|
|
data/configure
ADDED
data/heroku_external_db.gemspec
CHANGED
@@ -1,81 +1,28 @@
|
|
1
|
-
# Generated by jeweler
|
2
|
-
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
-
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
1
|
# -*- encoding: utf-8 -*-
|
5
2
|
|
6
|
-
Gem::Specification.new do |
|
7
|
-
|
8
|
-
s.version = "1.0.1"
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.version = "1.0.3"
|
9
5
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
s.description = %q{ heroku_external_db lets you specify multiple databases using Heroku-style DATABASE_URL parameters, wire
|
6
|
+
gem.authors = ["Nat Budin", "Ben Oakes"]
|
7
|
+
gem.email = ["natbudin@gmail.com", "hello@benjaminoakes.com"]
|
8
|
+
gem.description = %q{ heroku_external_db lets you specify multiple databases using Heroku-style DATABASE_URL parameters, wire
|
14
9
|
them up to different ActiveRecord configurations, and automatically configure it from the Rails
|
15
10
|
environment. It also adds support for the :sslca configuration parameter so you can talk to external
|
16
11
|
MySQL servers over SSL.
|
17
12
|
}
|
18
|
-
|
19
|
-
|
20
|
-
"LICENSE.txt",
|
21
|
-
"README.rdoc"
|
22
|
-
]
|
23
|
-
s.files = [
|
24
|
-
".document",
|
25
|
-
"Gemfile",
|
26
|
-
"Gemfile.lock",
|
27
|
-
"LICENSE.txt",
|
28
|
-
"README.rdoc",
|
29
|
-
"Rakefile",
|
30
|
-
"VERSION",
|
31
|
-
"heroku_external_db.gemspec",
|
32
|
-
"init.rb",
|
33
|
-
"lib/generators/heroku_external_db/USAGE",
|
34
|
-
"lib/generators/heroku_external_db/heroku_external_db_generator.rb",
|
35
|
-
"lib/generators/heroku_external_db/templates/initializer.rb",
|
36
|
-
"lib/heroku_external_db.rb",
|
37
|
-
"rails/init.rb",
|
38
|
-
"spec/heroku_external_db_spec.rb",
|
39
|
-
"spec/spec_helper.rb"
|
40
|
-
]
|
41
|
-
s.homepage = %q{http://github.com/nbudin/heroku_external_db}
|
42
|
-
s.licenses = ["MIT"]
|
43
|
-
s.require_paths = ["lib"]
|
44
|
-
s.rubygems_version = %q{1.6.2}
|
45
|
-
s.summary = %q{Makes it easy to connect Heroku apps to external databases}
|
46
|
-
s.test_files = [
|
47
|
-
"spec/heroku_external_db_spec.rb",
|
48
|
-
"spec/spec_helper.rb"
|
49
|
-
]
|
13
|
+
gem.summary = %q{Makes it easy to connect Heroku apps to external databases}
|
14
|
+
gem.homepage = %q{http://github.com/nbudin/heroku_external_db}
|
50
15
|
|
51
|
-
|
52
|
-
|
16
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
gem.files = `git ls-files`.split("\n")
|
18
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
gem.name = "heroku_external_db"
|
20
|
+
gem.require_paths = ["lib"]
|
21
|
+
gem.licenses = ["MIT"]
|
53
22
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
60
|
-
s.add_development_dependency(%q<mocha>, [">= 0"])
|
61
|
-
s.add_development_dependency(%q<rails>, ["~> 3.0.0"])
|
62
|
-
else
|
63
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
64
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
65
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
66
|
-
s.add_dependency(%q<rspec>, [">= 2.4.0"])
|
67
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
68
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
69
|
-
s.add_dependency(%q<rails>, ["~> 3.0.0"])
|
70
|
-
end
|
71
|
-
else
|
72
|
-
s.add_dependency(%q<shoulda>, [">= 0"])
|
73
|
-
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
74
|
-
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
75
|
-
s.add_dependency(%q<rspec>, [">= 2.4.0"])
|
76
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
77
|
-
s.add_dependency(%q<mocha>, [">= 0"])
|
78
|
-
s.add_dependency(%q<rails>, ["~> 3.0.0"])
|
79
|
-
end
|
23
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
24
|
+
gem.add_development_dependency "rspec", ">= 2.4.0"
|
25
|
+
gem.add_development_dependency "rcov"
|
26
|
+
gem.add_development_dependency "mocha"
|
27
|
+
gem.add_development_dependency "rails", ">= 3.0.0"
|
80
28
|
end
|
81
|
-
|
data/lib/heroku_external_db.rb
CHANGED
@@ -76,15 +76,27 @@ module HerokuExternalDb
|
|
76
76
|
# Returns a partial ActiveRecord configuration hash for the given SSL CA certificate.
|
77
77
|
# Checks to make sure the given filename actually exists, and raises an error if it
|
78
78
|
# does not.
|
79
|
-
def
|
80
|
-
return {} unless
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
79
|
+
def db_configuration(opts)
|
80
|
+
return {} unless opts
|
81
|
+
raise "ca_path for #{opts.inspect} cannot be determined from Rails root; please set it explicitly" unless ca_path
|
82
|
+
|
83
|
+
config = {}
|
84
|
+
|
85
|
+
[
|
86
|
+
:sslca,
|
87
|
+
|
88
|
+
# Needed when using X.509
|
89
|
+
:sslcert,
|
90
|
+
:sslkey,
|
91
|
+
].each do |k|
|
92
|
+
if value = opts[k]
|
93
|
+
filepath = File.join(ca_path, value)
|
94
|
+
raise "File #{filepath.inspect} does not exist!" unless File.exists?(filepath)
|
95
|
+
config[k] = filepath
|
96
|
+
end
|
97
|
+
end
|
86
98
|
|
87
|
-
return
|
99
|
+
return config
|
88
100
|
end
|
89
101
|
|
90
102
|
# Returns an ActiveRecord configuration hash based on the environment variables.
|
@@ -94,7 +106,11 @@ module HerokuExternalDb
|
|
94
106
|
config = parse_db_uri(ENV["#{env_prefix}_DATABASE_URL"])
|
95
107
|
|
96
108
|
if ENV["#{env_prefix}_DATABASE_CA"]
|
97
|
-
config.merge!(
|
109
|
+
config.merge!(db_configuration({
|
110
|
+
:sslca => ENV["#{env_prefix}_DATABASE_CA"],
|
111
|
+
:sslcert => ENV["#{env_prefix}_DATABASE_CERT"],
|
112
|
+
:sslkey => ENV["#{env_prefix}_DATABASE_KEY"],
|
113
|
+
}))
|
98
114
|
end
|
99
115
|
|
100
116
|
config
|
@@ -118,4 +134,4 @@ module HerokuExternalDb
|
|
118
134
|
end
|
119
135
|
end
|
120
136
|
end
|
121
|
-
end
|
137
|
+
end
|
@@ -74,24 +74,59 @@ describe HerokuExternalDb::Configuration do
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
describe "#
|
77
|
+
describe "#db_configuration" do
|
78
|
+
# Help make a "mock" certificate file
|
79
|
+
def mock_cert(name)
|
80
|
+
path = Tempfile.new(name).path
|
81
|
+
ca_path, cert_filename = File.split(path)
|
82
|
+
return path, cert_filename
|
83
|
+
end
|
84
|
+
|
78
85
|
context "with a CA path" do
|
79
86
|
before do
|
80
87
|
@cert_path, @cert_filename = setup_ca_cert(@extdb)
|
81
88
|
end
|
82
89
|
|
83
90
|
it "should return an empty hash if not given a filename" do
|
84
|
-
@extdb.
|
91
|
+
@extdb.db_configuration(nil).should == {}
|
85
92
|
end
|
86
93
|
|
87
94
|
it "should have the correct pathname to the CA cert" do
|
88
|
-
@config = @extdb.
|
95
|
+
@config = @extdb.db_configuration(:sslca => @cert_filename)
|
89
96
|
@config[:sslca].should == @cert_path
|
90
97
|
end
|
98
|
+
|
99
|
+
context 'when using X.509' do
|
100
|
+
it "should have the correct pathname to the client cert" do
|
101
|
+
@config = @extdb.db_configuration(:sslcert => @cert_filename)
|
102
|
+
@config[:sslcert].should == @cert_path
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should have the correct pathname to the client key" do
|
106
|
+
@config = @extdb.db_configuration(:sslkey => @cert_filename)
|
107
|
+
@config[:sslkey].should == @cert_path
|
108
|
+
end
|
109
|
+
|
110
|
+
it 'should support setting all 3 X.509 certs' do
|
111
|
+
ca_cert_path, ca_cert_filename = mock_cert("ca-cert.pem")
|
112
|
+
client_cert_path, client_cert_filename = mock_cert("client-cert.pem")
|
113
|
+
client_key_path, client_key_filename = mock_cert("client-key.pem")
|
114
|
+
|
115
|
+
@config = @extdb.db_configuration({
|
116
|
+
:sslca => ca_cert_filename,
|
117
|
+
:sslcert => client_cert_filename,
|
118
|
+
:sslkey => client_key_filename,
|
119
|
+
})
|
120
|
+
|
121
|
+
@config[:sslca].should == ca_cert_path
|
122
|
+
@config[:sslcert].should == client_cert_path
|
123
|
+
@config[:sslkey].should == client_key_path
|
124
|
+
end
|
125
|
+
end
|
91
126
|
|
92
127
|
it "should throw an error if the file doesn't exist" do
|
93
128
|
File.delete(@cert_path)
|
94
|
-
lambda { @extdb.
|
129
|
+
lambda { @extdb.db_configuration(:sslca => @cert_filename) }.should raise_error
|
95
130
|
end
|
96
131
|
|
97
132
|
after do
|
@@ -101,11 +136,11 @@ describe HerokuExternalDb::Configuration do
|
|
101
136
|
|
102
137
|
context "without a CA path" do
|
103
138
|
it "should return an empty hash if not given a filename" do
|
104
|
-
@extdb.
|
139
|
+
@extdb.db_configuration(nil).should == {}
|
105
140
|
end
|
106
141
|
|
107
142
|
it "should raise an error if given a filename" do
|
108
|
-
lambda { @extdb.
|
143
|
+
lambda { @extdb.db_configuration(:sslca => "filename") }.should raise_error
|
109
144
|
end
|
110
145
|
end
|
111
146
|
end
|
@@ -230,4 +265,4 @@ describe HerokuExternalDb::Configuration do
|
|
230
265
|
ENV.delete("EXTERNAL_DATABASE_URL")
|
231
266
|
end
|
232
267
|
end
|
233
|
-
end
|
268
|
+
end
|
metadata
CHANGED
@@ -1,112 +1,113 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: heroku_external_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 1.0.3
|
6
10
|
platform: ruby
|
7
11
|
authors:
|
8
12
|
- Nat Budin
|
13
|
+
- Ben Oakes
|
9
14
|
autorequire:
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
18
|
+
date: 2011-11-21 00:00:00 -05:00
|
14
19
|
default_executable:
|
15
20
|
dependencies:
|
16
21
|
- !ruby/object:Gem::Dependency
|
17
22
|
name: shoulda
|
23
|
+
prerelease: false
|
18
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
19
25
|
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
segments:
|
30
|
+
- 0
|
23
31
|
version: "0"
|
24
32
|
type: :development
|
25
|
-
prerelease: false
|
26
33
|
version_requirements: *id001
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: bundler
|
29
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
-
none: false
|
31
|
-
requirements:
|
32
|
-
- - ~>
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: 1.0.0
|
35
|
-
type: :development
|
36
|
-
prerelease: false
|
37
|
-
version_requirements: *id002
|
38
|
-
- !ruby/object:Gem::Dependency
|
39
|
-
name: jeweler
|
40
|
-
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 1.5.2
|
46
|
-
type: :development
|
47
|
-
prerelease: false
|
48
|
-
version_requirements: *id003
|
49
34
|
- !ruby/object:Gem::Dependency
|
50
35
|
name: rspec
|
51
|
-
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
52
38
|
none: false
|
53
39
|
requirements:
|
54
40
|
- - ">="
|
55
41
|
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 2
|
44
|
+
- 4
|
45
|
+
- 0
|
56
46
|
version: 2.4.0
|
57
47
|
type: :development
|
58
|
-
|
59
|
-
version_requirements: *id004
|
48
|
+
version_requirements: *id002
|
60
49
|
- !ruby/object:Gem::Dependency
|
61
50
|
name: rcov
|
62
|
-
|
51
|
+
prerelease: false
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
63
53
|
none: false
|
64
54
|
requirements:
|
65
55
|
- - ">="
|
66
56
|
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
67
59
|
version: "0"
|
68
60
|
type: :development
|
69
|
-
|
70
|
-
version_requirements: *id005
|
61
|
+
version_requirements: *id003
|
71
62
|
- !ruby/object:Gem::Dependency
|
72
63
|
name: mocha
|
73
|
-
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
74
66
|
none: false
|
75
67
|
requirements:
|
76
68
|
- - ">="
|
77
69
|
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
78
72
|
version: "0"
|
79
73
|
type: :development
|
80
|
-
|
81
|
-
version_requirements: *id006
|
74
|
+
version_requirements: *id004
|
82
75
|
- !ruby/object:Gem::Dependency
|
83
76
|
name: rails
|
84
|
-
|
77
|
+
prerelease: false
|
78
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
85
79
|
none: false
|
86
80
|
requirements:
|
87
|
-
- -
|
81
|
+
- - ">="
|
88
82
|
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 3
|
85
|
+
- 0
|
86
|
+
- 0
|
89
87
|
version: 3.0.0
|
90
88
|
type: :development
|
91
|
-
|
92
|
-
version_requirements: *id007
|
89
|
+
version_requirements: *id005
|
93
90
|
description: " heroku_external_db lets you specify multiple databases using Heroku-style DATABASE_URL parameters, wire\n them up to different ActiveRecord configurations, and automatically configure it from the Rails\n environment. It also adds support for the :sslca configuration parameter so you can talk to external\n MySQL servers over SSL.\n"
|
94
|
-
email:
|
91
|
+
email:
|
92
|
+
- natbudin@gmail.com
|
93
|
+
- hello@benjaminoakes.com
|
95
94
|
executables: []
|
96
95
|
|
97
96
|
extensions: []
|
98
97
|
|
99
|
-
extra_rdoc_files:
|
100
|
-
|
101
|
-
- README.rdoc
|
98
|
+
extra_rdoc_files: []
|
99
|
+
|
102
100
|
files:
|
103
101
|
- .document
|
102
|
+
- .gitignore
|
103
|
+
- .rvmrc
|
104
104
|
- Gemfile
|
105
105
|
- Gemfile.lock
|
106
106
|
- LICENSE.txt
|
107
107
|
- README.rdoc
|
108
108
|
- Rakefile
|
109
109
|
- VERSION
|
110
|
+
- configure
|
110
111
|
- heroku_external_db.gemspec
|
111
112
|
- init.rb
|
112
113
|
- lib/generators/heroku_external_db/USAGE
|
@@ -130,7 +131,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
131
|
requirements:
|
131
132
|
- - ">="
|
132
133
|
- !ruby/object:Gem::Version
|
133
|
-
hash: -147050405772207697
|
134
134
|
segments:
|
135
135
|
- 0
|
136
136
|
version: "0"
|
@@ -139,11 +139,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
requirements:
|
140
140
|
- - ">="
|
141
141
|
- !ruby/object:Gem::Version
|
142
|
+
segments:
|
143
|
+
- 0
|
142
144
|
version: "0"
|
143
145
|
requirements: []
|
144
146
|
|
145
147
|
rubyforge_project:
|
146
|
-
rubygems_version: 1.
|
148
|
+
rubygems_version: 1.3.7
|
147
149
|
signing_key:
|
148
150
|
specification_version: 3
|
149
151
|
summary: Makes it easy to connect Heroku apps to external databases
|