Sha256: 98a228a287dbec9a9761b0f90f13e9e6e2896aa5816a612830e5913ce4d19289

Contents?: true

Size: 1.68 KB

Versions: 94

Compression:

Stored size: 1.68 KB

Contents

module Puma
  module App
    class Status
      def initialize(cli)
        @cli = cli
        @auth_token = nil
      end
      OK_STATUS = '{ "status": "ok" }'.freeze

      attr_accessor :auth_token

      def authenticate(env)
        return true unless @auth_token
        env['QUERY_STRING'].to_s.split(/&;/).include?("token=#{@auth_token}")
      end

      def rack_response(status, body, content_type='application/json')
        headers = {
          'Content-Type' => content_type,
          'Content-Length' => body.bytesize.to_s
        }

        [status, headers, [body]]
      end

      def call(env)
        unless authenticate(env)
          return rack_response(403, 'Invalid auth token', 'text/plain')
        end

        case env['PATH_INFO']
        when /\/stop$/
          @cli.stop
          return rack_response(200, OK_STATUS)

        when /\/halt$/
          @cli.halt
          return rack_response(200, OK_STATUS)

        when /\/restart$/
          @cli.restart
          return rack_response(200, OK_STATUS)

        when /\/phased-restart$/
          if !@cli.phased_restart
            return rack_response(404, '{ "error": "phased restart not available" }')
          else
            return rack_response(200, OK_STATUS)
          end

        when /\/reload-worker-directory$/
          if !@cli.reload_worker_directory
            return rack_response(404, '{ "error": "reload_worker_directory not available" }')
          else
            return rack_response(200, OK_STATUS)
          end

        when /\/stats$/
          return rack_response(200, @cli.stats)
        else
          rack_response 404, "Unsupported action", 'text/plain'
        end
      end
    end
  end
end

Version data entries

94 entries across 91 versions & 15 rubygems

Version Path
logstash-output-scalyr-0.1.9 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-output-scalyr-0.1.8 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-output-scalyr-0.1.7 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-output-scalyr-0.1.6 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.3.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-filter-csharp-0.2.1 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-filter-csharp-0.2.0 vendor/bundle/jruby/2.3.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-output-scalyr-0.1.5 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-output-scalyr-0.1.4 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-output-scalyr-0.1.3 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-output-scalyr-0.1.2 vendor/bundle/jruby/2.5.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-filter-device_detection-1.0.7-java vendor/bundle/jruby/1.9/gems/puma-2.16.0-java/lib/puma/app/status.rb
mrcooper-logstash-output-azuresearch-0.2.2 vendor/jruby/2.5.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-output-icinga-1.1.0 vendor/jruby/1.9/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-output-icinga-1.1.0 vendor/jruby/2.3.0/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/puma-2.16.0-java/lib/puma/app/status.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/puma-2.16.0-java/lib/puma/app/status.rb