Module: CFoundryHelper::Helpers::ClientHelper

Defined in:
lib/cfoundry_helper/helpers/client_helper.rb

Constant Summary collapse

@@scim_client =
nil
@@cloud_controller_client =
nil
@@auth_token =
nil
@@current_target_url =
nil

Class Method Summary collapse

Class Method Details

.cloud_controller_clientObject

Use this client to connect to the cloudcontroller and register a new user.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 54

def self.cloud_controller_client
  # 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_urlObject



15
16
17
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 15

def self.current_target_url
  return @@current_target_url
end

.current_target_url=(url) ⇒ Object



11
12
13
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 11

def self.current_target_url=(url)
  @@current_target_url = url
end

.get_auth_tokenObject



23
24
25
26
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 23

def self.get_auth_token
  self.cloud_controller_client
  return @@auth_token
end

.get_cc_target_urlObject



19
20
21
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 19

def self.get_cc_target_url
  return self.cloud_controller_client.target
end

.scim_clientObject

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/



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 35

def self.scim_client
  # just return the already initialized client if present
  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?

  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}")
end

.set_cc_client(client) ⇒ Object



74
75
76
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 74

def self.set_cc_client(client)
  @@cloud_controller_client = client
end

.set_scim_client(client) ⇒ Object



70
71
72
# File 'lib/cfoundry_helper/helpers/client_helper.rb', line 70

def self.set_scim_client(client)
  @@scim_client = client
end