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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 58d63c9094472a6824a0252db3d4c5034e4e0f15
4
- data.tar.gz: 2b25890c2b08b980a41ed33ae29ff23d103c5375
3
+ metadata.gz: e85e959466efdc7947188a49c24bbf8d508aabbb
4
+ data.tar.gz: 29a2407e0292ab7c60ea385ec0dd641b0a5823ff
5
5
  SHA512:
6
- metadata.gz: 715d70462c14b32f25433d15be7fed660e19e8666c499d7afc402f626e2cf58c0ea14eb978fe7ce46485d04d8adabd6f629346df9a01eca96352efe532cbb138
7
- data.tar.gz: 3ddbe6b2f5530804e95f36742a43408caa5b0027e176353966275e22f08531718fca04732291ed3f83569d79a6cacef0464e8aa600835b27a2355e67d1013a27
6
+ metadata.gz: 11e4d689feaa4a4bd9c97aa0389ea02af2bf1f4d2d81ddc1d295f686672f5de125fc9be12a6497510273133184734ae0b1e165ba80141f0f893d1ee51ea4947e
7
+ data.tar.gz: f31c2b20861179550aba4d9a38d1eecd5b3170f5a62e7c876ac8dfe676031041d48622abe3d51154e690bf21d04612962eddfd12d4060f4c716423520bc53d4a
@@ -1,3 +1,3 @@
1
1
  class PlatformSH
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
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
- # Reads Platform.sh configuration from environment and returns a single object
8
- def self.config
9
- if ENV.has_key? "PLATFORM_PROJECT" then
10
- conf = {}
11
- conf["application"] = read_base64_json('PLATFORM_APPLICATION')
12
- conf["relationships"] = read_base64_json('PLATFORM_RELATIONSHIPS')
13
- conf["variables"] = read_base64_json('PLATFORM_VARIABLES')
14
- conf["application_name"] =ENV["PLATFORM_APPLICATION_NAME"] || nil
15
- conf["app_dir"] =ENV["PLATFORM_APP_DIR"] || nil
16
- conf["document_root"] =ENV["PLATFORM_DOCUMENT_ROOT"] || nil
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
- else
23
- $stderr.puts "This is not running on platform.sh"
24
- return nil
21
+ conf["relationships"] = read_base64_json('PLATFORM_RELATIONSHIPS')
22
+ conf["variables"] = read_base64_json('PLATFORM_VARIABLES')
25
23
  end
26
- return conf;
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
@@ -22,5 +22,5 @@ Gem::Specification.new do |spec|
22
22
  spec.add_development_dependency "bundler", "~> 1.12"
23
23
  spec.add_development_dependency "rake", "~> 10.0"
24
24
  spec.add_development_dependency "rspec", "~> 3.0"
25
-
25
+ spec.add_development_dependency "byebug"
26
26
  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.1.2
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-08-10 00:00:00.000000000 Z
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