Class: Sidekiq::Web

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/web.rb,
lib/sidekiq/web/action.rb,
lib/sidekiq/web/config.rb,
lib/sidekiq/web/router.rb,
lib/sidekiq/web/application.rb

Defined Under Namespace

Modules: Router Classes: Action, Application, Config, Route

Constant Summary collapse

ROOT =
File.expand_path("#{File.dirname(__FILE__)}/../../web")
VIEWS =
"#{ROOT}/views"
LOCALES =
["#{ROOT}/locales"]
LAYOUT =
"#{VIEWS}/layout.html.erb"
ASSETS =
"#{ROOT}/assets"
DEFAULT_TABS =
{
  "Dashboard" => "",
  "Busy" => "busy",
  "Queues" => "queues",
  "Retries" => "retries",
  "Scheduled" => "scheduled",
  "Dead" => "morgue",
  "Metrics" => "metrics",
  "Profiles" => "profiles"
}
@@config =
Sidekiq::Web::Config.new

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.app_url=(url) ⇒ Object



41
42
43
# File 'lib/sidekiq/web.rb', line 41

def app_url=(url)
  @@config.app_url = url
end

.assets_pathObject



49
# File 'lib/sidekiq/web.rb', line 49

def assets_path = @@config.assets_path

.assets_path=(path) ⇒ Object



45
46
47
# File 'lib/sidekiq/web.rb', line 45

def assets_path=(path)
  @@config.assets_path = path
end

.call(env) ⇒ Object

Allow user to say

run Sidekiq::Web

rather than:

run Sidekiq::Web.new


81
82
83
84
# File 'lib/sidekiq/web.rb', line 81

def self.call(env)
  @inst ||= new
  @inst.call(env)
end

.configureObject



33
34
35
36
37
38
39
# File 'lib/sidekiq/web.rb', line 33

def configure
  if block_given?
    yield @@config
  else
    @@config
  end
end

.custom_job_info_rowsObject



57
# File 'lib/sidekiq/web.rb', line 57

def custom_job_info_rows = @@config.custom_job_info_rows

.localesObject



53
# File 'lib/sidekiq/web.rb', line 53

def locales = @@config.locales

.middlewaresObject



67
# File 'lib/sidekiq/web.rb', line 67

def middlewares = @@config.middlewares

.redis_poolObject



59
60
61
# File 'lib/sidekiq/web.rb', line 59

def redis_pool
  @pool || Sidekiq.default_configuration.redis_pool
end

.redis_pool=(pool) ⇒ Object



63
64
65
# File 'lib/sidekiq/web.rb', line 63

def redis_pool=(pool)
  @pool = pool
end

.register(*args, **kw, &block) ⇒ Object



71
72
73
74
# File 'lib/sidekiq/web.rb', line 71

def register(*args, **kw, &block)
  Sidekiq.logger.warn { "`Sidekiq::Web.register` is deprecated, use `Sidekiq::Web.configure {|cfg| cfg.register(...) }`" }
  @@config.register(*args, **kw, &block)
end

.reset!Object

testing, internal use only



87
88
89
90
# File 'lib/sidekiq/web.rb', line 87

def self.reset!
  @@config.reset!
  @inst = nil
end

.tabsObject



51
# File 'lib/sidekiq/web.rb', line 51

def tabs = @@config.tabs

.use(*args, &block) ⇒ Object



69
# File 'lib/sidekiq/web.rb', line 69

def use(*args, &block) = @@config.middlewares << [args, block]

.viewsObject



55
# File 'lib/sidekiq/web.rb', line 55

def views = @@config.views

Instance Method Details

#appObject



99
100
101
# File 'lib/sidekiq/web.rb', line 99

def app
  @app ||= build(@@config)
end

#call(env) ⇒ Object



92
93
94
95
96
97
# File 'lib/sidekiq/web.rb', line 92

def call(env)
  env[:web_config] = Sidekiq::Web.configure
  env[:csp_nonce] = SecureRandom.hex(8)
  env[:redis_pool] = self.class.redis_pool
  safe_request?(env) ? app.call(env) : deny(env)
end

#deny(env) ⇒ Object



112
113
114
115
# File 'lib/sidekiq/web.rb', line 112

def deny(env)
  Sidekiq.logger.warn "attack prevented by #{self.class}"
  [403, {Rack::CONTENT_TYPE => "text/plain"}, ["Forbidden"]]
end

#safe_methods?(env) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/sidekiq/web.rb', line 103

def safe_methods?(env)
  %w[GET HEAD OPTIONS TRACE].include? env["REQUEST_METHOD"]
end

#safe_request?(env) ⇒ Boolean

Returns:

  • (Boolean)


107
108
109
110
# File 'lib/sidekiq/web.rb', line 107

def safe_request?(env)
  return true if safe_methods?(env)
  env["HTTP_SEC_FETCH_SITE"] == "same-origin"
end