Class: RedhatAccess::Api::StrataProxyController

Inherits:
TelemetryApiController show all
Defined in:
app/controllers/redhat_access/api/strata_proxy_controller.rb

Instance Method Summary collapse

Methods inherited from TelemetryApiController

#check_telemetry_enabled, #connection_status, #get_creds, #get_current_organization, #get_machines, #proxy, #render_telemetry_off

Methods included from Telemetry::LookUps

#can_mask_rules, #can_unregister_system, #current_organization, #disconnected_org?, #get_basic_auth_options, #get_branch_id_for_org, #get_branch_id_for_uuid, #get_content_host, #get_content_hosts, #get_default_ssl_ca_file, #get_http_options, #get_http_user_agent, #get_leaf_id, #get_mutual_tls_auth_options, #get_organization, #get_plugin_parent_name, #get_plugin_parent_version, #get_portal_http_proxy, #get_rha_plugin_name, #get_rha_plugin_rpm_name, #get_rha_plugin_version, #get_ssl_options_for_org, #get_ssl_options_for_uuid, #get_telemetry_config, #insights_api_host, #is_org_selected?, #is_susbcribed_to_redhat?, #telemetry_enabled?, #telemetry_enabled_for_uuid?, #upstream_owner, #use_basic_auth?, #user_login_to_hash

Methods included from RedhatAccess::Authentication::ClientAuthentication

#authenticate_client, #cert_from_request, #cert_present?, #deny_access, #set_client_user

Methods inherited from ApiController

#api_request?, #http_error_response

Instance Method Details

#action_permissionObject



10
11
12
13
14
15
16
17
# File 'app/controllers/redhat_access/api/strata_proxy_controller.rb', line 10

def action_permission
  case params[:action]
  when 'call'
    :call
  else
    super
  end
end

#callObject

The method that “proxies” tapi requests over to Strata



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/controllers/redhat_access/api/strata_proxy_controller.rb', line 30

def call
  original_method  = request.method
  original_params = request.query_parameters
  original_payload = request.request_parameters[controller_name]
  if request.post? && request.raw_post
       original_payload = request.raw_post.clone
  end

  if request.put?
     original_payload = request.body.read
  end
  resource = params[:path] == nil ?  "/" : params[:path]
  if params[:file]
    original_payload = get_file_data(params)
  end
  client = get_api_client
  res = client.call_strata(original_method, URI.escape(resource), original_params, original_payload, nil)
  #401 erros means our proxy is not configured right.
  #Change it to 502 to distinguish with local applications 401 errors
  resp_data = res[:data]
  if res[:code] == 401
    res[:code] = 502
    resp_data = {
      :message => 'Authentication to the Strata Service failed.'
    }
  end
  render status: res[:code] , json: resp_data #.gsub('https://api.access.redhat.com','https://192.168.121.13/redhat_access/strata/')
end

#get_api_clientObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/redhat_access/api/strata_proxy_controller.rb', line 59

def get_api_client
  accept_hdr = request.headers['Accept']
  content_hdr = request.headers['Content-Type']
  headers = { 'accept' => accept_hdr}
  unless content_hdr.nil?
     headers['content-type'] = content_hdr
  end
  headers['Authorization'] = env['HTTP_AUTHORIZATION'] if env['HTTP_AUTHORIZATION']
  Rails.logger.debug("User agent for telemetry is #{get_http_user_agent}")
  strata_host = 'https://api.' + REDHAT_ACCESS_CONFIG[:strata_host]
  return RedhatAccess::Telemetry::PortalClient.new(strata_host,
                                                   strata_host,
                                                   nil,
                                                   self,
                                                   {:logger => Rails.logger,
                                                    :http_proxy => get_portal_http_proxy,
                                                    :user_agent => get_http_user_agent,
                                                    :headers => headers
                                                   })
end

#get_auth_opts(creds) ⇒ Object



19
20
21
22
# File 'app/controllers/redhat_access/api/strata_proxy_controller.rb', line 19

def get_auth_opts(creds)
  #We only support pass through basic auth @see get_api_client method
  return {}
end

#indexObject



24
25
26
# File 'app/controllers/redhat_access/api/strata_proxy_controller.rb', line 24

def index
  render :text => "Strata Telemetry API"
end