Sha256: 1144b7020d3ff4b6eaceec9243029b5fb985075597f4844416cf0fd751607bcf

Contents?: true

Size: 1.55 KB

Versions: 21

Compression:

Stored size: 1.55 KB

Contents

require "grape"

module RestFtpDaemon
  module API
    class Debug < Grape::API
      include BmcDaemonLib

      ### HELPERS
      helpers do
        def log_context
          {caller: "API::Debug"}
        end

        def debug_metrics
          Metrics.sample
        end

        def debug_encodings
          # Encodings
          encodings = {}
          jobs = JobQueue.instance.jobs

          jobs.each do |job|
            # here = out[job.id] = {}
            me = encodings[job.id] = {}

            me[:error] = job.error.encoding.to_s unless job.error.nil?
            me[:status] = job.status.encoding.to_s unless job.status.nil?

            Job::IMPORTED.each do |name|
              value = job.send(name)
              me[name] = value.encoding.to_s if value.is_a? String
            end

            job.infos.each do |name, value|
              me["infos_#{name}"] = value.encoding.to_s if value.is_a? String
            end
          end
        end

      end

      ### ENDPOINTS
      desc "debug"#, hidden: true
      get "/" do

        # Extract routes
        routes = []
        API::Root.routes.each do |route|
          routes << {
            url: "#{route.options[:method]} #{route.pattern.path}",
            vars: route.instance_variables,
            options: route.options,
            }

        end

        # Build response
        return  {
          metrics: debug_metrics,
          encodings: debug_encodings,
          routes: routes,
          content_types: Grape::ContentTypes::CONTENT_TYPES
          }
      end

    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
rest-ftp-daemon-1.1.1 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.1.0 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.15 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.14 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.13 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.12 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.11 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.10 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.9 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.8 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.7 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.6 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.5 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.4 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.3 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.2 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-1.0.1 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-0.502.2 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-0.502.1 lib/rest-ftp-daemon/api/debug.rb
rest-ftp-daemon-0.502.0 lib/rest-ftp-daemon/api/debug.rb