sqreen 1.18.5 → 1.19.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +22 -0
- data/lib/sqreen/actions.rb +2 -0
- data/lib/sqreen/actions/actions_index.rb +16 -0
- data/lib/sqreen/actions/base.rb +4 -10
- data/lib/sqreen/actions/block_ip.rb +2 -0
- data/lib/sqreen/actions/block_user.rb +2 -0
- data/lib/sqreen/actions/ip_range_indexed_action_class.rb +4 -24
- data/lib/sqreen/actions/ip_ranges_index.rb +32 -11
- data/lib/sqreen/actions/redirect_ip.rb +2 -0
- data/lib/sqreen/actions/redirect_user.rb +2 -0
- data/lib/sqreen/actions/repository.rb +27 -8
- data/lib/sqreen/actions/unknown_action_type.rb +4 -0
- data/lib/sqreen/actions/user_action_class.rb +5 -30
- data/lib/sqreen/actions/users_index.rb +35 -0
- data/lib/sqreen/agent.rb +2 -1
- data/lib/sqreen/attack_blocked.rb +2 -0
- data/lib/sqreen/backport.rb +2 -0
- data/lib/sqreen/backport/clock_gettime.rb +74 -0
- data/lib/sqreen/backport/original_name.rb +2 -0
- data/lib/sqreen/binding_accessor.rb +2 -0
- data/lib/sqreen/binding_accessor/path_elem.rb +2 -0
- data/lib/sqreen/binding_accessor/transforms.rb +8 -1
- data/lib/sqreen/call_countable.rb +2 -0
- data/lib/sqreen/capped_queue.rb +2 -0
- data/lib/sqreen/cb.rb +2 -0
- data/lib/sqreen/cb_tree.rb +2 -0
- data/lib/sqreen/condition_evaluator.rb +2 -0
- data/lib/sqreen/conditionable.rb +2 -0
- data/lib/sqreen/configuration.rb +14 -0
- data/lib/sqreen/context.rb +2 -0
- data/lib/sqreen/default_cb.rb +2 -0
- data/lib/sqreen/deferred_logger.rb +2 -0
- data/lib/sqreen/deliveries.rb +2 -0
- data/lib/sqreen/deliveries/batch.rb +2 -0
- data/lib/sqreen/deliveries/simple.rb +2 -0
- data/lib/sqreen/dependency.rb +3 -1
- data/lib/sqreen/dependency/detector.rb +22 -14
- data/lib/sqreen/dependency/libsqreen.rb +4 -0
- data/lib/sqreen/dependency/new_relic.rb +2 -0
- data/lib/sqreen/dependency/rack.rb +10 -5
- data/lib/sqreen/dependency/rails.rb +4 -0
- data/lib/sqreen/dependency/sentry.rb +2 -0
- data/lib/sqreen/dependency/sinatra.rb +12 -1
- data/lib/sqreen/encoding_sanitizer.rb +2 -0
- data/lib/sqreen/error_handling_middleware.rb +2 -0
- data/lib/sqreen/event.rb +2 -0
- data/lib/sqreen/events/attack.rb +2 -0
- data/lib/sqreen/events/remote_exception.rb +2 -0
- data/lib/sqreen/events/request_record.rb +2 -0
- data/lib/sqreen/exception.rb +2 -0
- data/lib/sqreen/formatter_with_tid.rb +2 -0
- data/lib/sqreen/framework_cb.rb +2 -0
- data/lib/sqreen/frameworks.rb +2 -0
- data/lib/sqreen/frameworks/generic.rb +2 -0
- data/lib/sqreen/frameworks/rails.rb +1 -0
- data/lib/sqreen/frameworks/rails3.rb +2 -0
- data/lib/sqreen/frameworks/request_recorder.rb +2 -0
- data/lib/sqreen/frameworks/sinatra.rb +2 -0
- data/lib/sqreen/frameworks/sqreen_test.rb +2 -0
- data/lib/sqreen/graft.rb +12 -0
- data/lib/sqreen/graft/call.rb +150 -0
- data/lib/sqreen/{dependency → graft}/callback.rb +12 -4
- data/lib/sqreen/graft/hook.rb +316 -0
- data/lib/sqreen/{dependency → graft}/hook_point.rb +152 -33
- data/lib/sqreen/graft/hook_point_error.rb +10 -0
- data/lib/sqreen/invalid_signature_exception.rb +2 -0
- data/lib/sqreen/js.rb +2 -0
- data/lib/sqreen/js/call_context.rb +2 -0
- data/lib/sqreen/js/context_pool.rb +2 -0
- data/lib/sqreen/js/exec_js_runnable.rb +2 -0
- data/lib/sqreen/js/execjs_adapter.rb +2 -0
- data/lib/sqreen/js/executable_js.rb +2 -0
- data/lib/sqreen/js/js_service.rb +2 -0
- data/lib/sqreen/js/js_service_adapter.rb +2 -0
- data/lib/sqreen/js/mini_racer_adapter.rb +2 -0
- data/lib/sqreen/js/mini_racer_executable_js.rb +2 -0
- data/lib/sqreen/js/thread_local_exec_js_runnable.rb +2 -0
- data/lib/sqreen/legacy.rb +8 -0
- data/lib/sqreen/{instrumentation.rb → legacy/instrumentation.rb} +31 -2
- data/lib/sqreen/log.rb +2 -0
- data/lib/sqreen/log/loggable.rb +28 -0
- data/lib/sqreen/logger.rb +2 -0
- data/lib/sqreen/metrics.rb +2 -0
- data/lib/sqreen/metrics/average.rb +2 -0
- data/lib/sqreen/metrics/base.rb +2 -0
- data/lib/sqreen/metrics/binning.rb +2 -0
- data/lib/sqreen/metrics/collect.rb +2 -0
- data/lib/sqreen/metrics/sum.rb +2 -0
- data/lib/sqreen/metrics_store.rb +2 -0
- data/lib/sqreen/metrics_store/already_registered_metric.rb +2 -0
- data/lib/sqreen/metrics_store/unknown_metric.rb +2 -0
- data/lib/sqreen/metrics_store/unregistered_metric.rb +2 -0
- data/lib/sqreen/middleware.rb +2 -0
- data/lib/sqreen/mono_time.rb +2 -0
- data/lib/sqreen/node.rb +2 -0
- data/lib/sqreen/not_implemented_yet.rb +2 -0
- data/lib/sqreen/null_logger.rb +2 -0
- data/lib/sqreen/payload_creator.rb +2 -0
- data/lib/sqreen/payload_creator/header_section.rb +2 -0
- data/lib/sqreen/performance_notifications.rb +2 -0
- data/lib/sqreen/performance_notifications/binned_metrics.rb +2 -0
- data/lib/sqreen/performance_notifications/log.rb +2 -0
- data/lib/sqreen/performance_notifications/log_performance.rb +2 -0
- data/lib/sqreen/performance_notifications/metrics.rb +2 -0
- data/lib/sqreen/performance_notifications/newrelic.rb +2 -0
- data/lib/sqreen/prefix.rb +2 -0
- data/lib/sqreen/rails_middleware.rb +2 -0
- data/lib/sqreen/remote_command.rb +2 -0
- data/lib/sqreen/remote_command/failure_output.rb +5 -0
- data/lib/sqreen/rules.rb +2 -0
- data/lib/sqreen/rules/attrs.rb +2 -0
- data/lib/sqreen/rules/auth_track_cb.rb +2 -0
- data/lib/sqreen/rules/binding_accessor_matcher_cb.rb +2 -0
- data/lib/sqreen/rules/binding_accessor_metrics.rb +2 -0
- data/lib/sqreen/rules/blacklist_ips_cb.rb +2 -0
- data/lib/sqreen/rules/count_http_codes.rb +2 -0
- data/lib/sqreen/rules/crawler_user_agent_matches_cb.rb +2 -0
- data/lib/sqreen/rules/crawler_user_agent_matches_metrics_cb.rb +2 -0
- data/lib/sqreen/rules/custom_error_cb.rb +2 -0
- data/lib/sqreen/rules/devise_auth_track_cb.rb +2 -0
- data/lib/sqreen/rules/devise_signup_track_cb.rb +2 -0
- data/lib/sqreen/rules/execjs_cb.rb +2 -0
- data/lib/sqreen/rules/headers_insert_cb.rb +7 -0
- data/lib/sqreen/rules/matcher_rule.rb +2 -0
- data/lib/sqreen/rules/not_found_cb.rb +7 -0
- data/lib/sqreen/rules/rails_parameters_cb.rb +2 -0
- data/lib/sqreen/rules/record_request_context.rb +2 -0
- data/lib/sqreen/rules/regexp_rule_cb.rb +2 -0
- data/lib/sqreen/rules/rule_cb.rb +2 -0
- data/lib/sqreen/rules/run_req_start_actions.rb +3 -1
- data/lib/sqreen/rules/run_user_actions.rb +3 -1
- data/lib/sqreen/rules/shell_env_cb.rb +2 -0
- data/lib/sqreen/rules/signup_track_cb.rb +2 -0
- data/lib/sqreen/rules/update_request_context.rb +2 -0
- data/lib/sqreen/rules/url_matches_cb.rb +2 -0
- data/lib/sqreen/rules/user_agent_matches_cb.rb +2 -0
- data/lib/sqreen/rules/waf_cb.rb +28 -5
- data/lib/sqreen/rules/xss_cb.rb +2 -0
- data/lib/sqreen/run_when_called_cb.rb +2 -0
- data/lib/sqreen/runner.rb +25 -7
- data/lib/sqreen/runtime_infos.rb +2 -0
- data/lib/sqreen/safe_json.rb +2 -0
- data/lib/sqreen/sdk.rb +4 -0
- data/lib/sqreen/sensitive_data_redactor.rb +2 -0
- data/lib/sqreen/serializer.rb +2 -0
- data/lib/sqreen/session.rb +2 -0
- data/lib/sqreen/shared_storage.rb +2 -0
- data/lib/sqreen/shared_storage23.rb +2 -0
- data/lib/sqreen/shrink_wrap.rb +16 -0
- data/lib/sqreen/signature_verifier.rb +2 -0
- data/lib/sqreen/sinatra_middleware.rb +2 -0
- data/lib/sqreen/sqreen_signed_verifier.rb +2 -0
- data/lib/sqreen/token_invalid_exception.rb +2 -0
- data/lib/sqreen/token_not_found_exception.rb +2 -0
- data/lib/sqreen/trie.rb +2 -0
- data/lib/sqreen/unauthorized.rb +2 -0
- data/lib/sqreen/util.rb +5 -0
- data/lib/sqreen/util/capped_array.rb +2 -0
- data/lib/sqreen/util/capped_hash.rb +2 -0
- data/lib/sqreen/util/capped_string.rb +2 -0
- data/lib/sqreen/util/capper.rb +2 -0
- data/lib/sqreen/version.rb +3 -1
- data/lib/sqreen/waf_error.rb +2 -0
- data/lib/sqreen/weave.rb +12 -0
- data/lib/sqreen/weave/hardcoded.rb +19 -0
- data/lib/sqreen/weave/instrumentor.rb +48 -0
- data/lib/sqreen/weave/legacy.rb +12 -0
- data/lib/sqreen/weave/legacy/instrumentation.rb +406 -0
- data/lib/sqreen/web_server.rb +2 -0
- data/lib/sqreen/web_server/generic.rb +2 -0
- data/lib/sqreen/web_server/passenger.rb +2 -0
- data/lib/sqreen/web_server/puma.rb +2 -0
- data/lib/sqreen/web_server/rainbows.rb +2 -0
- data/lib/sqreen/web_server/thin.rb +2 -0
- data/lib/sqreen/web_server/unicorn.rb +2 -0
- data/lib/sqreen/web_server/webrick.rb +2 -0
- data/lib/sqreen/worker.rb +2 -0
- metadata +28 -9
- data/lib/sqreen/dependency/hook.rb +0 -102
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 315d183f0c86adad0c106a7f3a9b31ae5049c387233b78e1df3d3ec5e93db21d
|
4
|
+
data.tar.gz: 75b7d65ba2dd9ac049f7a81f6d60c5c96b67d2a7fb453f8e3a181b07035542ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2358bca4465a486e04b5454f44a03244e980f1b59e5118bc8aaa6ddb57030cdcf73507949a796cdbbd9d8bc91ca1cf6028e9a12a7a61faceb1250ffca062a73
|
7
|
+
data.tar.gz: d126dbefe095bd988e378dbacdee915e0e0de6c5cce4c0865b988816df20f71b2552b52087779792537071ff7c2757f868899c2aa93671813caf02e7795ed7cc
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
## 1.19.2
|
2
|
+
|
3
|
+
* Handle unexpected rule callback return values more gracefully
|
4
|
+
* Fix incorrect return value for 404 native callback
|
5
|
+
|
6
|
+
## 1.19.1
|
7
|
+
|
8
|
+
* Fix LocalJumpError when reaching a Rack app nested in a Rails app
|
9
|
+
|
10
|
+
## 1.19.0
|
11
|
+
|
12
|
+
* Upgrade WAF features via libsqreen 0.6.1
|
13
|
+
* Improve time defensiveness in WAF
|
14
|
+
* Improve compatibility with APM agents via a new optional instrumentation engine
|
15
|
+
* Fix action reloading not being entirely cleared on reload
|
16
|
+
* Improve handling of hash symbol keys in some security rules
|
17
|
+
* Fix constant resolution scope on agent boot
|
18
|
+
|
19
|
+
## 1.18.6
|
20
|
+
|
21
|
+
* Improve default WAF time budget handling logic
|
22
|
+
|
1
23
|
## 1.18.5
|
2
24
|
|
3
25
|
* Fix type mismatch in WAF time budget handling
|
data/lib/sqreen/actions.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
# typed: true
|
2
|
+
module Sqreen
|
3
|
+
module Actions
|
4
|
+
# documents the operations an actions index should implement
|
5
|
+
class ActionsIndex
|
6
|
+
# all actions matching, possibly already expired
|
7
|
+
def actions_matching(_key)
|
8
|
+
raise 'implement in subclasses'
|
9
|
+
end
|
10
|
+
|
11
|
+
def index(_params, _action)
|
12
|
+
raise 'implement in subclasses'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/lib/sqreen/actions/base.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
# typed: false
|
2
|
+
|
1
3
|
# Copyright (c) 2015 Sqreen. All Rights Reserved.
|
2
4
|
# Please refer to our terms for more information: https://www.sqreen.com/terms.html
|
3
5
|
|
4
6
|
# TODO: remove class vars
|
5
7
|
|
8
|
+
require 'sqreen/sdk'
|
6
9
|
require 'sqreen/exception'
|
7
10
|
|
8
11
|
module Sqreen
|
@@ -75,16 +78,7 @@ module Sqreen
|
|
75
78
|
subclasses.keys
|
76
79
|
end
|
77
80
|
|
78
|
-
|
79
|
-
def actions_matching(_key)
|
80
|
-
raise 'implement in singletons of subclasses'
|
81
|
-
end
|
82
|
-
|
83
|
-
def index(_params, _action)
|
84
|
-
raise 'implement in singletons of subclasses'
|
85
|
-
end
|
86
|
-
|
87
|
-
def clear
|
81
|
+
def new_index
|
88
82
|
raise 'implement in singletons of subclasses'
|
89
83
|
end
|
90
84
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
# Copyright (c) 2015 Sqreen. All Rights Reserved.
|
2
4
|
# Please refer to our terms for more information: https://www.sqreen.com/terms.html
|
3
5
|
|
@@ -6,30 +8,8 @@ require 'sqreen/actions/ip_ranges_index'
|
|
6
8
|
module Sqreen
|
7
9
|
module Actions
|
8
10
|
module IpRangeIndexedActionClass
|
9
|
-
|
10
|
-
|
11
|
-
def actions_matching(client_ip)
|
12
|
-
matching_actions client_ip
|
13
|
-
end
|
14
|
-
|
15
|
-
def index(params, action)
|
16
|
-
ranges = parse_ip_ranges params
|
17
|
-
|
18
|
-
ranges.each do |r|
|
19
|
-
add_prefix r, action
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
# returns array of prefixes in string form
|
26
|
-
def parse_ip_ranges(params)
|
27
|
-
ranges = params['ip_cidr']
|
28
|
-
unless ranges && ranges.is_a?(Array) && !ranges.empty?
|
29
|
-
raise 'no non-empty ip_cidr array present'
|
30
|
-
end
|
31
|
-
|
32
|
-
ranges
|
11
|
+
def new_index
|
12
|
+
IpRangesIndex.new
|
33
13
|
end
|
34
14
|
end
|
35
15
|
end
|
@@ -1,22 +1,30 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
# Copyright (c) 2015 Sqreen. All Rights Reserved.
|
2
4
|
# Please refer to our terms for more information: https://www.sqreen.com/terms.html
|
3
5
|
|
4
6
|
require 'ipaddr'
|
7
|
+
require 'sqreen/actions/actions_index'
|
5
8
|
require 'sqreen/trie'
|
6
9
|
require 'sqreen/prefix'
|
7
10
|
|
8
11
|
module Sqreen
|
9
12
|
module Actions
|
10
|
-
|
11
|
-
def
|
12
|
-
@trie_v4
|
13
|
-
@trie_v6
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
class IpRangesIndex < ActionsIndex
|
14
|
+
def initialize
|
15
|
+
@trie_v4 = Sqreen::Trie.new
|
16
|
+
@trie_v6 = Sqreen::Trie.new(nil, nil, Socket::AF_INET6)
|
17
|
+
end
|
18
|
+
|
19
|
+
def index(params, action)
|
20
|
+
ranges = parse_ip_ranges params
|
21
|
+
|
22
|
+
ranges.each do |r|
|
23
|
+
add_prefix r, action
|
24
|
+
end
|
17
25
|
end
|
18
26
|
|
19
|
-
def
|
27
|
+
def actions_matching(client_ip)
|
20
28
|
parsed_ip = IPAddr.new(client_ip.gsub(/%[^%\/]+/, ''))
|
21
29
|
trie = parsed_ip.family == Socket::AF_INET6 ? @trie_v6 : @trie_v4
|
22
30
|
return [] unless trie
|
@@ -27,9 +35,22 @@ module Sqreen
|
|
27
35
|
found.map(&:data)
|
28
36
|
end
|
29
37
|
|
30
|
-
|
31
|
-
|
32
|
-
|
38
|
+
private
|
39
|
+
|
40
|
+
# returns array of prefixes in string form
|
41
|
+
def parse_ip_ranges(params)
|
42
|
+
ranges = params['ip_cidr']
|
43
|
+
unless ranges && ranges.is_a?(Array) && !ranges.empty?
|
44
|
+
raise 'no non-empty ip_cidr array present'
|
45
|
+
end
|
46
|
+
|
47
|
+
ranges
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_prefix(prefix_str, data)
|
51
|
+
prefix = Sqreen::Prefix.from_str(prefix_str, data)
|
52
|
+
trie = prefix.family == Socket::AF_INET6 ? @trie_v6 : @trie_v4
|
53
|
+
trie.insert prefix
|
33
54
|
end
|
34
55
|
end
|
35
56
|
end
|
@@ -1,24 +1,43 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
# Copyright (c) 2015 Sqreen. All Rights Reserved.
|
2
4
|
# Please refer to our terms for more information: https://www.sqreen.com/terms.html
|
3
5
|
|
4
6
|
module Sqreen
|
5
7
|
module Actions
|
6
|
-
# Where the
|
8
|
+
# Where the actions are stored
|
9
|
+
# The current ones are stored in Repository.current
|
7
10
|
class Repository
|
8
|
-
|
11
|
+
def initialize
|
12
|
+
@indexes = Hash[Base.known_subclasses.map do |clazz|
|
13
|
+
[clazz.type_name, clazz.new_index]
|
14
|
+
end]
|
15
|
+
end
|
9
16
|
|
10
17
|
def add(params, action)
|
11
|
-
action.class.index(params || {}, action)
|
18
|
+
@indexes[action.class.type_name].index(params || {}, action)
|
12
19
|
end
|
13
20
|
|
14
|
-
|
15
|
-
|
16
|
-
|
21
|
+
# type is either a class or a type name
|
22
|
+
def get(type, key)
|
23
|
+
type = type.type_name if type.class == Class
|
24
|
+
@indexes[type].actions_matching key
|
17
25
|
end
|
18
26
|
|
19
|
-
|
20
|
-
|
27
|
+
singleton_class.class_eval do
|
28
|
+
attr_reader :current
|
29
|
+
def current=(new_inst)
|
30
|
+
raise 'nil is unacceptable' if new_inst.nil?
|
31
|
+
@current = new_inst
|
32
|
+
end
|
33
|
+
|
34
|
+
def clear
|
35
|
+
self.current = Repository.new
|
36
|
+
end
|
21
37
|
end
|
38
|
+
|
39
|
+
# initialize current to empty repository
|
40
|
+
clear
|
22
41
|
end
|
23
42
|
end
|
24
43
|
end
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
# Copyright (c) 2015 Sqreen. All Rights Reserved.
|
2
4
|
# Please refer to our terms for more information: https://www.sqreen.com/terms.html
|
3
5
|
|
6
|
+
require 'sqreen/exception'
|
7
|
+
|
4
8
|
module Sqreen
|
5
9
|
# Implements actions (behavior taken in response to agent signals)
|
6
10
|
module Actions
|
@@ -1,40 +1,15 @@
|
|
1
|
+
# typed: true
|
2
|
+
|
1
3
|
# Copyright (c) 2015 Sqreen. All Rights Reserved.
|
2
4
|
# Please refer to our terms for more information: https://www.sqreen.com/terms.html
|
3
5
|
|
4
|
-
require 'sqreen/
|
6
|
+
require 'sqreen/actions/users_index'
|
5
7
|
|
6
8
|
module Sqreen
|
7
9
|
module Actions
|
8
10
|
module UserActionClass
|
9
|
-
def
|
10
|
-
|
11
|
-
key = stringify_keys(identity_params)
|
12
|
-
actions = @idx[key]
|
13
|
-
actions || []
|
14
|
-
end
|
15
|
-
|
16
|
-
def index(params, action)
|
17
|
-
@idx ||= {}
|
18
|
-
users = params['users']
|
19
|
-
raise ::Sqreen::Exception, 'nil "users" param for block_user action' if users.nil?
|
20
|
-
raise ::Sqreen::Exception, '"users" param must be an array' unless users.is_a? Array
|
21
|
-
|
22
|
-
users.each do |u|
|
23
|
-
@idx[u] ||= []
|
24
|
-
@idx[u] << action
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def clear
|
29
|
-
@idx = {}
|
30
|
-
end
|
31
|
-
|
32
|
-
private
|
33
|
-
|
34
|
-
def stringify_keys(hash)
|
35
|
-
Hash[
|
36
|
-
hash.map { |k, v| [k.to_s, v] }
|
37
|
-
]
|
11
|
+
def new_index
|
12
|
+
UsersIndex.new
|
38
13
|
end
|
39
14
|
end
|
40
15
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# typed: true
|
2
|
+
require 'sqreen/actions/actions_index'
|
3
|
+
|
4
|
+
module Sqreen
|
5
|
+
module Actions
|
6
|
+
class UsersIndex < ActionsIndex
|
7
|
+
def actions_matching(identity_params)
|
8
|
+
return [] unless @idx
|
9
|
+
key = stringify_keys(identity_params)
|
10
|
+
actions = @idx[key]
|
11
|
+
actions || []
|
12
|
+
end
|
13
|
+
|
14
|
+
def index(params, action)
|
15
|
+
@idx ||= {}
|
16
|
+
users = params['users']
|
17
|
+
raise ::Sqreen::Exception, 'nil "users" param for block_user action' if users.nil?
|
18
|
+
raise ::Sqreen::Exception, '"users" param must be an array' unless users.is_a? Array
|
19
|
+
|
20
|
+
users.each do |u|
|
21
|
+
@idx[u] ||= []
|
22
|
+
@idx[u] << action
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def stringify_keys(hash)
|
29
|
+
Hash[
|
30
|
+
hash.map { |k, v| [k.to_s, v] }
|
31
|
+
]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/sqreen/agent.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
|
+
# typed: ignore
|
2
|
+
|
1
3
|
# Copyright (c) 2015 Sqreen. All Rights Reserved.
|
2
4
|
# Please refer to our terms for more information: https://www.sqreen.com/terms.html
|
3
5
|
|
4
6
|
require 'sqreen/version'
|
5
|
-
require 'sqreen/instrumentation'
|
6
7
|
require 'sqreen/session'
|
7
8
|
require 'sqreen/runner'
|
8
9
|
require 'sqreen/log'
|
data/lib/sqreen/backport.rb
CHANGED
@@ -0,0 +1,74 @@
|
|
1
|
+
# typed: ignore
|
2
|
+
|
3
|
+
# Copyright (c) 2015 Sqreen. All Rights Reserved.
|
4
|
+
# Please refer to our terms for more information: https://www.sqreen.com/terms.html
|
5
|
+
|
6
|
+
require 'sqreen/backport'
|
7
|
+
|
8
|
+
module Sqreen
|
9
|
+
module Backport
|
10
|
+
module ClockGettime
|
11
|
+
class << self
|
12
|
+
def supported?
|
13
|
+
Process.respond_to?(:clock_gettime)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
unless supported?
|
18
|
+
require 'ffi'
|
19
|
+
|
20
|
+
class Timespec < FFI::Struct
|
21
|
+
layout :tv_sec => :time_t, :tv_nsec => :long
|
22
|
+
end
|
23
|
+
|
24
|
+
module LibC
|
25
|
+
extend FFI::Library
|
26
|
+
ffi_lib FFI::Library::LIBC
|
27
|
+
|
28
|
+
# TODO: FFI::NotFoundError
|
29
|
+
|
30
|
+
if RUBY_PLATFORM =~ /darwin/
|
31
|
+
attach_function :mach_absolute_time, [], :uint64
|
32
|
+
end
|
33
|
+
|
34
|
+
attach_function :clock_gettime, [:int, :pointer], :int
|
35
|
+
end
|
36
|
+
|
37
|
+
module Constants
|
38
|
+
case RUBY_PLATFORM
|
39
|
+
when /darwin/
|
40
|
+
CLOCK_REALTIME = 0
|
41
|
+
CLOCK_MONOTONIC = 6
|
42
|
+
CLOCK_PROCESS_CPUTIME_ID = 12
|
43
|
+
CLOCK_THERAD_CPUTIME_ID = 16
|
44
|
+
when /linux/
|
45
|
+
CLOCK_REALTIME = 0
|
46
|
+
CLOCK_MONOTONIC = 1
|
47
|
+
CLOCK_PROCESS_CPUTIME_ID = 2
|
48
|
+
CLOCK_THREAD_CPUTIME_ID = 3
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def clock_gettime(clock_id, unit = :float_second)
|
53
|
+
unless unit == :float_second
|
54
|
+
raise "Process.clock_gettime: unsupported unit #{unit.inspect}"
|
55
|
+
end
|
56
|
+
|
57
|
+
t = Timespec.new
|
58
|
+
ret = LibC.clock_gettime(clock_id, t.pointer)
|
59
|
+
|
60
|
+
raise SystemCallError, "Errno #{FFI.errno}" if ret == -1
|
61
|
+
|
62
|
+
t[:tv_sec].to_f + t[:tv_nsec].to_f / 1_000_000_000
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
unless Sqreen::Backport::ClockGettime.supported?
|
70
|
+
Process.instance_eval do
|
71
|
+
extend Sqreen::Backport::ClockGettime
|
72
|
+
include Sqreen::Backport::ClockGettime::Constants
|
73
|
+
end
|
74
|
+
end
|