platform_sh 0.2.3 → 0.2.4
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 +4 -4
- data/lib/platform_sh.rb +70 -21
- data/lib/platform_sh/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 557c7b76ab879a1d8ed7683b02b6e5440b7003ba
|
4
|
+
data.tar.gz: 73f9f29e020929824a6a1e8140532dd27e844dd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc9631b086ae4b5e76ae843e09193b23f65c49b030d299d1ccb6ca2adad718988b5313deb80fcbb40ed97a9ee402195d9a608307a27849b509890b23a88fb9e5
|
7
|
+
data.tar.gz: e2b1b759d75c824c93f0c3b51ea09f50be34f2cc919ed03ea21748f66a9ba91fcb8bad2f38d597f3387838b4e4be68366689c6394bcdb08a5b64e2391035c4e5
|
data/lib/platform_sh.rb
CHANGED
@@ -55,29 +55,78 @@ class PlatformSH
|
|
55
55
|
JSON.parse(File.read('/run/config.json'))
|
56
56
|
end
|
57
57
|
|
58
|
+
|
58
59
|
#Tries to guess relational database url
|
59
60
|
def self.guess_database_url
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
when "mysql"
|
70
|
-
scheme = "mysql2"
|
71
|
-
when "pgsql"
|
72
|
-
scheme = "postgresql"
|
73
|
-
else
|
74
|
-
scheme = database['scheme']
|
75
|
-
end
|
76
|
-
database_url = "#{scheme}://#{database['username']}:#{database['password']}@#{database['host']}:#{database['port']}/#{database['path']}"
|
77
|
-
return database_url
|
78
|
-
else
|
79
|
-
$stderr.puts "More than one database, giving up, set configuration by hand"
|
61
|
+
postgresql_url = self.guess_postgresql_url
|
62
|
+
mysql_url = self.guess_mysql_url
|
63
|
+
if !mysql_url.nil? && !postgresql_url.nil?
|
64
|
+
$stderr.puts "More than one relational database, giving up, set configuration by hand"
|
65
|
+
return nil
|
66
|
+
end
|
67
|
+
if (mysql_url.nil? && postgresql_url.nil?)
|
68
|
+
$stderr.puts "Could not find a relational database"
|
69
|
+
return nil
|
80
70
|
end
|
71
|
+
return mysql_url || postgresql_url
|
81
72
|
end
|
82
73
|
|
83
|
-
|
74
|
+
def self.guess_url(service_type, platform_scheme, url_template)
|
75
|
+
services = PlatformSH::config["relationships"].select {|k,v| v[0]["scheme"]==platform_scheme}
|
76
|
+
case services.length
|
77
|
+
when 0
|
78
|
+
$stderr.puts "Could not find an #{service_type}"
|
79
|
+
return nil
|
80
|
+
when 1
|
81
|
+
service = services.first[1][0]
|
82
|
+
service = service.each_with_object({}){|(k,v), h| h[k.to_sym] = v} #keys need to be symbols
|
83
|
+
return url_template % service
|
84
|
+
else
|
85
|
+
$stderr.puts "More than one #{service_type}, giving up, set configuration by hand"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def self.guess_elasticsearch_url
|
90
|
+
self.guess_url("elasticsearch", "http", "http://%{host}:%{port}")
|
91
|
+
end
|
92
|
+
|
93
|
+
def self.guess_redis_url
|
94
|
+
self.guess_url("redis", "redis", "redis://%{host}:%{port}")
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.guess_mongodb_url
|
98
|
+
self.guess_url("mongodb", "mongodb", "mongodb://%{username}:%{password}@%{host}:%{port}/%{path}")
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.guess_solr_url
|
102
|
+
self.guess_url("solr", "solr", "http://%{host}:%{port}/%{path}")
|
103
|
+
end
|
104
|
+
|
105
|
+
def self.guess_mysql_url
|
106
|
+
#fallback to mysql url if mysql2 gem is not loaded
|
107
|
+
if Gem::Specification::find_all_by_name("mysql2").empty?
|
108
|
+
template = "mysql://%{username}:%{password}@%{host}:%{port}/%{path}"
|
109
|
+
else
|
110
|
+
template = "mysql2://%{username}:%{password}@%{host}:%{port}/%{path}"
|
111
|
+
end
|
112
|
+
self.guess_url("mysql", "mysql",template)
|
113
|
+
end
|
114
|
+
|
115
|
+
def self.guess_rabbitmq_url
|
116
|
+
self.guess_url("rabbitmq", "amqp","amqp://%{username}:%{password}@%{host}:%{port}")
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.guess_postgresql_url
|
120
|
+
self.guess_url("postgresql", "pgsql","postgresql://%{username}:%{password}@%{host}:%{port}")
|
121
|
+
end
|
122
|
+
|
123
|
+
def self.export_services_urls
|
124
|
+
ENV['DATABASE_URL']=PlatformSH::guess_database_url
|
125
|
+
ENV['MONGODB_URL']=PlatformSH::guess_mongodb_url
|
126
|
+
ENV['REDIS_URL']=PlatformSH::guess_redis_url
|
127
|
+
ENV['ELASTICSEARCH_URL']=PlatformSH::guess_redis_url
|
128
|
+
ENV['RABBITMQ_URL']=PlatformSH::guess_rabbitmq_url
|
129
|
+
ENV['SOLR_URL']=PlatformSH::guess_solr_url
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
data/lib/platform_sh/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: platform_sh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ori Pekelman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-12-
|
11
|
+
date: 2016-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|