cf-app-utils 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +22 -0
- data/README.md +43 -0
- data/lib/cf-app-utils.rb +1 -0
- data/lib/cf-app-utils/cf.rb +4 -0
- data/lib/cf-app-utils/cf/app/credentials.rb +23 -0
- data/lib/cf-app-utils/cf/app/service.rb +40 -0
- metadata +106 -0
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Cloud Foundry
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# cf-app-utils
|
2
|
+
|
3
|
+
Helper methods for apps running on Cloud Foundry.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'cf-app-utils'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install cf-app-utils
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Require and use the gem in your application:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
require 'cf-app-utils'
|
27
|
+
```
|
28
|
+
|
29
|
+
### CF::App::Credentials.find\_by\_service\_*
|
30
|
+
|
31
|
+
Returns the credentials hash for a given service that you have bound to
|
32
|
+
your application.
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
# Get credentials for the service with the given name
|
36
|
+
CF::App::Credentials.find_by_service_name('master-db')
|
37
|
+
|
38
|
+
# Get credentials for the first service with the given tag
|
39
|
+
CF::App::Credentials.find_by_service_tag('relational')
|
40
|
+
|
41
|
+
# Get credentials for the first service with the given label
|
42
|
+
CF::App::Credentials.find_by_service_label('cleardb')
|
43
|
+
```
|
data/lib/cf-app-utils.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'cf-app-utils/cf'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CF::App
|
2
|
+
class Credentials
|
3
|
+
class << self
|
4
|
+
# Returns credentials for the service with the given +name+.
|
5
|
+
def find_by_service_name(name)
|
6
|
+
service = Service.find_by_name(name)
|
7
|
+
service['credentials'] if service
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns credentials for the first service with the given +tag+.
|
11
|
+
def find_by_service_tag(tag)
|
12
|
+
service = Service.find_by_tag(tag)
|
13
|
+
service['credentials'] if service
|
14
|
+
end
|
15
|
+
|
16
|
+
# Returns credentials for the first service with the given +label+.
|
17
|
+
def find_by_service_label(label)
|
18
|
+
service = Service.find_by_label(label)
|
19
|
+
service['credentials'] if service
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module CF::App
|
4
|
+
class Service #:nodoc:
|
5
|
+
class << self
|
6
|
+
def find_by_name(name)
|
7
|
+
all.detect do |service|
|
8
|
+
service['name'] == name
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def find_by_tag(tag)
|
13
|
+
all.detect do |service|
|
14
|
+
service['tags'].include?(tag)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def find_by_label(label)
|
19
|
+
all.detect do |service|
|
20
|
+
service['label'] == label
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def all
|
27
|
+
@services ||= begin
|
28
|
+
services = JSON.parse(ENV['VCAP_SERVICES']).map(&:last).flatten
|
29
|
+
services.map do |service|
|
30
|
+
service['label'] =~ /^(.*)-(.*)$/
|
31
|
+
label, version = $1, $2
|
32
|
+
service['label'] = label
|
33
|
+
service['version'] = version
|
34
|
+
service
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cf-app-utils
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cloud Foundry
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: Helper methods for apps running on Cloud Foundry
|
63
|
+
email:
|
64
|
+
- vcap-dev@cloudfoundry.org
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- lib/cf-app-utils/cf/app/credentials.rb
|
70
|
+
- lib/cf-app-utils/cf/app/service.rb
|
71
|
+
- lib/cf-app-utils/cf.rb
|
72
|
+
- lib/cf-app-utils.rb
|
73
|
+
- LICENSE.txt
|
74
|
+
- README.md
|
75
|
+
homepage: ''
|
76
|
+
licenses:
|
77
|
+
- MIT
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
segments:
|
89
|
+
- 0
|
90
|
+
hash: 1116896598145755807
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
hash: 1116896598145755807
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.23
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Helper methods for apps running on Cloud Foundry
|
106
|
+
test_files: []
|