cfoundry_helper 0.2.3 → 0.3.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: e9e5eea3ba6528384eca3da7e4e0f58ba46caf4f
4
- data.tar.gz: 9560df1f344b424b325e4c421f87731dcc087451
3
+ metadata.gz: adb8f6ca8a613c1c8b2cf30c86414353bd05a5cb
4
+ data.tar.gz: 0dc73d74b5abb77ca19a35de693fa90d5b53ad77
5
5
  SHA512:
6
- metadata.gz: 5463df4c0675a0af8405883ff4c1cebfab58e47d8b649208bde9360f88dd8c1620f10d5b7959acd37eb1fc17b789002fc512201fe23ecf488abee522d2e63655
7
- data.tar.gz: 63e2fab1f26d3538db51c6619d06c687675981e1543fa0c12b76ee31d080579ff6e493f86b57ac5fee528df110c51f49ea2ce56297823addd349d52a115251e2
6
+ metadata.gz: c9dd54b554659eaa2e78a54fb2cc98a956a9e6d7d8d5594dd250cdab1ccc66b966dd3ca5fb8ed7c2f9d1f1174cfdfa59b334b0556b4810830af1687634f6f752
7
+ data.tar.gz: 392f7e4c848e3463a6045baedb9a3f1921e74c6172972421696696243cb15e9059fe40507ea6699b49e2d93deb10a33eb2342772f139def65bd2c0de33877e09
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cfoundry_helper (0.2.3)
4
+ cfoundry_helper (0.3.0)
5
5
  activesupport
6
6
  cfoundry
7
7
 
@@ -21,7 +21,7 @@ GEM
21
21
  builder (3.1.4)
22
22
  cf-uaa-lib (2.0.0)
23
23
  multi_json
24
- cfoundry (4.5.1)
24
+ cfoundry (4.5.3)
25
25
  activemodel (>= 3.2.13, < 5.0.0)
26
26
  cf-uaa-lib (~> 2.0.0)
27
27
  multi_json (~> 1.7)
data/README.textile CHANGED
@@ -3,6 +3,15 @@ h1. CFoundry Helper
3
3
  This collection of scripts provides helper methods to the cfoundry gem's
4
4
  API. It implements common use cases when administrating a Cloud Foundry installation.
5
5
 
6
+ h2. Configuration
7
+
8
+ You can configure multiple targets within the services.yml configuration file. Please refer to the services.yml.example file for a detailed example.
9
+
10
+ h2. Usage
11
+
12
+ Since cfoundry_helper now supports multiple CF targets you have to set your desired target by using the
13
+ CFoundryHelper::Helpers::ClientHelper.current_target_url= method for selecting a target from your service configuration file.
14
+
6
15
  h2. Organization management
7
16
 
8
17
  The CFoundryHelper::Helpers::OrganizationHelper modules' methods provide helper methods for the following use cases:
@@ -31,7 +40,7 @@ The CFoundryHelper::Helpers::OrganizationHelper modules' methods provide helper
31
40
 
32
41
  h2. Client Helper
33
42
 
34
- The CFoundryHelper::Helpers::ClientHelper is a factory for uaa and cloud controller clients.
43
+ The CFoundryHelper::Helpers::ClientHelper is a factory for uaa and cloud controller clients. The current_target_url has to point to your desired endpoint as defined in the config yaml file.
35
44
 
36
45
 
37
46
  h2. Scripts
@@ -49,7 +58,7 @@ h2. Important environment variables
49
58
 
50
59
  h2. Console Usage
51
60
 
52
- Use the following command to start the console with the associated target:
61
+ Use the following command to start the console:
53
62
  RAILS_ENV=<target_env> CFOUNDRY_HELPER_CONFIG=<services config file> rake c
54
63
 
55
64
  e.g.: RAILS_ENV=production CFOUNDRY_HELPER_CONFIG=config/services.yml rake c
@@ -1,22 +1,25 @@
1
1
  production: &defaults
2
- uaa:
3
- site: "http://uaa.any9app.com"
4
- client_id: ""
5
- client_secret: ""
6
- cloud_controller:
7
- site: "http://api.any9app.com"
8
- username: ""
9
- password: ""
2
+ "http://api.any9app.com":
3
+ uaa:
4
+ site: "http://uaa.any9app.com"
5
+ client_id: "user_registrator"
6
+ client_secret: "user_registrator_password"
7
+ cloud_controller:
8
+ site: "http://api.any9app.com"
9
+ username: "admin"
10
+ password: "admin_password"
11
+ "http://api.other_target.com":
12
+ uaa:
13
+ site: "http://uaa.other_target.com"
14
+ client_id: "user_registrator"
15
+ client_secret: "user_registrator_password"
16
+ cloud_controller:
17
+ site: "http://api.other_target.com"
18
+ username: "admin"
19
+ password: "admin_password"
10
20
 
11
21
  development:
12
22
  <<: *defaults
13
23
 
14
24
  test:
15
- uaa:
16
- site: ""
17
- client_id: ""
18
- client_secret: ""
19
- cloud_controller:
20
- site: ""
21
- user: ""
22
- password: ""
25
+ <<: *defaults
@@ -0,0 +1,4 @@
1
+ module CFoundryHelper::Errors
2
+ class ConfigurationError < StandardError
3
+ end
4
+ end
@@ -5,7 +5,15 @@ module CFoundryHelper::Helpers
5
5
  @@scim_client = nil
6
6
  @@cloud_controller_client = nil
7
7
  @@auth_token = nil
8
+ @@current_target_url = nil
8
9
 
10
+ def self.current_target_url=(url)
11
+ @@current_target_url = url
12
+ end
13
+
14
+ def self.current_target_url
15
+ return @@current_target_url
16
+ end
9
17
 
10
18
  def self.get_cc_target_url
11
19
  return self.cloud_controller_client.target
@@ -25,37 +33,42 @@ module CFoundryHelper::Helpers
25
33
  # see http://www.simplecloud.info/
26
34
  def self.scim_client
27
35
  # just return the already initialized client if present
36
+ raise CFoundryHelper::Errors::ConfigurationError, "The ClientHelper's current target url is not defined in the configuration yaml file!" if CFoundryHelper.config[@@current_target_url].nil?
37
+
28
38
  return @@scim_client unless @@scim_client.nil?
29
39
 
30
40
  token_issuer = CF::UAA::TokenIssuer.new(
31
- CFoundryHelper.config['uaa']['site'],
32
- CFoundryHelper.config['uaa']['client_id'],
33
- CFoundryHelper.config['uaa']['client_secret'])
41
+ CFoundryHelper.config[@@current_target_url]['uaa']['site'],
42
+ CFoundryHelper.config[@@current_target_url]['uaa']['client_id'],
43
+ CFoundryHelper.config[@@current_target_url]['uaa']['client_secret'])
34
44
 
35
45
  token_info = token_issuer.client_credentials_grant
36
46
  access_token = token_info.info["access_token"]
37
- @@scim_client = CF::UAA::Scim.new(CFoundryHelper.config['uaa']['site'], "bEareR #{access_token}")
47
+ @@scim_client = CF::UAA::Scim.new(CFoundryHelper.config[@@current_target_url]['uaa']['site'], "bEareR #{access_token}")
38
48
  end
39
49
 
40
50
  ##
41
51
  # Use this client to connect to the cloudcontroller
42
52
  # and register a new user.
43
53
  def self.cloud_controller_client
54
+ # just return the already initialized client if present
55
+ raise CFoundryHelper::Errors::ConfigurationError, "The ClientHelper's current target url is not defined in the configuration yaml file!" if CFoundryHelper.config[@@current_target_url].nil?
56
+
57
+
44
58
  # just return the already initialized client if it was explicit setted.
45
59
  # Don't cache the client in this method because long running apps will
46
60
  # have some trouble with expired auth tokens.
47
61
  # TODO: Refresh the token with the uaa refresh method.
48
62
  return @@cloud_controller_client if @@cloud_controller_client
49
63
 
50
- token_issuer = CF::UAA::TokenIssuer.new(CFoundryHelper.config['uaa']['site'], "cf")
51
- token_info = token_issuer.implicit_grant_with_creds(CFoundryHelper.config['cloud_controller'])
64
+ token_issuer = CF::UAA::TokenIssuer.new(CFoundryHelper.config[@@current_target_url]['uaa']['site'], "cf")
65
+ token_info = token_issuer.implicit_grant_with_creds(CFoundryHelper.config[@@current_target_url]['cloud_controller'])
52
66
  access_token = token_info.info["access_token"]
53
67
  token = CFoundry::AuthToken.from_hash({:token => "bearer #{access_token}"})
54
68
  @@auth_token = token
55
- CFoundry::V2::Client.new(CFoundryHelper.config['cloud_controller']['site'], token)
69
+ CFoundry::V2::Client.new(CFoundryHelper.config[@@current_target_url]['cloud_controller']['site'], token)
56
70
  end
57
71
 
58
-
59
72
  def self.set_scim_client(client)
60
73
  @@scim_client = client
61
74
  end
@@ -63,8 +76,5 @@ module CFoundryHelper::Helpers
63
76
  def self.set_cc_client(client)
64
77
  @@cloud_controller_client = client
65
78
  end
66
-
67
-
68
-
69
79
  end
70
80
  end
@@ -1,3 +1,3 @@
1
1
  module CFoundryHelper
2
- VERSION = "0.2.3"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -7,6 +7,7 @@ Bundler.require
7
7
  module CFoundryHelper
8
8
  autoload :Helpers, File.expand_path('../cfoundry_helper/helpers', __FILE__)
9
9
  autoload :Models, File.expand_path('../cfoundry_helper/models', __FILE__)
10
+ autoload :Errors, File.expand_path('../cfoundry_helper/errors', __FILE__)
10
11
 
11
12
  @@config = nil
12
13
  @@config_file_path = nil
@@ -23,7 +24,7 @@ module CFoundryHelper
23
24
  self.read_config_file
24
25
  end
25
26
 
26
- def self.set_config_file_path(path)
27
+ def self.config_file_path=(path)
27
28
  @@config_file_path = path
28
29
  end
29
30
 
@@ -31,6 +32,17 @@ module CFoundryHelper
31
32
  return @@config_file_path
32
33
  end
33
34
 
35
+ # Returns an array of target available target urls defined in the configuration file as strings.
36
+ # @returns [Array]
37
+ def self.available_targets
38
+ self.config.keys
39
+ end
40
+
41
+ # Returns the config hash for the given target url as defined in the configuration file.
42
+ # Returns nil if the given target url is not defined within the config file.
43
+ def self.config_for_target(url)
44
+ self.config[url]
45
+ end
34
46
 
35
47
  protected
36
48
 
@@ -47,7 +59,7 @@ module CFoundryHelper
47
59
  end
48
60
 
49
61
  def self.check_config_file_path
50
- raise "No configuration file path has been set! Please call ClientHelper.set_config_file_path first or set a valid CFOUNDRY_HELPER_CONFIG env variable!" if @@config_file_path.nil?
62
+ raise "No configuration file path has been set! Please call ClientHelper.config_file_path= first or set a valid CFOUNDRY_HELPER_CONFIG env variable!" if @@config_file_path.nil?
51
63
  raise "There's no configuration file on #{@@config_file_path}!" if !File.exists? @@config_file_path
52
64
  end
53
65
 
@@ -55,7 +67,7 @@ module CFoundryHelper
55
67
  def self.set_config_file_path_from_env
56
68
  config_file_path = ENV["CFOUNDRY_HELPER_CONFIG"]
57
69
  unless config_file_path.nil?
58
- self.set_config_file_path config_file_path
70
+ self.config_file_path = config_file_path
59
71
  end
60
72
  end
61
73
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cfoundry_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Weber
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-17 00:00:00.000000000 Z
11
+ date: 2013-10-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -203,6 +203,7 @@ files:
203
203
  - cfoundry_helper.gemspec
204
204
  - config/services.yml.example
205
205
  - lib/cfoundry_helper.rb
206
+ - lib/cfoundry_helper/errors.rb
206
207
  - lib/cfoundry_helper/helpers.rb
207
208
  - lib/cfoundry_helper/helpers/client_helper.rb
208
209
  - lib/cfoundry_helper/helpers/organization_helper.rb