redhat_access 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +24 -0
- data/LICENSE.txt +620 -0
- data/README.rdoc +7 -0
- data/Rakefile +131 -0
- data/app/assets/javascripts/insights/app.module.js +64 -0
- data/app/assets/javascripts/insights/application.js +18 -0
- data/app/assets/javascripts/insights/configuration.controller.js +66 -0
- data/app/assets/javascripts/insights/configuration.service.js +28 -0
- data/app/assets/javascripts/insights/views/configuration.html +85 -0
- data/app/assets/javascripts/insights/views/error.html +13 -0
- data/app/assets/javascripts/insights/views/help.html +16 -0
- data/app/assets/javascripts/redhat_access/analytics_dashboard.js +2 -0
- data/app/assets/javascripts/redhat_access/application.js +15 -0
- data/app/assets/javascripts/redhat_access/redhat_access.module.js +126 -0
- data/app/assets/stylesheets/insights/application.css +14 -0
- data/app/assets/stylesheets/insights/insights.css +21 -0
- data/app/assets/stylesheets/redhat_access/application.css +14 -0
- data/app/assets/stylesheets/redhat_access/telemetry_configuration.css +4 -0
- data/app/controllers/redhat_access/analytics_dashboard_controller.rb +12 -0
- data/app/controllers/redhat_access/api/api_controller.rb +24 -0
- data/app/controllers/redhat_access/api/attachments_controller.rb +40 -0
- data/app/controllers/redhat_access/api/logs_controller.rb +49 -0
- data/app/controllers/redhat_access/api/machine_telemetry_api_controller.rb +112 -0
- data/app/controllers/redhat_access/api/strata_proxy_controller.rb +81 -0
- data/app/controllers/redhat_access/api/telemetry_api_controller.rb +179 -0
- data/app/controllers/redhat_access/application_controller.rb +2 -0
- data/app/controllers/redhat_access/cases_controller.rb +14 -0
- data/app/controllers/redhat_access/configuration_controller.rb +21 -0
- data/app/controllers/redhat_access/log_viewer_controller.rb +9 -0
- data/app/controllers/redhat_access/redhat_access_controller.rb +8 -0
- data/app/controllers/redhat_access/search_controller.rb +9 -0
- data/app/controllers/redhat_access/strata_credentials_controller.rb +48 -0
- data/app/controllers/redhat_access/telemetry_configurations_controller.rb +38 -0
- data/app/controllers/redhat_access/telemetry_controller.rb +6 -0
- data/app/helpers/redhat_access/analytics_dashboard_helper.rb +13 -0
- data/app/helpers/redhat_access/application_helper.rb +4 -0
- data/app/helpers/redhat_access/attachments_helper.rb +4 -0
- data/app/helpers/redhat_access/cases_helper.rb +4 -0
- data/app/helpers/redhat_access/log_viewer_helper.rb +4 -0
- data/app/helpers/redhat_access/logs_helper.rb +4 -0
- data/app/helpers/redhat_access/redhat_access_helper.rb +4 -0
- data/app/helpers/redhat_access/search_helper.rb +4 -0
- data/app/helpers/redhat_access/telemetry_configuration_helper.rb +4 -0
- data/app/models/redhat_access/concerns/organization_extensions.rb +10 -0
- data/app/models/redhat_access/telemetry_configuration.rb +11 -0
- data/app/models/redhat_access/telemetry_proxy_credentials.rb +10 -0
- data/app/services/redhat_access/authentication/client_authentication.rb +80 -0
- data/app/services/redhat_access/telemetry/look_ups.rb +233 -0
- data/app/services/redhat_access/telemetry/portal_client.rb +39 -0
- data/app/views/redhat_access/analytics_dashboard/configuration.html.erb +85 -0
- data/app/views/redhat_access/analytics_dashboard/error.html.erb +13 -0
- data/app/views/redhat_access/analytics_dashboard/help.html.erb +16 -0
- data/app/views/redhat_access/analytics_dashboard/index.html.erb +69 -0
- data/app/views/redhat_access/analytics_dashboard/welcome.html.erb +8 -0
- data/app/views/redhat_access/redhat_access/index.html.erb +34 -0
- data/ca/rh_cert-api_chain.pem +74 -0
- data/config/config.yml.example +15 -0
- data/config/environments/development.rb +5 -0
- data/config/initializers/load_config.rb +5 -0
- data/config/mount_engine.rb +3 -0
- data/config/routes.rb +36 -0
- data/db/migrate/20141204161152_create_redhat_access_telemetry_proxy_credentials.rb +11 -0
- data/db/migrate/20150319153744_create_redhat_access_telemetry_configurations.rb +13 -0
- data/db/migrate/20160425175501_add_email_to_telemetry_configurations.rb +5 -0
- data/db/seeds.d/200-update-insights-roles.rb +11 -0
- data/lib/redhat_access/configuration.rb +8 -0
- data/lib/redhat_access/engine.rb +225 -0
- data/lib/redhat_access/sos_reports/generator.rb +58 -0
- data/lib/redhat_access/strata/client.rb +39 -0
- data/lib/redhat_access/version.rb +3 -0
- data/lib/redhat_access.rb +5 -0
- data/lib/tasks/redhat_access_tasks.rake +41 -0
- data/locale/Makefile +62 -0
- data/locale/de/LC_MESSAGES/redhat_access.mo +0 -0
- data/locale/de/redhat_access.po +589 -0
- data/locale/es/LC_MESSAGES/redhat_access.mo +0 -0
- data/locale/es/redhat_access.po +589 -0
- data/locale/fr/LC_MESSAGES/redhat_access.mo +0 -0
- data/locale/fr/redhat_access.po +593 -0
- data/locale/gemspec.rb +2 -0
- data/locale/it/LC_MESSAGES/redhat_access.mo +0 -0
- data/locale/it/redhat_access.po +589 -0
- data/locale/ja/LC_MESSAGES/redhat_access.mo +0 -0
- data/locale/ja/redhat_access.po +569 -0
- data/locale/ko/LC_MESSAGES/redhat_access.mo +0 -0
- data/locale/ko/redhat_access.po +570 -0
- data/locale/pt/LC_MESSAGES/redhat_access.mo +0 -0
- data/locale/pt/redhat_access.po +588 -0
- data/locale/redhat_access.pot +34 -0
- data/locale/ru/LC_MESSAGES/redhat_access.mo +0 -0
- data/locale/ru/redhat_access.po +580 -0
- data/locale/zh/LC_MESSAGES/redhat_access.mo +0 -0
- data/locale/zh/redhat_access.po +561 -0
- data/redhat_access.gemspec +30 -0
- data/script/rails +8 -0
- data/script/sos_reports/foreman_sosreport.pam +9 -0
- data/script/sos_reports/foreman_sosreport_console.apps +3 -0
- data/script/sos_reports/foreman_sosreport_wrapper.py +65 -0
- data/test/dummy/README.rdoc +261 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/config/application.rb +59 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +25 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/fixtures/redhat_access/telemetry_configurations.yml +11 -0
- data/test/fixtures/redhat_access/telemetry_proxy_credentials.yml +11 -0
- data/test/functional/redhat_access/analytics_dashboard_controller_test.rb +11 -0
- data/test/functional/redhat_access/attachments_controller_test.rb +11 -0
- data/test/functional/redhat_access/cases_controller_test.rb +16 -0
- data/test/functional/redhat_access/configuration_controller_test.rb +11 -0
- data/test/functional/redhat_access/log_viewer_controller_test.rb +11 -0
- data/test/functional/redhat_access/logs_controller_test.rb +9 -0
- data/test/functional/redhat_access/redhat_access_controller_test.rb +11 -0
- data/test/functional/redhat_access/search_controller_test.rb +11 -0
- data/test/functional/redhat_access/telemetry_configuration_controller_test.rb +26 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/models/redhat_access/telemetry_proxy_credentials_test.rb +9 -0
- data/test/redhat_access_test.rb +7 -0
- data/test/sos-report-test.rb +32 -0
- data/test/test_helper.rb +15 -0
- data/test/unit/helpers/redhat_access/analytics_dashboard_helper_test.rb +6 -0
- data/test/unit/helpers/redhat_access/attachments_helper_test.rb +6 -0
- data/test/unit/helpers/redhat_access/cases_helper_test.rb +6 -0
- data/test/unit/helpers/redhat_access/log_viewer_helper_test.rb +6 -0
- data/test/unit/helpers/redhat_access/logs_helper_test.rb +6 -0
- data/test/unit/helpers/redhat_access/redhat_access_helper_test.rb +6 -0
- data/test/unit/helpers/redhat_access/search_helper_test.rb +6 -0
- data/test/unit/helpers/redhat_access/telemetry_configuration_helper_test.rb +6 -0
- data/test/unit/redhat_access/telemetry_configuration_test.rb +9 -0
- data/vendor/assets/fonts/fonts/FontAwesome.otf +0 -0
- data/vendor/assets/fonts/fonts/fontawesome-webfont.eot +0 -0
- data/vendor/assets/fonts/fonts/fontawesome-webfont.svg +655 -0
- data/vendor/assets/fonts/fonts/fontawesome-webfont.ttf +0 -0
- data/vendor/assets/fonts/fonts/fontawesome-webfont.woff +0 -0
- data/vendor/assets/fonts/fonts/icomoon.eot +0 -0
- data/vendor/assets/fonts/fonts/icomoon.svg +22 -0
- data/vendor/assets/fonts/fonts/icomoon.ttf +0 -0
- data/vendor/assets/fonts/fonts/icomoon.woff +0 -0
- data/vendor/assets/fonts/fonts/overpass_bold-web.eot +0 -0
- data/vendor/assets/fonts/fonts/overpass_bold-web.svg +454 -0
- data/vendor/assets/fonts/fonts/overpass_bold-web.ttf +0 -0
- data/vendor/assets/fonts/fonts/overpass_bold-web.woff +0 -0
- data/vendor/assets/fonts/fonts/overpass_light-webfont.eot +0 -0
- data/vendor/assets/fonts/fonts/overpass_light-webfont.svg +2105 -0
- data/vendor/assets/fonts/fonts/overpass_light-webfont.ttf +0 -0
- data/vendor/assets/fonts/fonts/overpass_light-webfont.woff +0 -0
- data/vendor/assets/fonts/fonts/overpass_regular-web.eot +0 -0
- data/vendor/assets/fonts/fonts/overpass_regular-web.svg +454 -0
- data/vendor/assets/fonts/fonts/overpass_regular-web.ttf +0 -0
- data/vendor/assets/fonts/fonts/overpass_regular-web.woff +0 -0
- data/vendor/assets/fonts/fonts/portalicons.eot +0 -0
- data/vendor/assets/fonts/fonts/portalicons.svg +145 -0
- data/vendor/assets/fonts/fonts/portalicons.ttf +0 -0
- data/vendor/assets/fonts/fonts/portalicons.woff +0 -0
- data/vendor/assets/images/images/Icon_RH_Document_Blueprint_RGB_Button.png +0 -0
- data/vendor/assets/images/images/Icon_RH_Misc_Lifestyle_RGB_Button.png +0 -0
- data/vendor/assets/images/images/Icon_RH_Software_Data_CMYK_Button.png +0 -0
- data/vendor/assets/images/images/Icon_RH_Software_Transfer-Upload_CMYK_Button.png +0 -0
- data/vendor/assets/images/images/bg1.jpg +0 -0
- data/vendor/assets/images/images/bg_body.jpg +0 -0
- data/vendor/assets/images/images/bg_chart-shadow.png +0 -0
- data/vendor/assets/images/images/bg_dount-hole-na.png +0 -0
- data/vendor/assets/images/images/bg_glow.jpg +0 -0
- data/vendor/assets/images/images/bg_pattern.png +0 -0
- data/vendor/assets/images/images/i_chart.png +0 -0
- data/vendor/assets/images/images/img-insights-connection-sat.png +0 -0
- data/vendor/assets/images/images/img-insights-connection.png +0 -0
- data/vendor/assets/images/images/img-sat5-step2-admin.png +0 -0
- data/vendor/assets/images/images/img-sat5-step3-completed.png +0 -0
- data/vendor/assets/images/images/img-sat5-step3-pending.png +0 -0
- data/vendor/assets/images/images/img-sat5-step3-setup.png +0 -0
- data/vendor/assets/images/images/img-sat5-step5-overview.png +0 -0
- data/vendor/assets/images/images/img-sat5-step5-reports.png +0 -0
- data/vendor/assets/images/images/img-sat5-step5-systems.png +0 -0
- data/vendor/assets/images/images/img-sat6-step2.jpg +0 -0
- data/vendor/assets/images/images/img-sat6-step3.jpg +0 -0
- data/vendor/assets/images/images/img-sat6-step3.png +0 -0
- data/vendor/assets/images/images/img-sat6-step4.jpg +0 -0
- data/vendor/assets/images/images/img-sat6-step5a.jpg +0 -0
- data/vendor/assets/images/images/img-sat6-step5b.jpg +0 -0
- data/vendor/assets/images/images/img-sat6-step5c.jpg +0 -0
- data/vendor/assets/images/images/img-sat6-step5d.jpg +0 -0
- data/vendor/assets/images/images/keynote-snap.jpg +0 -0
- data/vendor/assets/images/images/keynote-snap.png +0 -0
- data/vendor/assets/images/images/splash-gettingstarted.jpg +0 -0
- data/vendor/assets/images/images/splash-learnmore.jpg +0 -0
- data/vendor/assets/images/images/splash-security.jpg +0 -0
- data/vendor/assets/javascripts/angular/angular.js +20131 -0
- data/vendor/assets/javascripts/redhat_access/redhat_access_angular_ui-deps.js +14103 -0
- data/vendor/assets/javascripts/redhat_access/redhat_access_angular_ui.js +7854 -0
- data/vendor/assets/javascripts/telemetry/insights.js +39 -0
- data/vendor/assets/stylesheets/redhat_access/redhat_access_angular_ui-deps.css +11 -0
- data/vendor/assets/stylesheets/redhat_access/redhat_access_angular_ui.css +1 -0
- data/vendor/assets/stylesheets/telemetry/sat6.css +18 -0
- metadata +341 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require_dependency "redhat_access/application_controller"
|
|
2
|
+
module RedhatAccess
|
|
3
|
+
module Api
|
|
4
|
+
class ApiController < ApplicationController
|
|
5
|
+
#skip_before_filter :verify_authenticity_token, :unless => :protect_api_from_forgery?
|
|
6
|
+
#before_filter :set_default_response_format, :authorize, :add_version_header, :set_gettext_locale
|
|
7
|
+
before_filter :session_expiry, :update_activity_time
|
|
8
|
+
#around_filter :set_timezone
|
|
9
|
+
|
|
10
|
+
cache_sweeper :topbar_sweeper
|
|
11
|
+
|
|
12
|
+
respond_to :json
|
|
13
|
+
|
|
14
|
+
def http_error_response(msg,status)
|
|
15
|
+
render json: { :message => msg }, :status => status
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def api_request?
|
|
19
|
+
true
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
require_dependency "redhat_access/application_controller"
|
|
2
|
+
require_dependency "redhat_access/strata/client"
|
|
3
|
+
require_dependency "redhat_access/sos_reports/generator"
|
|
4
|
+
|
|
5
|
+
module RedhatAccess
|
|
6
|
+
module Api
|
|
7
|
+
class AttachmentsController < RedhatAccess::Api::ApiController
|
|
8
|
+
wrap_parameters :attach_payload, format: :json
|
|
9
|
+
def index
|
|
10
|
+
render :text => "SOS Report?checked=true",
|
|
11
|
+
:layout => false
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def create
|
|
15
|
+
data = params[:attach_payload]
|
|
16
|
+
begin
|
|
17
|
+
case_number = data[:caseNum]
|
|
18
|
+
sos_file = RedhatAccess::SosReports::Generator.create_report case_number
|
|
19
|
+
strata = RedhatAccess::Strata::Client.new(data[:authToken])
|
|
20
|
+
strata.api.attachment_broker.add(case_number,
|
|
21
|
+
false,
|
|
22
|
+
sos_file,
|
|
23
|
+
"Attachment for case #{case_number}")
|
|
24
|
+
render :nothing => true,
|
|
25
|
+
:status => 201
|
|
26
|
+
rescue => e
|
|
27
|
+
logger.error e.backtrace
|
|
28
|
+
#logger.error "Failed to import facts for Host::Discovered: #{e}"
|
|
29
|
+
render :text => "Error attaching sos file " + e.message,
|
|
30
|
+
:layout => false ,
|
|
31
|
+
:status => 500
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def api_version
|
|
36
|
+
'v1'
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
require_dependency "redhat_access/application_controller"
|
|
2
|
+
|
|
3
|
+
module RedhatAccess
|
|
4
|
+
module Api
|
|
5
|
+
class LogsController < RedhatAccess::Api::ApiController
|
|
6
|
+
# Use temporary implementation to show proof of ooncept in beta release
|
|
7
|
+
# In GA a more robust implementation will be used
|
|
8
|
+
#@@log_files = ['/var/log/foreman/production.log','/var/log/foreman/delayed_job.log','/var/log/foreman/jobs-startup.log']
|
|
9
|
+
@@log_files = REDHAT_ACCESS_CONFIG[:diagnostic_logs]
|
|
10
|
+
|
|
11
|
+
def index
|
|
12
|
+
#
|
|
13
|
+
# This REST hack of using index for both list and specific resource get
|
|
14
|
+
# is being forced by the current UI design
|
|
15
|
+
#
|
|
16
|
+
path = params[:path]
|
|
17
|
+
if path.nil?
|
|
18
|
+
render :plain => get_available_logs, :layout => false
|
|
19
|
+
else
|
|
20
|
+
if is_valid_file? path
|
|
21
|
+
render :file => path, :layout => false
|
|
22
|
+
else
|
|
23
|
+
render :text => ''
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def get_available_logs
|
|
29
|
+
files = @@log_files.select do |file|
|
|
30
|
+
File.exist?(file) && File.readable?(file) && File.size(file) > 0
|
|
31
|
+
end
|
|
32
|
+
files.join("\n")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def is_valid_file? file
|
|
36
|
+
@@log_files.include?(file) && File.exist?(file) && File.readable?(file) && File.size(file) > 0
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def permission_denied
|
|
41
|
+
render :template => "katello/common/403"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def api_version
|
|
45
|
+
'v1'
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
require_dependency "redhat_access/application_controller"
|
|
2
|
+
require 'rest_client'
|
|
3
|
+
require 'redhat_access_lib'
|
|
4
|
+
require 'uri'
|
|
5
|
+
|
|
6
|
+
module RedhatAccess
|
|
7
|
+
module Api
|
|
8
|
+
class MachineTelemetryApiController < TelemetryApiController
|
|
9
|
+
|
|
10
|
+
skip_before_filter :authorize
|
|
11
|
+
skip_before_filter :require_login
|
|
12
|
+
skip_before_filter :session_expiry
|
|
13
|
+
skip_before_filter :verify_authenticity_token
|
|
14
|
+
skip_before_filter :check_telemetry_enabled
|
|
15
|
+
before_filter :telemetry_auth
|
|
16
|
+
before_filter :ensure_telemetry_enabled, :only => [:proxy, :proxy_upload]
|
|
17
|
+
|
|
18
|
+
def telemetry_auth
|
|
19
|
+
authenticate_client
|
|
20
|
+
unless valid_machine_user?
|
|
21
|
+
deny_access
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def ensure_telemetry_enabled
|
|
26
|
+
render_telemetry_off unless telemetry_enabled_for_uuid?(User.current.login)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def get_auth_opts()
|
|
30
|
+
if valid_machine_user?
|
|
31
|
+
get_ssl_options_for_uuid(User.current.login, nil)
|
|
32
|
+
else
|
|
33
|
+
raise(RedhatAccess::Telemetry::LookUps::RecordNotFound,'Invalid User')
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def api_connection_test
|
|
38
|
+
client = get_api_client
|
|
39
|
+
res = client.call_tapi('GET', '/', nil, nil, nil)
|
|
40
|
+
Rails.logger.debug(res[:data])
|
|
41
|
+
render status: res[:code], json: {}
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def proxy_upload
|
|
45
|
+
original_method = request.method
|
|
46
|
+
original_params = add_branch_to_params(request.query_parameters)
|
|
47
|
+
original_payload = request.request_parameters[controller_name]
|
|
48
|
+
if not params[:id] and params[:test]
|
|
49
|
+
resource = "uploads/"
|
|
50
|
+
original_payload = {:test => params[:test]}
|
|
51
|
+
else
|
|
52
|
+
resource = "uploads/#{params[:id]}"
|
|
53
|
+
end
|
|
54
|
+
if params[:file]
|
|
55
|
+
original_payload = get_file_data(params)
|
|
56
|
+
end
|
|
57
|
+
client = get_api_client
|
|
58
|
+
Rails.logger.debug("Proxy upload original_payload : #{original_payload}")
|
|
59
|
+
res = client.call_tapi(original_method, URI.escape(resource), original_params, original_payload, nil, use_subsets)
|
|
60
|
+
render status: res[:code] , json: res[:data]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def get_branch_info
|
|
64
|
+
uuid = User.current.login
|
|
65
|
+
begin
|
|
66
|
+
org = get_organization(uuid)
|
|
67
|
+
major,minor,build = get_plugin_parent_version.scan(/\d+/)
|
|
68
|
+
client_id = {:remote_leaf => uuid ,
|
|
69
|
+
:remote_branch => get_branch_id_for_uuid(uuid),
|
|
70
|
+
:display_name => org.name,
|
|
71
|
+
:hostname => request.host,
|
|
72
|
+
:product => {:type => get_plugin_parent_name,
|
|
73
|
+
:major_version => major,
|
|
74
|
+
:minor_version => minor
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
render :json => client_id.to_json
|
|
78
|
+
rescue RedhatAccess::Telemetry::LookUps::RecordNotFound => e
|
|
79
|
+
http_error_response(e.message, 400)
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
protected
|
|
86
|
+
|
|
87
|
+
def use_subsets
|
|
88
|
+
false
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def valid_machine_user?
|
|
92
|
+
if User.current && User.current.is_a?(RedhatAccess::Authentication::CertUser)
|
|
93
|
+
return true unless get_content_host(User.current.login).nil?
|
|
94
|
+
return false
|
|
95
|
+
else
|
|
96
|
+
return false
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
def get_http_user_agent
|
|
101
|
+
base_user_agent = super
|
|
102
|
+
client_user_agent = request.env['HTTP_USER_AGENT']
|
|
103
|
+
"#{base_user_agent};#{client_user_agent}"
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def get_branch_id
|
|
108
|
+
get_branch_id_for_uuid(User.current.login)
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
require_dependency "redhat_access/application_controller"
|
|
2
|
+
require 'rest_client'
|
|
3
|
+
require 'redhat_access_lib'
|
|
4
|
+
require 'uri'
|
|
5
|
+
|
|
6
|
+
module RedhatAccess
|
|
7
|
+
module Api
|
|
8
|
+
class StrataProxyController < TelemetryApiController
|
|
9
|
+
|
|
10
|
+
def action_permission
|
|
11
|
+
case params[:action]
|
|
12
|
+
when 'call'
|
|
13
|
+
:call
|
|
14
|
+
else
|
|
15
|
+
super
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def get_auth_opts()
|
|
20
|
+
#We only support pass through basic auth @see get_api_client method
|
|
21
|
+
return {}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def index
|
|
25
|
+
render :text => "Strata Telemetry API"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
# The method that "proxies" tapi requests over to Strata
|
|
30
|
+
def call
|
|
31
|
+
original_method = request.method
|
|
32
|
+
original_params = request.query_parameters
|
|
33
|
+
original_payload = request.request_parameters[controller_name]
|
|
34
|
+
if request.post? && request.raw_post
|
|
35
|
+
original_payload = request.raw_post.clone
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
if request.put?
|
|
39
|
+
original_payload = request.body.read
|
|
40
|
+
end
|
|
41
|
+
resource = params[:path] == nil ? "/" : params[:path]
|
|
42
|
+
if params[:file]
|
|
43
|
+
original_payload = get_file_data(params)
|
|
44
|
+
end
|
|
45
|
+
client = get_api_client
|
|
46
|
+
res = client.call_strata(original_method, URI.escape(resource), original_params, original_payload, nil)
|
|
47
|
+
#401 erros means our proxy is not configured right.
|
|
48
|
+
#Change it to 502 to distinguish with local applications 401 errors
|
|
49
|
+
resp_data = res[:data]
|
|
50
|
+
if res[:code] == 401
|
|
51
|
+
res[:code] = 502
|
|
52
|
+
resp_data = {
|
|
53
|
+
:message => 'Authentication to the Strata Service failed.'
|
|
54
|
+
}
|
|
55
|
+
end
|
|
56
|
+
render status: res[:code] , json: resp_data #.gsub('https://api.access.redhat.com','https://192.168.121.13/redhat_access/strata/')
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def get_api_client
|
|
60
|
+
accept_hdr = request.headers['Accept']
|
|
61
|
+
content_hdr = request.headers['Content-Type']
|
|
62
|
+
headers = { 'accept' => accept_hdr}
|
|
63
|
+
unless content_hdr.nil?
|
|
64
|
+
headers['content-type'] = content_hdr
|
|
65
|
+
end
|
|
66
|
+
headers['Authorization'] = env['HTTP_AUTHORIZATION'] if env['HTTP_AUTHORIZATION']
|
|
67
|
+
Rails.logger.debug("User agent for telemetry is #{get_http_user_agent}")
|
|
68
|
+
strata_host = 'https://api.' + REDHAT_ACCESS_CONFIG[:strata_host]
|
|
69
|
+
return RedhatAccess::Telemetry::PortalClient.new(strata_host,
|
|
70
|
+
strata_host,
|
|
71
|
+
nil,
|
|
72
|
+
self,
|
|
73
|
+
{:logger => Rails.logger,
|
|
74
|
+
:http_proxy => get_portal_http_proxy,
|
|
75
|
+
:user_agent => get_http_user_agent,
|
|
76
|
+
:headers => headers
|
|
77
|
+
})
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
require_dependency "redhat_access/application_controller"
|
|
2
|
+
require 'rest_client'
|
|
3
|
+
require 'redhat_access_lib'
|
|
4
|
+
require 'uri'
|
|
5
|
+
|
|
6
|
+
module RedhatAccess
|
|
7
|
+
module Api
|
|
8
|
+
class TelemetryApiController < RedhatAccess::Api::ApiController
|
|
9
|
+
include RedhatAccess::Authentication::ClientAuthentication
|
|
10
|
+
include RedhatAccess::Telemetry::LookUps
|
|
11
|
+
|
|
12
|
+
before_filter :check_telemetry_enabled, :only => [:proxy]
|
|
13
|
+
|
|
14
|
+
UPLOAD_HOST = REDHAT_ACCESS_CONFIG[:telemetry_upload_host]
|
|
15
|
+
API_HOST = REDHAT_ACCESS_CONFIG[:telemetry_api_host]
|
|
16
|
+
UPLOAD_URL = "#{UPLOAD_HOST}/r/insights/uploads"
|
|
17
|
+
STRATA_URL = "#{API_HOST}/r/insights"
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def action_permission
|
|
21
|
+
case params[:action]
|
|
22
|
+
when 'proxy'
|
|
23
|
+
:proxy
|
|
24
|
+
when 'connection_status'
|
|
25
|
+
:connection_status
|
|
26
|
+
else
|
|
27
|
+
super
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def check_telemetry_enabled
|
|
32
|
+
render_telemetry_off unless telemetry_enabled?(Organization.current)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def render_telemetry_off
|
|
36
|
+
http_error_response("Telemetry is not enabled for your organization",403)
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def get_creds
|
|
40
|
+
# enable this once cert auth is fixed:
|
|
41
|
+
# return User
|
|
42
|
+
#return TelemetryProxyCredentials.limit(1)[0]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def get_auth_opts()
|
|
46
|
+
return get_ssl_options_for_org(Organization.current ,nil)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def index
|
|
50
|
+
render :text => "Telemetry API"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# # Returns an array of the machine IDs that this user has access to
|
|
55
|
+
def get_machines
|
|
56
|
+
#TODO err out if org is not selected
|
|
57
|
+
machines = get_content_hosts(Organization.current)
|
|
58
|
+
if machines.empty?
|
|
59
|
+
machines = ['NULL_SET']
|
|
60
|
+
end
|
|
61
|
+
Rails.logger.debug("Machines : #{machines}")
|
|
62
|
+
machines
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def connection_status
|
|
66
|
+
client = get_api_client
|
|
67
|
+
res = client.call_tapi('GET', 'me', nil, nil, nil)
|
|
68
|
+
Rails.logger.debug(res[:data])
|
|
69
|
+
case res[:code]
|
|
70
|
+
when 200
|
|
71
|
+
resp = JSON.parse(res[:data])
|
|
72
|
+
data = {
|
|
73
|
+
:connectionStatus => 'Connected',
|
|
74
|
+
:account => resp["account_number"],
|
|
75
|
+
:company => resp["company"],
|
|
76
|
+
:orgId => resp["ord_id"]
|
|
77
|
+
}
|
|
78
|
+
render status: res[:code] , json: data
|
|
79
|
+
when 401
|
|
80
|
+
data = {
|
|
81
|
+
:connectionStatus => 'Authentication Failure',
|
|
82
|
+
:account => 'Unknown',
|
|
83
|
+
:company => 'Unknown',
|
|
84
|
+
}
|
|
85
|
+
render status: 200 , json: data
|
|
86
|
+
else
|
|
87
|
+
data = {
|
|
88
|
+
:connectionStatus => 'Connection Failed',
|
|
89
|
+
:account => 'Unknown',
|
|
90
|
+
:company => 'Unknown',
|
|
91
|
+
}
|
|
92
|
+
render status: 200 , json: data
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# The method that "proxies" tapi requests over to Strata
|
|
97
|
+
def proxy
|
|
98
|
+
original_method = request.method
|
|
99
|
+
original_params = request.query_parameters
|
|
100
|
+
if request.user_agent and not request.user_agent.include?('redhat_access_cfme')
|
|
101
|
+
original_params = add_branch_to_params(request.query_parameters)
|
|
102
|
+
end
|
|
103
|
+
original_payload = request.request_parameters[controller_name]
|
|
104
|
+
if request.post? && request.raw_post
|
|
105
|
+
original_payload = request.raw_post.clone
|
|
106
|
+
end
|
|
107
|
+
resource = params[:path] == nil ? "/" : params[:path]
|
|
108
|
+
if params[:file]
|
|
109
|
+
original_payload = get_file_data(params)
|
|
110
|
+
end
|
|
111
|
+
client = get_api_client
|
|
112
|
+
res = client.call_tapi(original_method, URI.escape(resource), original_params, original_payload, nil, use_subsets)
|
|
113
|
+
#401 erros means our proxy is not configured right.
|
|
114
|
+
#Change it to 502 to distinguish with local applications 401 errors
|
|
115
|
+
resp_data = res[:data]
|
|
116
|
+
if res[:code] == 401
|
|
117
|
+
res[:code] = 502
|
|
118
|
+
resp_data = {
|
|
119
|
+
:message => 'Authentication to the Insights Service failed.',
|
|
120
|
+
:headers => {}
|
|
121
|
+
}
|
|
122
|
+
end
|
|
123
|
+
if original_params && original_params["accept"] && original_params["accept"] = "csv"
|
|
124
|
+
send_data resp_data, type: 'text/csv; charset=utf-8', :filename => "insights_report.csv"
|
|
125
|
+
else
|
|
126
|
+
if resp_data.headers && resp_data.headers[:x_resource_count]
|
|
127
|
+
response.headers['X-Resource-Count'] = resp_data.headers[:x_resource_count]
|
|
128
|
+
end
|
|
129
|
+
render status: res[:code] , json: resp_data
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
protected
|
|
134
|
+
|
|
135
|
+
def use_subsets
|
|
136
|
+
true
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def get_file_data params
|
|
140
|
+
return {
|
|
141
|
+
:file => params[:file],
|
|
142
|
+
:filename => params[:file].original_filename
|
|
143
|
+
}
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def add_branch_to_params(params)
|
|
147
|
+
if params.nil?
|
|
148
|
+
params = {}
|
|
149
|
+
end
|
|
150
|
+
params[:branch_id] = get_branch_id
|
|
151
|
+
Rails.logger.debug{"Request parameters for telemetry request #{params}"}
|
|
152
|
+
params
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def get_http_user_agent
|
|
156
|
+
"#{get_plugin_parent_name}/#{get_plugin_parent_version};#{get_rha_plugin_name}/#{get_rha_plugin_version}"
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def get_branch_id
|
|
160
|
+
get_branch_id_for_org(Organization.current)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
def get_api_client
|
|
164
|
+
Rails.logger.debug("User agent for telemetry is #{get_http_user_agent}")
|
|
165
|
+
return RedhatAccess::Telemetry::PortalClient.new(UPLOAD_URL,STRATA_URL,
|
|
166
|
+
get_creds,
|
|
167
|
+
self,
|
|
168
|
+
{:logger => Rails.logger,
|
|
169
|
+
:http_proxy => get_portal_http_proxy,
|
|
170
|
+
:user_agent => get_http_user_agent})
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def api_version
|
|
174
|
+
'v1'
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
end
|
|
178
|
+
end
|
|
179
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require_dependency "redhat_access/application_controller"
|
|
2
|
+
|
|
3
|
+
module RedhatAccess
|
|
4
|
+
class CasesController < ApplicationController
|
|
5
|
+
def create
|
|
6
|
+
redirect_to '/redhat_access/#/case/new'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def index
|
|
10
|
+
redirect_to '/redhat_access/#/case/list'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require_dependency "redhat_access/application_controller"
|
|
2
|
+
require_dependency "redhat_access/version"
|
|
3
|
+
|
|
4
|
+
module RedhatAccess
|
|
5
|
+
class ConfigurationController < ApplicationController
|
|
6
|
+
def index
|
|
7
|
+
strata_host = REDHAT_ACCESS_CONFIG[:strata_host]
|
|
8
|
+
if strata_host.nil?
|
|
9
|
+
strata_host = 'access.redhat.com'
|
|
10
|
+
end
|
|
11
|
+
client_id = "foreman_plugin_#{REDHAT_ACCESS_CONFIG[:deployment]}_#{RedhatAccess::VERSION}"
|
|
12
|
+
render :json => { :strataHostName => strata_host,:strataClientId => client_id }.to_json,
|
|
13
|
+
:layout => false
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def api_request?
|
|
17
|
+
true
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require_dependency "redhat_access/application_controller"
|
|
2
|
+
|
|
3
|
+
module RedhatAccess
|
|
4
|
+
class StrataCredentialsController < ApplicationController
|
|
5
|
+
|
|
6
|
+
def index
|
|
7
|
+
if TelemetryProxyCredentials.count == 0
|
|
8
|
+
render json: { :status => 'not_found' }, status: 404
|
|
9
|
+
return
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
creds = TelemetryProxyCredentials.limit(1)[0]
|
|
13
|
+
render json: { :status => 'success', :username => creds.username }
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def destroy
|
|
17
|
+
TelemetryProxyCredentials.delete_all
|
|
18
|
+
render json: { :status => 'success' }
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def create
|
|
22
|
+
if TelemetryProxyCredentials.count != 0
|
|
23
|
+
TelemetryProxyCredentials.delete_all
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
creds = TelemetryProxyCredentials.new
|
|
27
|
+
|
|
28
|
+
data = params[:strata_credential]
|
|
29
|
+
username = data[:username]
|
|
30
|
+
password = data[:password]
|
|
31
|
+
|
|
32
|
+
if not username.present? && username.length > 1
|
|
33
|
+
render json: { :status => 'error', :message => 'username missing or too short' }, status: 400
|
|
34
|
+
return
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
if not password.present? && password.length > 4
|
|
38
|
+
render json: { :status => 'error', :message => 'password missing or too short' }, status: 400
|
|
39
|
+
return
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
creds.attributes = { username: username, password: password }
|
|
43
|
+
creds.save
|
|
44
|
+
|
|
45
|
+
render json: { :status => 'success', :message => 'credentials saved' }
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require_dependency "redhat_access/application_controller"
|
|
2
|
+
|
|
3
|
+
module RedhatAccess
|
|
4
|
+
class TelemetryConfigurationsController < ApplicationController
|
|
5
|
+
include RedhatAccess::Telemetry::LookUps
|
|
6
|
+
def show
|
|
7
|
+
#TODO require current ORG
|
|
8
|
+
conf = get_telemetry_config(Organization.current)
|
|
9
|
+
render json: conf.to_json(:except => [ :id, :created_at, :portal_password ,:updated_at])
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def update
|
|
13
|
+
#TODO require current ORG
|
|
14
|
+
conf = get_telemetry_config(Organization.current)
|
|
15
|
+
if conf
|
|
16
|
+
begin
|
|
17
|
+
if conf.update_attributes(telemetry_configuration_params)
|
|
18
|
+
render json: {:message => "config updated"}
|
|
19
|
+
else
|
|
20
|
+
render json: {:error=>"Invalid parameters"}.to_json, status: 400
|
|
21
|
+
end
|
|
22
|
+
rescue=>e
|
|
23
|
+
Rails.logger.info(e)
|
|
24
|
+
render json: {:error=>"Error processing update"}.to_json, status: 500
|
|
25
|
+
end
|
|
26
|
+
else
|
|
27
|
+
render json: {:error=>"Configurationnotfound"}.to_json, status: 404
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
private
|
|
32
|
+
|
|
33
|
+
def telemetry_configuration_params
|
|
34
|
+
params.require(:telemetry_configuration).permit(:enable_telemetry, :portal_password, :portal_user, :organization_id, :email)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module RedhatAccess
|
|
2
|
+
module AnalyticsDashboardHelper
|
|
3
|
+
include RedhatAccess::Telemetry::LookUps
|
|
4
|
+
|
|
5
|
+
def help_path?
|
|
6
|
+
request.path == '/redhat_access/insights/help'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def manage_path?
|
|
10
|
+
request.path == '/redhat_access/insights/manage'
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|