platform_sh 0.2.9 → 0.2.10

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b6af1db4bf930f94f759a2c575532f76c8e0b8cfb9f31be4a65fc4b9f422409
4
- data.tar.gz: e984ea591ecda012d3f569fe3f05dd5aa58b423cc6508e8b4176246a3b6d1e77
3
+ metadata.gz: 8efa540d7fa320ebed86198301fd0f4dbdd67f254296b5e9d5842b59bde9ef1b
4
+ data.tar.gz: ee662935f81bf55da217f33e3699b5aefa423b662d439ec2080c7b7a9a641aa1
5
5
  SHA512:
6
- metadata.gz: edd2a3c6b3711f8ecd193968aecbd198fbf93428f78a72d3361d76432bd51a728ed199005f2a90e0a1ceae6d34780f444f55161a79776919bbb8e01c434c5034
7
- data.tar.gz: ebf82517232fdf704d9b5d517fb6049af604301235f96b88a298600178dfb1238294d707968edf44c12623385f5617a443595c5e5b7745fad4810d8753ffab70
6
+ metadata.gz: e6ee450b5383b5d8aa02771942ea9f192affe0dca9e0b7115c61552cd286f9ea88a97f726f0dd073234df5d24dac6f1ebe2de5c9e4419097b372533300f851e2
7
+ data.tar.gz: 3dc69475a823389401b291c34e0eb667e9749e6c31067d66d189e014eb290f2e88f5cba95a883bb3879a7adb90ed55ecd3603380b23e5a61f2bf694320b9e163
@@ -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
- 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
103
- case services.length
104
- when 0
105
- $logger.info "Could not find an #{scheme}"
106
- return nil
107
- when 1
108
- service = services.first[1][0]
109
- service = service.each_with_object({}){|(k,v), h| h[k.to_sym] = v} #keys need to be symbols
110
- return url_template % service
111
- else
112
- $logger.warn "More than one #{scheme}, giving up, set configuration by hand"
113
- return nil
114
- end
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
@@ -1,3 +1,3 @@
1
1
  class PlatformSH
2
- VERSION = "0.2.9"
2
+ VERSION = "0.2.10"
3
3
  end
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.9
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-02-06 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler