cfoundry_helper 0.3.0 → 0.3.1

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: adb8f6ca8a613c1c8b2cf30c86414353bd05a5cb
4
- data.tar.gz: 0dc73d74b5abb77ca19a35de693fa90d5b53ad77
3
+ metadata.gz: 537df23f74bd2092dbf4e29f0c81002251763424
4
+ data.tar.gz: 0fc6be2168d5bd780a557dcfaae57d3534285e62
5
5
  SHA512:
6
- metadata.gz: c9dd54b554659eaa2e78a54fb2cc98a956a9e6d7d8d5594dd250cdab1ccc66b966dd3ca5fb8ed7c2f9d1f1174cfdfa59b334b0556b4810830af1687634f6f752
7
- data.tar.gz: 392f7e4c848e3463a6045baedb9a3f1921e74c6172972421696696243cb15e9059fe40507ea6699b49e2d93deb10a33eb2342772f139def65bd2c0de33877e09
6
+ metadata.gz: f8ca889bf78357bfc20032681b658f15c92f76ae961bbe86e041ffa46d0d61e9f8999f908258c3451b0d40ff07cb8fc53da5e24eccb6b2a831f146d49433acd9
7
+ data.tar.gz: eb658526e019a09b72161ea95b993170ff5061fc2e31c2e78a76076d473d520a8498136e36076f08229c5c4f81dc4792dc402389ce810674ee78e1f85163970d
data/CHANGELOG.textile CHANGED
@@ -1,10 +1,18 @@
1
- h1. v0.1.0
2
- * OrganizationHelper implementation
3
- * ClientHelper implementation
4
- * UserHelper implementation
1
+ h2. v0.3.1
2
+ * removes env
3
+ * removes necessary configuration file
4
+ * adds the possibility to load configuration either from a file or from a hash
5
5
 
6
- h2. v0.2.0
7
- * add users to org script
6
+ h2. v0.3.0
7
+ * multiple target support
8
8
 
9
9
  h2. v0.2.1
10
10
  * Bugfix: Don't cache the cloud controller client since the access token expires in long running apps.
11
+
12
+ h2. v0.2.0
13
+ * add users to org script
14
+
15
+ h2. v0.1.0
16
+ * OrganizationHelper implementation
17
+ * ClientHelper implementation
18
+ * UserHelper implementation
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cfoundry_helper (0.3.0)
4
+ cfoundry_helper (0.3.1)
5
5
  activesupport
6
6
  cfoundry
7
7
 
data/README.textile CHANGED
@@ -5,12 +5,22 @@ API. It implements common use cases when administrating a Cloud Foundry installa
5
5
 
6
6
  h2. Configuration
7
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.
8
+ a) You can configure multiple targets within a configuration file. Please execute the following code to load the file's contents into the configuration:
9
+ CFoundryHelper.load_config_from_file file_location
9
10
 
10
- h2. Usage
11
+ b) You can also configure the targets by passing in a configuration hash:
12
+ CfoundryHelper.load_config_from_hash config_hash
13
+
14
+ !!! It is important to load a configuration using one of the methods above before executing any helper functions.
15
+
11
16
 
17
+ h2. Target Selection
12
18
  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.
19
+ CFoundryHelper::Helpers::ClientHelper.current_target_url= method for selecting a target from your service configuration file.
20
+ You can list all configured targets using the CFoundryHelper.available_targets method.
21
+
22
+ !!! It is important to select a target before executing any helper functions, e.g:
23
+ CFoundryHelper::Helpers::ClientHelper.current_target_url = CFoundryHelper.available_targets.first
14
24
 
15
25
  h2. Organization management
16
26
 
@@ -40,25 +50,18 @@ The CFoundryHelper::Helpers::OrganizationHelper modules' methods provide helper
40
50
 
41
51
  h2. Client Helper
42
52
 
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.
53
+ The CFoundryHelper::Helpers::ClientHelper is a factory for uaa and cloud controller clients. The current_target_url has to point to your desired endpoint. (see Target Selection)
44
54
 
45
55
 
46
56
  h2. Scripts
47
57
 
48
58
  * bin/add_users_to_org : adds users to an organization
49
- ** usage : RAILS_ENV=<test / production / development> bundle exec bin/add_users_to_org <org name> <users_email_list_file_location> <services_config_file_location>
59
+ ** usage : bundle exec bin/add_users_to_org <org name> <users_email_list_file_location> <services_config_file_location>
50
60
  * bin/create_space_for_org : creates a space to an organization and assigns all organization members to it
51
- ** usage : RAILS_ENV=<test / production / development> bundle exec bin/create_space_for_org <org name> <space name> <services_config_file_location>
52
-
53
- h2. Important environment variables
61
+ ** usage : bundle exec bin/create_space_for_org <org name> <space name> <services_config_file_location>
54
62
 
55
- * RAILS_ENV : The helper is reading the target environment on which to execute commands using the RAILS_ENV environment variable. (e.g. production, test)
56
-
57
- * CFOUNDRY_HELPER_CONFIG This variable has to point to your services.yml file.
58
63
 
59
64
  h2. Console Usage
60
65
 
61
66
  Use the following command to start the console:
