cloudfoundry-env 0.0.2 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/README.md +77 -0
- data/cloudfoundry-env.gemspec +1 -1
- data/lib/cloudfoundry/environment.rb +4 -0
- data/lib/cloudfoundry/version.rb +1 -1
- data/spec/environment_spec.rb +6 -0
- metadata +9 -7
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
This is a small gem which an application running on a Cloud Foundry instance can use to access their environment.
|
2
|
+
If the application is not running on Cloud Foundry then all methods will return nil so its easy to provide an alternate configuration.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
### Command Line
|
7
|
+
```bash
|
8
|
+
gem install cloudfoundry-env
|
9
|
+
```
|
10
|
+
|
11
|
+
### Gemfile
|
12
|
+
|
13
|
+
``` ruby
|
14
|
+
gem "cloudfoundry-env","~> 0.0.2", :require => "cloudfoundry/environment"
|
15
|
+
```
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
#### Listening on the proper HTTP port
|
20
|
+
|
21
|
+
``` ruby
|
22
|
+
configure do
|
23
|
+
set(:port, CloudFoundry::Environment.port || 4567)
|
24
|
+
end
|
25
|
+
```
|
26
|
+
|
27
|
+
#### Connecting to a service
|
28
|
+
|
29
|
+
``` ruby
|
30
|
+
@redis = Redis.new(CloudFoundry::Environment.redis_cnx || {host: "127.0.0.1", port: "6379"})
|
31
|
+
```
|
32
|
+
|
33
|
+
#### Conditional logic for multiple instances of an app
|
34
|
+
|
35
|
+
``` ruby
|
36
|
+
# The new wordpress path
|
37
|
+
@blog_rss = "#{@blog}/post/category/announcement/feed"
|
38
|
+
|
39
|
+
freq = 60 + (60 * 5 * (CloudFoundry::Environment.instance_index || 0))
|
40
|
+
|
41
|
+
@blog_feed = CloudFoundry::Feed.new(@blog_rss, @redis, crawl_frequency: freq)
|
42
|
+
|
43
|
+
```
|
44
|
+
|
45
|
+
## CloudFoundry::Environment Methods
|
46
|
+
|
47
|
+
* host - Return a string with the host ip address or nil if not running on cloud
|
48
|
+
* port - Returns integer with port number
|
49
|
+
* instance_index - Returns integer with instance index starting at 1
|
50
|
+
* running_local? - returns `true` if the app is not running on a CloudFoundry instance
|
51
|
+
* is_prod_app?(regex) - Returns `true` if the app name starts with regex provided. Good for having staging and prod apps
|
52
|
+
|
53
|
+
* services - Returns a Hashie::Mash representation of the services so it can be used as a class with native attributes
|
54
|
+
* Cloud Foundry Services - http://start.cloudfoundry.com/services.html
|
55
|
+
* Hashie - https://github.com/intridea/hashie
|
56
|
+
* [service_name]_cnx - Returns a Hashie::Mash representation of only the credentials for a service. Example from rspec test:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
cf = CloudFoundry::Environment
|
60
|
+
cf.redis_cnx.port.should == 5076
|
61
|
+
cf.redis_cnx.host.should == "172.30.48.40"
|
62
|
+
cf.redis_cnx.password.should == "49badd9d-40a9-aaa-4e8fcdc15a75"
|
63
|
+
```
|
64
|
+
|
65
|
+
* [service_name]_info - Returns a Hashie::Mash representation of the service. Example from rspec test:
|
66
|
+
|
67
|
+
``` ruby
|
68
|
+
cf = CloudFoundry::Environment
|
69
|
+
cf.mongo_info.name.should == "mongodb-78564"
|
70
|
+
cf.mongo_info.credentials.port.should == 25084
|
71
|
+
cf.mongo_cnx.host.should == "172.30.48.64"
|
72
|
+
cf.mongo_cnx.db.should == "db"
|
73
|
+
cf.mongo_cnx.username.should == "1aaca416-fb89-4a08-8b7b-3d022ef3c44b"
|
74
|
+
cf.mongo_cnx.password.should == "7ea3c7ab-bd10-4ff9-8131-50d951b5863f"
|
75
|
+
```
|
76
|
+
|
77
|
+
|
data/cloudfoundry-env.gemspec
CHANGED
@@ -7,7 +7,7 @@ Gem::Specification.new do |s|
|
|
7
7
|
s.version = Cloudfoundry::Environment::VERSION
|
8
8
|
s.authors = ["ciberch"]
|
9
9
|
s.email = ["monica.keller@gmail.com"]
|
10
|
-
s.homepage = "
|
10
|
+
s.homepage = "https://github.com/cloudfoundry-samples/cloudfoundry-env"
|
11
11
|
s.summary = "Ruby Apps can use gem to parse the Cloud Foundry Environment"
|
12
12
|
s.description = "App Name, App Owner, Port Number, Host, Services, Instances"
|
13
13
|
|
data/lib/cloudfoundry/version.rb
CHANGED
data/spec/environment_spec.rb
CHANGED
@@ -10,6 +10,12 @@ describe "CloudFoundry::Environment" do
|
|
10
10
|
cf.redis_cnx.should be_nil
|
11
11
|
end
|
12
12
|
|
13
|
+
it "should read the host" do
|
14
|
+
CloudFoundry::Environment.host.should be_nil
|
15
|
+
ENV["VCAP_APP_HOST"] = "localhost"
|
16
|
+
CloudFoundry::Environment.host.should == "localhost"
|
17
|
+
end
|
18
|
+
|
13
19
|
it "should recognize when its running on Cloud Foundry" do
|
14
20
|
ENV["VCAP_APP_PORT"] = "9456"
|
15
21
|
ENV["VCAP_APPLICATION"] = load_fixture("vcap_application.json")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cloudfoundry-env
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
12
|
+
date: 2012-03-19 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70203930070160 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70203930070160
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hashie
|
27
|
-
requirement: &
|
27
|
+
requirement: &70203930069740 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,7 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70203930069740
|
36
36
|
description: App Name, App Owner, Port Number, Host, Services, Instances
|
37
37
|
email:
|
38
38
|
- monica.keller@gmail.com
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- .rspec
|
45
45
|
- .rvmrc
|
46
46
|
- Gemfile
|
47
|
+
- README.md
|
47
48
|
- Rakefile
|
48
49
|
- cloudfoundry-env.gemspec
|
49
50
|
- lib/cloudfoundry/environment.rb
|
@@ -57,7 +58,7 @@ files:
|
|
57
58
|
- spec/spec_helper.rb
|
58
59
|
- spec/test_app/Gemfile
|
59
60
|
- spec/test_app/sample.rb
|
60
|
-
homepage:
|
61
|
+
homepage: https://github.com/cloudfoundry-samples/cloudfoundry-env
|
61
62
|
licenses: []
|
62
63
|
post_install_message:
|
63
64
|
rdoc_options: []
|
@@ -91,3 +92,4 @@ test_files:
|
|
91
92
|
- spec/spec_helper.rb
|
92
93
|
- spec/test_app/Gemfile
|
93
94
|
- spec/test_app/sample.rb
|
95
|
+
has_rdoc:
|