Class: RedhatAccess::Api::LogsController

Inherits:
ApiController show all
Defined in:
app/controllers/redhat_access/api/logs_controller.rb

Constant Summary collapse

@@log_files =

Use temporary implementation to show proof of ooncept in beta release In GA a more robust implementation will be used @@log_files = [‘/var/log/foreman/production.log’,‘/var/log/foreman/delayed_job.log’,‘/var/log/foreman/jobs-startup.log’]

REDHAT_ACCESS_CONFIG[:diagnostic_logs]

Instance Method Summary collapse

Methods inherited from ApiController

#api_request?, #http_error_response

Instance Method Details

#api_versionObject



44
45
46
# File 'app/controllers/redhat_access/api/logs_controller.rb', line 44

def api_version
  'v1'
end

#get_available_logsObject



28
29
30
31
32
33
# File 'app/controllers/redhat_access/api/logs_controller.rb', line 28

def get_available_logs
  files = @@log_files.select do |file|
    File.exist?(file) && File.readable?(file) && File.size(file) > 0
  end
  files.join("\n")
end

#is_valid_file?(file) ⇒ Boolean

Returns:

  • (Boolean)


35
36
37
# File 'app/controllers/redhat_access/api/logs_controller.rb', line 35

def is_valid_file?  file
  @@log_files.include?(file) && File.exist?(file) && File.readable?(file) && File.size(file) > 0
end

#logsObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/controllers/redhat_access/api/logs_controller.rb', line 11

def logs
  #
  # This REST hack of using index for both list and specific resource get
  # is being forced by the current UI design
  #
  path = params[:path]
  if path.nil?
    render  :plain => get_available_logs, :layout => false
  else
    if is_valid_file? path
      render :file => path, :layout => false
    else
      render :text => ''
    end
  end
end

#permission_deniedObject



40
41
42
# File 'app/controllers/redhat_access/api/logs_controller.rb', line 40

def permission_denied
  render status: 403 , json: {:message => 'Permission denied.'}
end