Class: Conversant::V3::Services::Portal

Inherits:
Base
  • Object
show all
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

Returns:

  • (String)

Since:

  • 1.0.0

'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

#customer_id, #type

Instance Method Summary collapse

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

Parameters:

  • gte (String, nil) (defaults to: nil)
  • lte (String, nil) (defaults to: nil)

Returns:

  • (Array[Hash[String, untyped]])


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.message}"
  []
end

#dashboardDashboard

Get dashboard service instance

Returns:

  • (Dashboard)

    dashboard service for customer metadata and reporting

Since:

  • 1.0.8



104
105
106
# File 'lib/conversant/v3/services/portal.rb', line 104

def dashboard
  @dashboard ||= Dashboard.new(self)
end

#fetch_new_sessionString?

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.

Returns:

  • (String, nil)

    The SESSION cookie value, or nil if authentication fails

Since:

  • 1.0.0



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
  session_cookie = sessions[:session]
  redis.set(session_cache_key, session_cookie, ex: configuration.cache_ttl)
  logger.debug "#{identifier}.METHOD:authorize.SESSION_OBTAINED"
  session_cookie
rescue RestClient::Unauthorized, RestClient::Forbidden => e
  logger.error "#{identifier}.METHOD:authorize.AUTH_ERROR:#{e.message}"
  nil
rescue StandardError => e
  logger.error "#{identifier}.METHOD:authorize.ERROR:#{e.message}"
  nil
end

#requires_session?Boolean

Indicates whether Portal service requires a session cookie

Returns:

  • (Boolean)

    true (Portal requires SESSION cookie)

Since:

  • 1.0.0



207
208
209
# File 'lib/conversant/v3/services/portal.rb', line 207

def requires_session?
  true
end

#service_endpointString

Returns the Portal service endpoint URL

Returns:

  • (String)

    The portal endpoint URL

Since:

  • 1.0.0



193
194
195
# File 'lib/conversant/v3/services/portal.rb', line 193

def service_endpoint
  portal_endpoint
end