platform_sh 0.2.9 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/platform_sh.rb +58 -30
- data/lib/platform_sh/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8efa540d7fa320ebed86198301fd0f4dbdd67f254296b5e9d5842b59bde9ef1b
|
4
|
+
data.tar.gz: ee662935f81bf55da217f33e3699b5aefa423b662d439ec2080c7b7a9a641aa1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6ee450b5383b5d8aa02771942ea9f192affe0dca9e0b7115c61552cd286f9ea88a97f726f0dd073234df5d24dac6f1ebe2de5c9e4419097b372533300f851e2
|
7
|
+
data.tar.gz: 3dc69475a823389401b291c34e0eb667e9749e6c31067d66d189e014eb290f2e88f5cba95a883bb3879a7adb90ed55ecd3603380b23e5a61f2bf694320b9e163
|
data/lib/platform_sh.rb
CHANGED
@@ -13,26 +13,25 @@ class PlatformSH
|
|
13
13
|
'use strict'
|
14
14
|
# Reads Platform.sh configuration from environment and returns a single object
|
15
15
|
def self.config
|
16
|
-
if on_platform?
|
17
|
-
conf = {}
|
18
|
-
conf["application"] = read_base64_json('PLATFORM_APPLICATION')
|
19
|
-
conf["routes"] = read_base64_json('PLATFORM_ROUTES')
|
20
|
-
conf["application_name"] =ENV["PLATFORM_APPLICATION_NAME"] || nil
|
21
|
-
conf["app_dir"] =ENV["PLATFORM_APP_DIR"] || nil
|
22
|
-
conf["project"] =ENV["PLATFORM_PROJECT"] || nil
|
23
|
-
conf["document_root"] =ENV["PLATFORM_DOCUMENT_ROOT"] || nil
|
24
|
-
if !is_build_environment?
|
25
|
-
conf["environment"] =ENV["PLATFORM_ENVIRONMENT"] || nil
|
26
|
-
conf["project_entropy"] =ENV["PLATFORM_PROJECT_ENTROPY"] || nil
|
27
|
-
conf["port"] =ENV["PORT"] || nil
|
28
|
-
conf["socket"] =ENV["SOCKET"] || nil
|
29
|
-
conf["relationships"] = read_base64_json('PLATFORM_RELATIONSHIPS')
|
30
|
-
conf["variables"] = read_base64_json('PLATFORM_VARIABLES')
|
31
|
-
end
|
32
|
-
else
|
16
|
+
if !on_platform?
|
33
17
|
$logger.info "This is not running on platform.sh"
|
34
18
|
return nil
|
35
19
|
end
|
20
|
+
conf = {}
|
21
|
+
conf["application"] = read_base64_json('PLATFORM_APPLICATION')
|
22
|
+
conf["routes"] = read_base64_json('PLATFORM_ROUTES')
|
23
|
+
conf["application_name"] =ENV["PLATFORM_APPLICATION_NAME"] || nil
|
24
|
+
conf["app_dir"] =ENV["PLATFORM_APP_DIR"] || nil
|
25
|
+
conf["project"] =ENV["PLATFORM_PROJECT"] || nil
|
26
|
+
conf["document_root"] =ENV["PLATFORM_DOCUMENT_ROOT"] || nil
|
27
|
+
if !is_build_environment?
|
28
|
+
conf["environment"] =ENV["PLATFORM_ENVIRONMENT"] || nil
|
29
|
+
conf["project_entropy"] =ENV["PLATFORM_PROJECT_ENTROPY"] || nil
|
30
|
+
conf["port"] =ENV["PORT"] || nil
|
31
|
+
conf["socket"] =ENV["SOCKET"] || nil
|
32
|
+
conf["relationships"] = read_base64_json('PLATFORM_RELATIONSHIPS')
|
33
|
+
conf["variables"] = read_base64_json('PLATFORM_VARIABLES')
|
34
|
+
end
|
36
35
|
conf
|
37
36
|
end
|
38
37
|
|
@@ -60,12 +59,25 @@ class PlatformSH
|
|
60
59
|
|
61
60
|
|
62
61
|
def self.read_app_config
|
62
|
+
if !on_platform?
|
63
|
+
$logger.info "This is not running on platform.sh"
|
64
|
+
return nil
|
65
|
+
end
|
63
66
|
#FIXME we should be able to get
|
64
67
|
JSON.parse(File.read('/run/config.json'))
|
65
68
|
end
|
66
69
|
|
67
70
|
#Tries to guess the hostname it takes the first upstream
|
68
71
|
def self.guess_hostname
|
72
|
+
if !on_platform?
|
73
|
+
$logger.info "This is not running on platform.sh"
|
74
|
+
return nil
|
75
|
+
end
|
76
|
+
if is_build_environment?
|
77
|
+
$logger.info "No hostname in build environment"
|
78
|
+
return nil
|
79
|
+
end
|
80
|
+
|
69
81
|
upstreams = PlatformSH::config["routes"].select {|k,v| v["type"]=="upstream"}
|
70
82
|
begin
|
71
83
|
if upstreams.length > 1
|
@@ -85,6 +97,14 @@ class PlatformSH
|
|
85
97
|
|
86
98
|
#Tries to guess relational database url
|
87
99
|
def self.guess_database_url
|
100
|
+
if !on_platform?
|
101
|
+
$logger.info "This is not running on platform.sh"
|
102
|
+
return nil
|
103
|
+
end
|
104
|
+
if is_build_environment?
|
105
|
+
$logger.info "No relationships in build environment"
|
106
|
+
return nil
|
107
|
+
end
|
88
108
|
postgresql_url = self.guess_postgresql_url
|
89
109
|
mysql_url = self.guess_mysql_url
|
90
110
|
if !mysql_url.nil? && !postgresql_url.nil?
|
@@ -99,19 +119,27 @@ class PlatformSH
|
|
99
119
|
end
|
100
120
|
|
101
121
|
def self.guess_url(scheme, url_template, port=nil)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
122
|
+
if !on_platform?
|
123
|
+
$logger.info "This is not running on platform.sh"
|
124
|
+
return nil
|
125
|
+
end
|
126
|
+
if is_build_environment?
|
127
|
+
$logger.info "No relationships in build environment"
|
128
|
+
return nil
|
129
|
+
end
|
130
|
+
services = PlatformSH::config["relationships"].select {|k,v| v[0]["scheme"]==scheme && (!port || v[0]["port"].to_s==port.to_s )} #For ElasticSearch and InfluxDB both on HTTP we also look at the port
|
131
|
+
case services.length
|
132
|
+
when 0
|
133
|
+
$logger.info "Could not find an #{scheme}"
|
134
|
+
return nil
|
135
|
+
when 1
|
136
|
+
service = services.first[1][0]
|
137
|
+
service = service.each_with_object({}){|(k,v), h| h[k.to_sym] = v} #keys need to be symbols
|
138
|
+
return url_template % service
|
139
|
+
else
|
140
|
+
$logger.warn "More than one #{scheme}, giving up, set configuration by hand"
|
141
|
+
return nil
|
142
|
+
end
|
115
143
|
end
|
116
144
|
|
117
145
|
def self.guess_elasticsearch_url
|
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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ori Pekelman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|