Class: RedhatAccess::Api::MachineTelemetryApiController

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

Instance Method Summary collapse

Methods inherited from TelemetryApiController

#action_permission, #check_telemetry_enabled, #connection_status, #get_creds, #get_current_organization, #get_machines, #index, #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_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, #is_org_selected?, #is_susbcribed_to_redhat?, #telemetry_enabled?, #telemetry_enabled_for_uuid?, #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

#api_connection_testObject



37
38
39
40
41
42
# File 'app/controllers/redhat_access/api/machine_telemetry_api_controller.rb', line 37

def api_connection_test
  client = get_api_client
  res = client.call_tapi('GET', '/', nil, nil, nil)
  Rails.logger.debug(res[:data])
  render status: res[:code], json: {}
end

#ensure_telemetry_enabledObject



25
26
27
# File 'app/controllers/redhat_access/api/machine_telemetry_api_controller.rb', line 25

def ensure_telemetry_enabled
  render_telemetry_off unless telemetry_enabled_for_uuid?(User.current.)
end

#get_auth_opts(creds) ⇒ Object



29
30
31
32
33
34
35
# File 'app/controllers/redhat_access/api/machine_telemetry_api_controller.rb', line 29

def get_auth_opts(creds)
  if valid_machine_user?
    get_ssl_options_for_uuid(User.current., nil)
  else
    raise(RedhatAccess::Telemetry::LookUps::RecordNotFound,'Invalid User')
  end
end

#get_branch_infoObject



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/controllers/redhat_access/api/machine_telemetry_api_controller.rb', line 63

def get_branch_info
  uuid = User.current.
  begin
    org = get_organization(uuid)
    major,minor,build = get_plugin_parent_version.scan(/\d+/)
    client_id = {:remote_leaf => uuid ,
                 :remote_branch => get_branch_id_for_uuid(uuid),
                 :display_name => org.name,
                 :hostname => request.host,
                 :product => {:type => get_plugin_parent_name,
                              :major_version => major,
                              :minor_version => minor
                              }
                 }
    render :json => client_id.to_json
  rescue RedhatAccess::Telemetry::LookUps::RecordNotFound => e
    http_error_response(e.message, 400)
  end
end

#proxy_uploadObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/redhat_access/api/machine_telemetry_api_controller.rb', line 44

def proxy_upload
  original_method  = request.method
  original_params  = add_branch_to_params(request.query_parameters)
  original_payload = request.request_parameters[controller_name]
  if not params[:id] and params[:test]
    resource = "uploads/"
    original_payload = {:test => params[:test]}
  else
    resource = "uploads/#{params[:id]}"
  end
  if params[:file]
    original_payload = get_file_data(params)
  end
  client = get_api_client
  Rails.logger.debug("Proxy upload original_payload : #{original_payload}")
  res = client.call_tapi(original_method, URI.escape(resource), original_params, original_payload, nil, use_subsets)
  render status: res[:code] , json: res[:data]
end

#telemetry_authObject



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

def telemetry_auth
  authenticate_client
  unless valid_machine_user?
    deny_access
  end
end