Class: Conversant::V3::Services::Portal
- Includes:
- Authorization
- Defined in:
- lib/conversant/v3/services/portal.rb,
lib/conversant/v3/services/portal/dashboard.rb,
sig/conversant/v3/services/portal.rbs
Overview
Portal service for appliance management
Defined Under Namespace
Classes: Dashboard
Constant Summary collapse
- MASTER_APPLIANCE_REDIS_KEY =
Redis key prefix for caching appliance data
'CONVERSANT.V3.PORTAL.APPLIANCE.ITEMS'
Constants included from HttpClient
HttpClient::PORTAL_SESSION_REDIS_KEY, HttpClient::SSO_GW_SESSION2_REDIS_KEY
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#appliances(gte = nil, lte = nil) ⇒ Array[Hash[String, untyped]]
Get appliances within date range.
-
#dashboard ⇒ Dashboard
Get dashboard service instance.
-
#fetch_new_session ⇒ String?
Fetches a new SESSION cookie for Portal API access.
-
#requires_session? ⇒ Boolean
Indicates whether Portal service requires a session cookie.
-
#service_endpoint ⇒ String
Returns the Portal service endpoint URL.
Methods included from Authorization
#authorize, #authorized_headers, #base_headers, #build_cookie_hash, #build_headers_with_cookies, #cached_session, #fetch_session_cookie, #fetch_sso_session, #format_cookies, #log_missing_session, #session_cache_key, #sso_cache_key
Methods inherited from Base
#configuration, #identifier, #initialize, #logger, #portal_endpoint, #redis, #sso_endpoint, #validate_configuration!
Methods included from HttpClient
#add_cookies_to_headers, #authenticate, #configuration, #cookie_jar, #cookie_jar=, #debug_log, #extract_form_action, #http_get, #http_post, #login_url, #parse_cookie_to_jar, #redis, #request, #sso_login, #update_cookie_jar
Constructor Details
This class inherits a constructor from Conversant::V3::Base
Instance Method Details
#appliances(gte = nil, lte = nil) ⇒ Array[Hash[String, untyped]]
Get appliances within date range
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/conversant/v3/services/portal.rb', line 60 def appliances(gte = nil, lte = nil) today = Date.today.to_datetime gte ||= today.beginning_of_month.strftime('%Y-%m-%dT00:00:00Z') lte ||= today.end_of_month.strftime('%Y-%m-%dT23:59:59Z') key = "#{MASTER_APPLIANCE_REDIS_KEY}.#{gte.to_datetime&.strftime('%Y%m')}" items = redis.get(key) if items.nil? logger.debug "#{identifier}.METHOD:appliances.FETCHING_DATA" payload = { startTime: gte, endTime: lte } response = JSON.parse(call('POST', '/load_appliance_data', payload)) items = response&.[]('applianceList')&.map do |item| { ip: item['ip'], hostname: item['hostname'], deleted: item['deleted'], pop: item['pop'], volume: item['volume'], federation: item['federationVolume'] } end.to_json redis.set(key, items, ex: 600) end JSON.parse(items) rescue StandardError => e logger.error "#{identifier}.METHOD:appliances.ERROR:#{e.}" [] end |
#dashboard ⇒ Dashboard
Get dashboard service instance
104 105 106 |
# File 'lib/conversant/v3/services/portal.rb', line 104 def dashboard @dashboard ||= Dashboard.new(self) end |
#fetch_new_session ⇒ String?
Fetches a new SESSION cookie for Portal API access
Authenticates with root portal sessions (SESSION + SSO_GW_SESSION2) and uses them directly for Portal API calls. Makes a test call to verify the sessions are valid.
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/conversant/v3/services/portal.rb', line 153 def fetch_new_session sessions = authenticate return nil unless sessions && sessions[:session] && sessions[:sso_gw_session2] logger.debug "#{identifier}.METHOD:authorize.USING_ROOT_SESSIONS" # Make a test call to verify sessions are valid RestClient.get( "#{portal_endpoint}/?cId=#{customer_id}", { authority: URI.parse(portal_endpoint).hostname, referer: portal_endpoint, user_agent: configuration.default_ua, cookies: { 'SESSION': sessions[:session], 'SSO_GW_SESSION2': sessions[:sso_gw_session2] }, timeout: 30, open_timeout: 30 } ) # Cache and return the root SESSION cookie = sessions[:session] redis.set(session_cache_key, , ex: configuration.cache_ttl) logger.debug "#{identifier}.METHOD:authorize.SESSION_OBTAINED" rescue RestClient::Unauthorized, RestClient::Forbidden => e logger.error "#{identifier}.METHOD:authorize.AUTH_ERROR:#{e.}" nil rescue StandardError => e logger.error "#{identifier}.METHOD:authorize.ERROR:#{e.}" nil end |
#requires_session? ⇒ Boolean
Indicates whether Portal service requires a session cookie
207 208 209 |
# File 'lib/conversant/v3/services/portal.rb', line 207 def requires_session? true end |
#service_endpoint ⇒ String
Returns the Portal service endpoint URL
193 194 195 |
# File 'lib/conversant/v3/services/portal.rb', line 193 def service_endpoint portal_endpoint end |