62
- RAILS_ENV=<target_env> CFOUNDRY_HELPER_CONFIG=<services config file> rake c
63
-
64
- e.g.: RAILS_ENV=production CFOUNDRY_HELPER_CONFIG=config/services.yml rake c
67
+ bundle exec rake c
@@ -1,25 +1,18 @@
1
- production: &defaults
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"
20
-
21
- development:
22
- <<: *defaults
23
-
24
- test:
25
- <<: *defaults
1
+ "http://api.any9app.com":
2
+ uaa:
3
+ site: "http://uaa.any9app.com"
4
+ client_id: "user_registrator"
5
+ client_secret: "user_registrator_password"
6
+ cloud_controller:
7
+ site: "http://api.any9app.com"
8
+ username: "admin"
9
+ password: "admin_password"
10
+ "http://api.other_target.com":
11
+ uaa:
12
+ site: "http://uaa.other_target.com"
13
+ client_id: "user_registrator"
14
+ client_secret: "user_registrator_password"
15
+ cloud_controller:
16
+ site: "http://api.other_target.com"
17
+ username: "admin"
18
+ password: "admin_password"
@@ -1,6 +1,7 @@
1
1
  require 'bundler'
2
2
  require 'cfoundry'
3
3
  require 'active_support/core_ext/object/try'
4
+ require 'active_support/hash_with_indifferent_access'
4
5
 
5
6
  Bundler.require
6
7
 
@@ -10,26 +11,26 @@ module CFoundryHelper
10
11
  autoload :Errors, File.expand_path('../cfoundry_helper/errors', __FILE__)
11
12
 
12
13
  @@config = nil
13
- @@config_file_path = nil
14
-
15
- def self.env
16
- unless ENV['RAILS_ENV']
17
- return :development
18
- else
19
- ENV['RAILS_ENV'].to_sym
20
- end
21
- end
22
14
 
23
- def self.config
24
- self.read_config_file
15
+ # Loads the configuration from the specified hash.
16
+ def self.load_config_from_hash(hash)
17
+ config = hash
18
+ check_config! config
19
+ @@config = config
20
+ @@config
25
21
  end
26
22
 
27
- def self.config_file_path=(path)
28
- @@config_file_path = path
23
+ # Loads the configuration from the specified yaml file.
24
+ def self.load_config_from_file(file_location)
25
+ raise "There's no configuration file on #{file_location}!" unless File.exists? file_location
26
+ config = YAML.load_file(file_location)
27
+ check_config! config
28
+ @@config = config
29
+ @@config
29
30
  end
30
-
31
- def self.config_file_path
32
- return @@config_file_path
31
+
32
+ def self.config
33
+ @@config
33
34
  end
34
35
 
35
36
  # Returns an array of target available target urls defined in the configuration file as strings.
@@ -38,38 +39,29 @@ module CFoundryHelper
38
39
  self.config.keys
39
40
  end
40
41
 
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.
42
+ # Returns the config hash for the given target url as defined in the configuration.
43
+ # Returns nil if the given target url is not defined within the configuration.
43
44
  def self.config_for_target(url)
44
45
  self.config[url]
45
46
  end
46
47
 
47
- protected
48
-
49
- # reads the uaa and cc configuration from a config file
50
- def self.read_config_file
51
- # try to set the config file path from the env if not set already
52
- self.set_config_file_path_from_env if @@config_file_path.nil?
53
-
54
- if @@config.nil?
55
- self.check_config_file_path
56
- @@config = YAML.load_file(@@config_file_path)[CFoundryHelper.env.to_s]
57
- end
58
- @@config
59
- end
60
-
61
- def self.check_config_file_path
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?
63
- raise "There's no configuration file on #{@@config_file_path}!" if !File.exists? @@config_file_path
64
- end
65
-
66
- # sets the configuration file path from reading the CFOUNDRY_HELPER_CONFIG env variable
67
- def self.set_config_file_path_from_env
68
- config_file_path = ENV["CFOUNDRY_HELPER_CONFIG"]
69
- unless config_file_path.nil?
70
- self.config_file_path = config_file_path
48
+ private
49
+
50
+ def self.check_config!(config)
51
+ raise "No target hashes are defined within the configuration!" if config.count == 0
52
+
53
+ config.each do |target,hash|
54
+ # check uaa config
55
+ raise "No uaa section is specified within the target #{target} !" if hash["uaa"].nil?
56
+ raise "No uaa:site is specifed within the target #{target} !" if hash["uaa"]["site"].nil?
57
+ raise "No uaa:client_id is specifed within the target #{target} !" if hash["uaa"]["client_id"].nil?
58
+ raise "No uaa:client_secret is specifed within the target #{target} !" if hash["uaa"]["client_secret"].nil?
59
+
60
+ # check cc config
61
+ raise "No cloud_controller section is specified within the target #{target} !" if hash["cloud_controller"].nil?
62
+ raise "No cloud_controller:site is specifed within the target #{target} !" if hash["cloud_controller"]["site"].nil?
63
+ raise "No cloud_controller:username is specifed within the target #{target} !" if hash["cloud_controller"]["username"].nil?
64
+ raise "No cloud_controller:password is specifed within the target #{target} !" if hash["cloud_controller"]["password"].nil?
71
65
  end
72
66
  end
73
- end
74
-
75
- CFoundryHelper.config
67
+ end
@@ -52,7 +52,7 @@ module CFoundryHelper::Helpers
52
52
  # and register a new user.
53
53
  def self.cloud_controller_client
54
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?
55
+ raise CFoundryHelper::Errors::ConfigurationError, "The ClientHelper's current target url is not defined in the configuration!" if CFoundryHelper.config[@@current_target_url].nil?
56
56
 
57
57
 
58
58
  # just return the already initialized client if it was explicit setted.
@@ -1,3 +1,3 @@
1
1
  module CFoundryHelper
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  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.3.0
4
+ version: 0.3.1
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-24 00:00:00.000000000 Z
11
+ date: 2013-10-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler