Class: RedhatAccess::Api::TelemetryApiController
Instance Method Summary
collapse
#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
#authenticate_client, #cert_from_request, #cert_present?, #deny_access, #set_client_user
#api_request?, #http_error_response
Instance Method Details
#action_permission ⇒ Object
17
18
19
20
21
22
23
24
25
26
|
# File 'app/controllers/redhat_access/api/telemetry_api_controller.rb', line 17
def action_permission
case params[:action]
when 'proxy'
:proxy
when 'connection_status'
:connection_status
else
super
end
end
|
#check_telemetry_enabled ⇒ Object
28
29
30
|
# File 'app/controllers/redhat_access/api/telemetry_api_controller.rb', line 28
def check_telemetry_enabled
render_telemetry_off unless telemetry_enabled?(current_organization)
end
|
#connection_status ⇒ Object
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
|
# File 'app/controllers/redhat_access/api/telemetry_api_controller.rb', line 66
def connection_status
client = get_api_client
res = client.call_tapi('GET', 'me', nil, nil, nil)
Rails.logger.debug(res[:data])
case res[:code]
when 200
resp = JSON.parse(res[:data])
data = {
:connectionStatus => 'Connected',
:account => resp["account_number"],
:company => resp["company"],
:orgId => resp["ord_id"]
}
render status: res[:code] , json: data
when 401
data = {
:connectionStatus => 'Authentication Failure',
:account => 'Unknown',
:company => 'Unknown',
}
render status: 200 , json: data
else
data = {
:connectionStatus => 'Connection Failed',
:account => 'Unknown',
:company => 'Unknown',
}
render status: 200 , json: data
end
end
|
#get_auth_opts(creds) ⇒ Object
42
43
44
|
# File 'app/controllers/redhat_access/api/telemetry_api_controller.rb', line 42
def get_auth_opts(creds)
return get_ssl_options_for_org(current_organization ,nil)
end
|
#get_creds ⇒ Object
36
37
38
39
40
|
# File 'app/controllers/redhat_access/api/telemetry_api_controller.rb', line 36
def get_creds
end
|
#get_current_organization ⇒ Object
62
63
64
|
# File 'app/controllers/redhat_access/api/telemetry_api_controller.rb', line 62
def get_current_organization
current_organization
end
|
#get_machines ⇒ Object
# Returns an array of the machine IDs that this user has access to
52
53
54
55
56
57
58
59
|
# File 'app/controllers/redhat_access/api/telemetry_api_controller.rb', line 52
def get_machines
machines = get_content_hosts(current_organization)
if machines.empty?
machines = ['NULL_SET']
end
machines.sort
end
|
#index ⇒ Object
46
47
48
|
# File 'app/controllers/redhat_access/api/telemetry_api_controller.rb', line 46
def index
render :text => "Telemetry API"
end
|
#proxy ⇒ Object
The method that “proxies” tapi requests over to Strata
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
|
# File 'app/controllers/redhat_access/api/telemetry_api_controller.rb', line 98
def proxy
original_method = request.method
original_params = request.query_parameters
if request.user_agent and not request.user_agent.include?('redhat_access_cfme')
original_params = add_branch_to_params(request.query_parameters)
end
original_payload = request.request_parameters[controller_name]
if request.post? && request.raw_post
original_payload = request.raw_post.clone
elsif 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_tapi(original_method, URI.escape(resource), original_params, original_payload, nil, use_subsets)
resp_data = res[:data]
if res[:code] == 401
res[:code] = 502
resp_data = {
:message => 'Authentication to the Insights Service failed.',
:headers => {}
}
end
if resp_data.respond_to?(:headers)
if resp_data.[:content_disposition]
send_data resp_data, disposition: resp_data.[:content_disposition], type: resp_data.[:content_type]
return
end
if resp_data.[:x_resource_count]
response.['x-resource-count'] = resp_data.[:x_resource_count]
end
render status: res[:code], json: resp_data
else
render status: res[:code], json: resp_data
end
end
|
#render_telemetry_off ⇒ Object
32
33
34
|
# File 'app/controllers/redhat_access/api/telemetry_api_controller.rb', line 32
def render_telemetry_off
http_error_response("Telemetry is not enabled for your organization",403)
end
|