Module: CFoundryHelper::Helpers::ClientHelper
- Defined in:
- lib/cfoundry_helper/helpers/client_helper.rb
Constant Summary collapse
- MAX_CLIENT_TIMEOUT =
5 minutes
5*60
- @@scim_client =
nil
- @@cloud_controller_client =
nil
- @@auth_token =
nil
- @@current_target_url =
nil
- @@scim_client_init_time =
nil
- @@cc_client_init_time =
nil
Class Method Summary collapse
-
.cloud_controller_client ⇒ Object
Use this client to connect to the cloudcontroller and register a new user.
- .current_target_url ⇒ Object
- .current_target_url=(url) ⇒ Object
- .get_auth_token ⇒ Object
- .get_cc_target_url ⇒ Object
-
.scim_client ⇒ Object
Use this client to connect to the uaa-service and check wether a user alredy exists.
- .set_cc_client(client) ⇒ Object
- .set_scim_client(client) ⇒ Object
Class Method Details
.cloud_controller_client ⇒ Object
Use this client to connect to the cloudcontroller and register a new user.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 66 def self.cloud_controller_client # is the client outdated? unless @@cc_client_init_time.nil? time_diff = Time.now - @@cc_client_init_time if time_diff > MAX_CLIENT_TIMEOUT @@cloud_controller_client = nil @@auth_token = nil end end # just return the already initialized client if present raise CFoundryHelper::Errors::ConfigurationError, "The ClientHelper's current target url is not defined in the configuration!" if CFoundryHelper.config[@@current_target_url].nil? # just return the already initialized client if the auth token is not expired. return @@cloud_controller_client unless is_auth_token_expired? token_issuer = ::CF::UAA::TokenIssuer.new(CFoundryHelper.config[@@current_target_url]['uaa']['site'], "cf") token_info = token_issuer.implicit_grant_with_creds(CFoundryHelper.config[@@current_target_url]['cloud_controller']) access_token = token_info.info["access_token"] token = CFoundry::AuthToken.from_hash({:token => "bearer #{access_token}"}) @@auth_token = token cc_client = CFoundry::V2::Client.new(CFoundryHelper.config[@@current_target_url]['cloud_controller']['site'], token) set_cc_client(cc_client) end |
.current_target_url ⇒ Object
20 21 22 |
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 20 def self.current_target_url return @@current_target_url end |
.current_target_url=(url) ⇒ Object
16 17 18 |
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 16 def self.current_target_url=(url) @@current_target_url = url end |
.get_auth_token ⇒ Object
28 29 30 31 |
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 28 def self.get_auth_token self.cloud_controller_client return @@auth_token end |
.get_cc_target_url ⇒ Object
24 25 26 |
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 24 def self.get_cc_target_url return self.cloud_controller_client.target end |
.scim_client ⇒ Object
Use this client to connect to the uaa-service and check wether a user alredy exists.
scim is a “System for Cross-domain Identity Management” and it is uesd by the uaa service. see www.simplecloud.info/
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 40 def self.scim_client # is the client outdated? unless @@scim_client_init_time.nil? time_diff = Time.now - @@scim_client_init_time @@scim_client = nil if time_diff > MAX_CLIENT_TIMEOUT end 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? # just return the already initialized client if present return @@scim_client unless @@scim_client.nil? token_issuer = ::CF::UAA::TokenIssuer.new( CFoundryHelper.config[@@current_target_url]['uaa']['site'], CFoundryHelper.config[@@current_target_url]['uaa']['client_id'], CFoundryHelper.config[@@current_target_url]['uaa']['client_secret']) token_info = token_issuer.client_credentials_grant access_token = token_info.info["access_token"] scim_client = ::CF::UAA::Scim.new(CFoundryHelper.config[@@current_target_url]['uaa']['site'], "bEareR #{access_token}") set_scim_client(scim_client) end |
.set_cc_client(client) ⇒ Object
96 97 98 99 |
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 96 def self.set_cc_client(client) @@cc_client_init_time = Time.now @@cloud_controller_client = client end |
.set_scim_client(client) ⇒ Object
91 92 93 94 |
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 91 def self.set_scim_client(client) @@scim_client_init_time = Time.now @@scim_client = client end |