cf-autoconfig 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +12737 -0
- data/lib/cfautoconfig.rb +3 -0
- data/lib/cfautoconfig/blob/aws_s3.rb +23 -0
- data/lib/cfautoconfig/blob/aws_s3_configurer.rb +41 -0
- data/lib/cfautoconfig/configuration_helper.rb +19 -0
- data/lib/cfautoconfig/configurer.rb +44 -0
- data/lib/cfautoconfig/document/mongodb.rb +56 -0
- data/lib/cfautoconfig/document/mongodb_configurer.rb +44 -0
- data/lib/cfautoconfig/keyvalue/redis.rb +24 -0
- data/lib/cfautoconfig/keyvalue/redis_configurer.rb +33 -0
- data/lib/cfautoconfig/messaging/amqp.rb +30 -0
- data/lib/cfautoconfig/messaging/amqp_configurer.rb +33 -0
- data/lib/cfautoconfig/messaging/carrot.rb +24 -0
- data/lib/cfautoconfig/messaging/carrot_configurer.rb +33 -0
- data/lib/cfautoconfig/relational/mysql.rb +27 -0
- data/lib/cfautoconfig/relational/mysql_configurer.rb +38 -0
- data/lib/cfautoconfig/relational/postgres.rb +80 -0
- data/lib/cfautoconfig/relational/postgres_configurer.rb +42 -0
- data/lib/cfautoconfig/version.rb +3 -0
- metadata +275 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'cfautoconfig/configuration_helper'
|
2
|
+
|
3
|
+
begin
|
4
|
+
#Require mysql2 here is mandatory for configurer to ensure class is loaded before applying OpenClass
|
5
|
+
require "mysql2"
|
6
|
+
require File.join(File.dirname(__FILE__), 'mysql')
|
7
|
+
mysql2_version = Gem.loaded_specs['mysql2'].version
|
8
|
+
if mysql2_version >= Gem::Version.new(AutoReconfiguration::SUPPORTED_MYSQL2_VERSION)
|
9
|
+
if AutoReconfiguration::ConfigurationHelper.disabled? :mysql
|
10
|
+
puts "MySQL auto-reconfiguration disabled."
|
11
|
+
module Mysql2
|
12
|
+
class Client
|
13
|
+
#Remove introduced aliases and methods.
|
14
|
+
#This is mostly for testing, as we don't expect this script
|
15
|
+
#to run twice during a single app startup
|
16
|
+
if method_defined?(:initialize_with_cf)
|
17
|
+
undef_method :initialize_with_cf
|
18
|
+
alias :initialize :original_initialize
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
elsif Mysql2::Client.public_instance_methods.index 'initialize_with_cf'
|
23
|
+
puts "MySQL AutoReconfiguration already included."
|
24
|
+
else
|
25
|
+
module Mysql2
|
26
|
+
class Client
|
27
|
+
include AutoReconfiguration::Mysql
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
else
|
32
|
+
puts "Auto-reconfiguration not supported for this Mysql2 version. " +
|
33
|
+
"Found: #{mysql2_version}. Required: #{AutoReconfiguration::SUPPORTED_MYSQL2_VERSION} or higher."
|
34
|
+
end
|
35
|
+
rescue LoadError
|
36
|
+
puts "No MySQL Library Found. Skipping auto-reconfiguration."
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'cfruntime/properties'
|
2
|
+
module AutoReconfiguration
|
3
|
+
SUPPORTED_PG_VERSION = '0.11.0'
|
4
|
+
module Postgres
|
5
|
+
def self.included( base )
|
6
|
+
base.send( :alias_method, :original_open, :open)
|
7
|
+
base.send( :alias_method, :open, :open_with_cf )
|
8
|
+
base.send( :alias_method, :original_connect, :connect)
|
9
|
+
base.send( :alias_method, :connect, :connect_with_cf )
|
10
|
+
base.send( :alias_method, :original_connect_start, :connect_start)
|
11
|
+
base.send( :alias_method, :connect_start, :connect_start_with_cf )
|
12
|
+
end
|
13
|
+
|
14
|
+
def open_with_cf(*args)
|
15
|
+
connection_string = parse_cf_connection_args(*args)
|
16
|
+
if connection_string
|
17
|
+
#Send the new connection string to passed block for verification.
|
18
|
+
yield connection_string if block_given?
|
19
|
+
original_open(connection_string)
|
20
|
+
else
|
21
|
+
original_open(*args)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def connect_with_cf(*args)
|
26
|
+
connection_string = parse_cf_connection_args(*args)
|
27
|
+
if connection_string
|
28
|
+
#Send the new connection string to passed block for verification.
|
29
|
+
yield connection_string if block_given?
|
30
|
+
original_connect(connection_string)
|
31
|
+
else
|
32
|
+
original_connect(*args)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def connect_start_with_cf(*args)
|
37
|
+
connection_string = parse_cf_connection_args(*args)
|
38
|
+
if connection_string
|
39
|
+
#Send the new connection string to passed block for verification.
|
40
|
+
yield connection_string if block_given?
|
41
|
+
original_connect_start(connection_string)
|
42
|
+
else
|
43
|
+
original_connect_start(*args)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
# Parses all possible argument formats and returns a single connection string
|
49
|
+
# that includes all necessary connection parameters for the CF Postgres service
|
50
|
+
# Possible argument formats:
|
51
|
+
# ()
|
52
|
+
# (connection_hash)
|
53
|
+
# (connection_string)
|
54
|
+
# (host, port, options, tty, dbname, user, password)
|
55
|
+
def parse_cf_connection_args(*args)
|
56
|
+
service_names = CFRuntime::CloudApp.service_names_of_type('postgresql')
|
57
|
+
if service_names.length != 1
|
58
|
+
puts "Found #{service_names.length} postgresql services. Skipping auto-reconfiguration."
|
59
|
+
return
|
60
|
+
end
|
61
|
+
puts "Auto-reconfiguring PostgreSQL."
|
62
|
+
service_props = CFRuntime::CloudApp.service_props('postgresql')
|
63
|
+
#Use the parse_connect_args method from pg to process all possible formats into a single connection string
|
64
|
+
conn_string= parse_connect_args(*args)
|
65
|
+
sub_or_append_cf_arg(conn_string,'dbname',service_props[:database])
|
66
|
+
sub_or_append_cf_arg(conn_string,'host',service_props[:host])
|
67
|
+
sub_or_append_cf_arg(conn_string,'port',service_props[:port])
|
68
|
+
sub_or_append_cf_arg(conn_string,'user',service_props[:username])
|
69
|
+
sub_or_append_cf_arg(conn_string,'password',service_props[:password])
|
70
|
+
conn_string
|
71
|
+
end
|
72
|
+
|
73
|
+
def sub_or_append_cf_arg(conn_string,key,value)
|
74
|
+
cf_conn_string = conn_string.gsub!(/#{key}=\S+/,"#{key}='#{value}'")
|
75
|
+
if(cf_conn_string.nil?)
|
76
|
+
conn_string << " #{key}='#{value}'"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'cfautoconfig/configuration_helper'
|
2
|
+
begin
|
3
|
+
#Require pg here is mandatory for configurer to ensure class is loaded before applying OpenClass
|
4
|
+
require "pg"
|
5
|
+
require File.join(File.dirname(__FILE__), 'postgres')
|
6
|
+
pg_version = Gem.loaded_specs['pg'].version
|
7
|
+
if pg_version >= Gem::Version.new(AutoReconfiguration::SUPPORTED_PG_VERSION)
|
8
|
+
if AutoReconfiguration::ConfigurationHelper.disabled? :postgresql
|
9
|
+
puts "PostgreSQL auto-reconfiguration disabled."
|
10
|
+
class << PGconn
|
11
|
+
#Remove introduced aliases and methods.
|
12
|
+
#This is mostly for testing, as we don't expect this script
|
13
|
+
#to run twice during a single app startup
|
14
|
+
if method_defined?(:open_with_cf)
|
15
|
+
undef_method :open_with_cf
|
16
|
+
alias :open :original_open
|
17
|
+
end
|
18
|
+
if method_defined?(:connect_with_cf)
|
19
|
+
undef_method :connect_with_cf
|
20
|
+
alias :connect :original_connect
|
21
|
+
end
|
22
|
+
if method_defined?(:connect_start_with_cf)
|
23
|
+
undef_method :connect_start_with_cf
|
24
|
+
alias :connect_start :original_connect_start
|
25
|
+
end
|
26
|
+
end
|
27
|
+
elsif PGconn.public_methods.index :open_with_cf
|
28
|
+
puts "PostgreSQL AutoReconfiguration already included."
|
29
|
+
else
|
30
|
+
#Introduce around alias into PGconn class
|
31
|
+
class << PGconn
|
32
|
+
include AutoReconfiguration::Postgres
|
33
|
+
end
|
34
|
+
end
|
35
|
+
else
|
36
|
+
puts "Auto-reconfiguration not supported for this PG version. " +
|
37
|
+
"Found: #{pg_version}. Required: #{AutoReconfiguration::SUPPORTED_PG_VERSION} or higher."
|
38
|
+
end
|
39
|
+
rescue LoadError
|
40
|
+
puts "No PostgreSQL Library Found. Skipping auto-reconfiguration."
|
41
|
+
end
|
42
|
+
|
metadata
ADDED
@@ -0,0 +1,275 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cf-autoconfig
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- VMware
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: cf-runtime
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - '='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.1.1
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - '='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.1.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: redis
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '2.0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '2.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: amqp
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0.8'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.8'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: carrot
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: mysql2
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 0.2.7
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 0.2.7
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: pg
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ~>
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: 0.11.0
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.11.0
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: mongo
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ~>
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.2.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: 1.2.0
|
126
|
+
- !ruby/object:Gem::Dependency
|
127
|
+
name: rake
|
128
|
+
requirement: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ~>
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 0.9.2
|
134
|
+
type: :development
|
135
|
+
prerelease: false
|
136
|
+
version_requirements: !ruby/object:Gem::Requirement
|
137
|
+
none: false
|
138
|
+
requirements:
|
139
|
+
- - ~>
|
140
|
+
- !ruby/object:Gem::Version
|
141
|
+
version: 0.9.2
|
142
|
+
- !ruby/object:Gem::Dependency
|
143
|
+
name: rspec
|
144
|
+
requirement: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ~>
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 2.6.0
|
150
|
+
type: :development
|
151
|
+
prerelease: false
|
152
|
+
version_requirements: !ruby/object:Gem::Requirement
|
153
|
+
none: false
|
154
|
+
requirements:
|
155
|
+
- - ~>
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: 2.6.0
|
158
|
+
- !ruby/object:Gem::Dependency
|
159
|
+
name: ci_reporter
|
160
|
+
requirement: !ruby/object:Gem::Requirement
|
161
|
+
none: false
|
162
|
+
requirements:
|
163
|
+
- - ~>
|
164
|
+
- !ruby/object:Gem::Version
|
165
|
+
version: 1.6.5
|
166
|
+
type: :development
|
167
|
+
prerelease: false
|
168
|
+
version_requirements: !ruby/object:Gem::Requirement
|
169
|
+
none: false
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 1.6.5
|
174
|
+
- !ruby/object:Gem::Dependency
|
175
|
+
name: simplecov
|
176
|
+
requirement: !ruby/object:Gem::Requirement
|
177
|
+
none: false
|
178
|
+
requirements:
|
179
|
+
- - ~>
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: 0.6.1
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
none: false
|
186
|
+
requirements:
|
187
|
+
- - ~>
|
188
|
+
- !ruby/object:Gem::Version
|
189
|
+
version: 0.6.1
|
190
|
+
- !ruby/object:Gem::Dependency
|
191
|
+
name: simplecov-rcov
|
192
|
+
requirement: !ruby/object:Gem::Requirement
|
193
|
+
none: false
|
194
|
+
requirements:
|
195
|
+
- - ~>
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: 0.2.3
|
198
|
+
type: :development
|
199
|
+
prerelease: false
|
200
|
+
version_requirements: !ruby/object:Gem::Requirement
|
201
|
+
none: false
|
202
|
+
requirements:
|
203
|
+
- - ~>
|
204
|
+
- !ruby/object:Gem::Version
|
205
|
+
version: 0.2.3
|
206
|
+
- !ruby/object:Gem::Dependency
|
207
|
+
name: aws-s3
|
208
|
+
requirement: !ruby/object:Gem::Requirement
|
209
|
+
none: false
|
210
|
+
requirements:
|
211
|
+
- - ~>
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
version: 0.6.3
|
214
|
+
type: :development
|
215
|
+
prerelease: false
|
216
|
+
version_requirements: !ruby/object:Gem::Requirement
|
217
|
+
none: false
|
218
|
+
requirements:
|
219
|
+
- - ~>
|
220
|
+
- !ruby/object:Gem::Version
|
221
|
+
version: 0.6.3
|
222
|
+
description: Cloud Foundry auto-reconfiguration for Ruby
|
223
|
+
email: support@vmware.com
|
224
|
+
executables: []
|
225
|
+
extensions: []
|
226
|
+
extra_rdoc_files:
|
227
|
+
- LICENSE
|
228
|
+
files:
|
229
|
+
- LICENSE
|
230
|
+
- lib/cfautoconfig/blob/aws_s3.rb
|
231
|
+
- lib/cfautoconfig/blob/aws_s3_configurer.rb
|
232
|
+
- lib/cfautoconfig/configuration_helper.rb
|
233
|
+
- lib/cfautoconfig/configurer.rb
|
234
|
+
- lib/cfautoconfig/document/mongodb.rb
|
235
|
+
- lib/cfautoconfig/document/mongodb_configurer.rb
|
236
|
+
- lib/cfautoconfig/keyvalue/redis.rb
|
237
|
+
- lib/cfautoconfig/keyvalue/redis_configurer.rb
|
238
|
+
- lib/cfautoconfig/messaging/amqp.rb
|
239
|
+
- lib/cfautoconfig/messaging/amqp_configurer.rb
|
240
|
+
- lib/cfautoconfig/messaging/carrot.rb
|
241
|
+
- lib/cfautoconfig/messaging/carrot_configurer.rb
|
242
|
+
- lib/cfautoconfig/relational/mysql.rb
|
243
|
+
- lib/cfautoconfig/relational/mysql_configurer.rb
|
244
|
+
- lib/cfautoconfig/relational/postgres.rb
|
245
|
+
- lib/cfautoconfig/relational/postgres_configurer.rb
|
246
|
+
- lib/cfautoconfig/version.rb
|
247
|
+
- lib/cfautoconfig.rb
|
248
|
+
homepage: http://vmware.com
|
249
|
+
licenses: []
|
250
|
+
post_install_message:
|
251
|
+
rdoc_options:
|
252
|
+
- -N
|
253
|
+
- --tab-width=2
|
254
|
+
- --exclude='cf-autoconfig.gemspec|spec'
|
255
|
+
require_paths:
|
256
|
+
- lib
|
257
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
258
|
+
none: false
|
259
|
+
requirements:
|
260
|
+
- - ! '>='
|
261
|
+
- !ruby/object:Gem::Version
|
262
|
+
version: '0'
|
263
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
264
|
+
none: false
|
265
|
+
requirements:
|
266
|
+
- - ! '>='
|
267
|
+
- !ruby/object:Gem::Version
|
268
|
+
version: '0'
|
269
|
+
requirements: []
|
270
|
+
rubyforge_project:
|
271
|
+
rubygems_version: 1.8.24
|
272
|
+
signing_key:
|
273
|
+
specification_version: 3
|
274
|
+
summary: Cloud Foundry auto-reconfiguration for Ruby
|
275
|
+
test_files: []
|