platform_sh 0.1.2 → 0.2.0
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/version.rb +1 -1
- data/lib/platform_sh.rb +46 -16
- data/platform.gemspec +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e85e959466efdc7947188a49c24bbf8d508aabbb
|
4
|
+
data.tar.gz: 29a2407e0292ab7c60ea385ec0dd641b0a5823ff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11e4d689feaa4a4bd9c97aa0389ea02af2bf1f4d2d81ddc1d295f686672f5de125fc9be12a6497510273133184734ae0b1e165ba80141f0f893d1ee51ea4947e
|
7
|
+
data.tar.gz: f31c2b20861179550aba4d9a38d1eecd5b3170f5a62e7c876ac8dfe676031041d48622abe3d51154e690bf21d04612962eddfd12d4060f4c716423520bc53d4a
|
data/lib/platform_sh/version.rb
CHANGED
data/lib/platform_sh.rb
CHANGED
@@ -3,28 +3,42 @@ require "base64"
|
|
3
3
|
require 'json'
|
4
4
|
|
5
5
|
class PlatformSH
|
6
|
-
'use strict'
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
6
|
+
'use strict'
|
7
|
+
# Reads Platform.sh configuration from environment and returns a single object
|
8
|
+
def self.config
|
9
|
+
if on_platform?
|
10
|
+
conf = {}
|
11
|
+
conf["application"] = read_base64_json('PLATFORM_APPLICATION')
|
12
|
+
conf["application_name"] =ENV["PLATFORM_APPLICATION_NAME"] || nil
|
13
|
+
conf["app_dir"] =ENV["PLATFORM_APP_DIR"] || nil
|
14
|
+
conf["project"] =ENV["PLATFORM_PROJECT"] || nil
|
15
|
+
conf["document_root"] =ENV["PLATFORM_DOCUMENT_ROOT"] || nil
|
16
|
+
if !is_build_environment?
|
17
17
|
conf["environment"] =ENV["PLATFORM_ENVIRONMENT"] || nil
|
18
18
|
conf["project_entropy"] =ENV["PLATFORM_PROJECT_ENTROPY"] || nil
|
19
|
-
conf["project"] =ENV["PLATFORM_PROJECT"] || nil
|
20
19
|
conf["port"] =ENV["PORT"] || nil
|
21
20
|
conf["socket"] =ENV["SOCKET"] || nil
|
22
|
-
|
23
|
-
|
24
|
-
return nil
|
21
|
+
conf["relationships"] = read_base64_json('PLATFORM_RELATIONSHIPS')
|
22
|
+
conf["variables"] = read_base64_json('PLATFORM_VARIABLES')
|
25
23
|
end
|
26
|
-
|
24
|
+
else
|
25
|
+
$stderr.puts "This is not running on platform.sh"
|
26
|
+
return nil
|
27
27
|
end
|
28
|
+
conf
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.on_platform?
|
32
|
+
ENV.has_key? 'PLATFORM_PROJECT'
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.is_build_environment?
|
36
|
+
(!ENV.has_key?('PLATFORM_ENVIRONMENT') && ENV.has_key?('PLATFORM_PROJECT'))
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.relationship rel_name, attr
|
40
|
+
on_platform? ? config["relationships"][rel_name].first[attr] : nil
|
41
|
+
end
|
28
42
|
|
29
43
|
private
|
30
44
|
def self.read_base64_json(var_name)
|
@@ -41,4 +55,20 @@ class PlatformSH
|
|
41
55
|
JSON.parse(File.read('/run/config.json'))
|
42
56
|
end
|
43
57
|
|
58
|
+
#Tries to guess relational database url
|
59
|
+
def self.guess_database_url
|
60
|
+
databases = PlatformSH::config["relationships"].select {|k,v| v[0]["scheme"]=="mysql" || v[0]["scheme"]=="postgresql"}
|
61
|
+
case databases.length
|
62
|
+
when 0
|
63
|
+
$stderr.puts "Could not find a relational database"
|
64
|
+
return nil
|
65
|
+
when 1
|
66
|
+
database = databases.first[1][0]
|
67
|
+
database_url = "#{database['scheme']}://#{database['username']}:#{database['password']}@#{database['host']}:#{database['port']}/#{database['path']}"
|
68
|
+
return database_url
|
69
|
+
else
|
70
|
+
$stderr.puts "More than one database, giving up, set configuration by hand"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
44
74
|
end
|
data/platform.gemspec
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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2016-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: byebug
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
55
69
|
description: Platform.sh helper gem to ease interacting with the environment
|
56
70
|
email:
|
57
71
|
- ori@platform.sh
|