cf-app-utils 0.4 → 0.6
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 +4 -4
- data/README.md +6 -1
- data/lib/cf-app-utils/cf/app/credentials.rb +63 -21
- data/lib/cf-app-utils/cf/app/service.rb +5 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b06c1f28aaf815c8d05d16ca2bfa75ba89afb53
|
4
|
+
data.tar.gz: b929438f367b7fc1ebf01851403ce98914e3e8f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d50b5c16ab0c2751e1a35f8c9f2bb3485fd100cddfb2cef469fd2d6e1f6342fdb777ebe5d72d1037be54772ed80f9bf216a6201d587eb47e237a192ac8400d5
|
7
|
+
data.tar.gz: b2bfe53032e67d817c674705367c3c47f29c2bc92c3f8186c3888a9c43bb8a83ce5283c195fc52a15e2a9e0cb3737cb157d2694ccd02589ed3cb40e798d6cf1b
|
data/README.md
CHANGED
@@ -40,7 +40,7 @@ CF::App::Credentials.find_by_service_name('master-db')
|
|
40
40
|
CF::App::Credentials.find_by_service_tag('relational')
|
41
41
|
|
42
42
|
# Get credentials for all service instances with the given tag
|
43
|
-
CF::
|
43
|
+
CF::App::Credentials.find_all_by_service_tag('relational')
|
44
44
|
|
45
45
|
# Get credentials for all service instances that match all of the given tags
|
46
46
|
CF::App::Credentials.find_all_by_all_service_tags(['cleardb', 'relational'])
|
@@ -57,3 +57,8 @@ The keys in the hash are strings. For example, to get the `uri` value you can do
|
|
57
57
|
```ruby
|
58
58
|
cleardb_url = credentials['uri']
|
59
59
|
```
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
# Inject your own environment variables
|
63
|
+
CF::App::Credentials.new(my_env)
|
64
|
+
```
|
@@ -1,45 +1,87 @@
|
|
1
1
|
module CF::App
|
2
2
|
class Credentials
|
3
3
|
class << self
|
4
|
-
# Returns credentials for the service instance with the given +name+.
|
5
4
|
def find_by_service_name(name)
|
6
|
-
|
7
|
-
service['credentials'] if service
|
8
|
-
end
|
9
|
-
|
10
|
-
# Returns credentials for the first service instance with the given +tag+.
|
11
|
-
def find_by_service_tag(tag)
|
12
|
-
service = Service.find_by_tag(tag)
|
13
|
-
service['credentials'] if service
|
5
|
+
credentials.find_by_service_name(name)
|
14
6
|
end
|
15
7
|
|
16
8
|
def find_all_by_service_tag(tag)
|
17
|
-
|
18
|
-
services.map do |service|
|
19
|
-
service['credentials']
|
20
|
-
end
|
9
|
+
credentials.find_all_by_service_tag(tag)
|
21
10
|
end
|
22
11
|
|
23
12
|
# Returns credentials for the service instances with all the given +tags+.
|
24
13
|
def find_all_by_all_service_tags(tags)
|
25
|
-
|
14
|
+
credentials.find_all_by_all_service_tags(tags)
|
15
|
+
end
|
26
16
|
|
27
|
-
|
17
|
+
# Returns credentials for the first service instance with the given +tag+.
|
18
|
+
def find_by_service_tag(tag)
|
19
|
+
credentials.find_by_service_tag(tag)
|
28
20
|
end
|
29
21
|
|
30
22
|
# Returns credentials for the first service instance with the given +label+.
|
31
23
|
def find_by_service_label(label)
|
32
|
-
|
33
|
-
service['credentials'] if service
|
24
|
+
credentials.find_by_service_label(label)
|
34
25
|
end
|
35
26
|
|
36
27
|
# Returns credentials for all service instances with the given +label+.
|
37
28
|
def find_all_by_service_label(label)
|
38
|
-
|
39
|
-
services.map do |service|
|
40
|
-
service['credentials']
|
41
|
-
end
|
29
|
+
credentials.find_all_by_service_label(label)
|
42
30
|
end
|
31
|
+
|
32
|
+
def credentials
|
33
|
+
Credentials.new(ENV)
|
34
|
+
end
|
35
|
+
private :credentials
|
36
|
+
end
|
37
|
+
|
38
|
+
def initialize(env)
|
39
|
+
@locator = Service.new(env)
|
40
|
+
end
|
41
|
+
|
42
|
+
# Returns credentials for the service instance with the given +name+.
|
43
|
+
def find_by_service_name(name)
|
44
|
+
service = locator.find_by_name(name)
|
45
|
+
service['credentials'] if service
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns credentials for the first service instance with the given +tag+.
|
49
|
+
def find_by_service_tag(tag)
|
50
|
+
service = locator.find_by_tag(tag)
|
51
|
+
service['credentials'] if service
|
43
52
|
end
|
53
|
+
|
54
|
+
def find_all_by_service_tag(tag)
|
55
|
+
services = locator.find_all_by_tag(tag)
|
56
|
+
services.map do |service|
|
57
|
+
service['credentials']
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# Returns credentials for the service instances with all the given +tags+.
|
62
|
+
def find_all_by_all_service_tags(tags)
|
63
|
+
return [] if tags.empty?
|
64
|
+
|
65
|
+
locator.find_all_by_tags(tags).map { |service| service['credentials'] }
|
66
|
+
end
|
67
|
+
|
68
|
+
# Returns credentials for the first service instance with the given +label+.
|
69
|
+
def find_by_service_label(label)
|
70
|
+
service = locator.find_by_label(label)
|
71
|
+
service['credentials'] if service
|
72
|
+
end
|
73
|
+
|
74
|
+
# Returns credentials for all service instances with the given +label+.
|
75
|
+
def find_all_by_service_label(label)
|
76
|
+
services = locator.find_all_by_label(label)
|
77
|
+
services.map do |service|
|
78
|
+
service['credentials']
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
attr_reader :locator
|
85
|
+
|
44
86
|
end
|
45
87
|
end
|
@@ -2,7 +2,10 @@ require 'json'
|
|
2
2
|
|
3
3
|
module CF::App
|
4
4
|
class Service #:nodoc:
|
5
|
-
|
5
|
+
def initialize(env = ENV)
|
6
|
+
@env = env
|
7
|
+
end
|
8
|
+
|
6
9
|
def find_by_name(name)
|
7
10
|
all.detect do |service|
|
8
11
|
service['name'] == name
|
@@ -40,8 +43,7 @@ module CF::App
|
|
40
43
|
private
|
41
44
|
|
42
45
|
def all
|
43
|
-
@services ||= JSON.parse(
|
46
|
+
@services ||= JSON.parse(@env['VCAP_SERVICES']).values.flatten
|
44
47
|
end
|
45
|
-
end
|
46
48
|
end
|
47
49
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cf-app-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cloud Foundry
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -85,7 +85,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
85
85
|
version: '0'
|
86
86
|
requirements: []
|
87
87
|
rubyforge_project:
|
88
|
-
rubygems_version: 2.2.
|
88
|
+
rubygems_version: 2.2.3
|
89
89
|
signing_key:
|
90
90
|
specification_version: 4
|
91
91
|
summary: Helper methods for apps running on Cloud Foundry
|