castle-rb 9.0.0 → 9.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '085ac2cdd6ebd7b69ab9171c72009c3f3d792c3d21d55b93d914abd93425098d'
4
- data.tar.gz: c31f5076e77d08c27d06b7722558b816a56868a51e7a2f885b9fc9236fc50615
3
+ metadata.gz: 93980c047867e58e332b7503edfb243e157de612024a137e7e8fe2f6cd69b0ab
4
+ data.tar.gz: 487754c292626984bb233f67c88b0101aba4a206dfa7ab738f7e042799be59cf
5
5
  SHA512:
6
- metadata.gz: ecf515a3a5ff3a264a749171a6507d1c03635415359a392b8daafbf1e57291749e509501d449c902b1811903688a2499b7b845bc9cf27d167faa8412cb3ff40e
7
- data.tar.gz: 125266f1b4875f105b024b4bef5baf38175af1741e53c35cfe66ab7051dceb6adb76dda87b330ccdd48b06fc30bd4434283868e8be4de540752fbbbe06028ff9
6
+ metadata.gz: 42b66ed4b557d084bbfbb0b15b69793811c35e87e642b0a07de4aee9c8c0379732747aa9bd8a4890ff34a0420926f280d7d44044f09347e4078b9d65af6c9630
7
+ data.tar.gz: f15c06bfdcc644c419ff45fa6777c11ddae889a1be42d3b2c88665ce45b08acb71474c182b6524b6d70aa3777349733753fda516bd2215f63ca337bdf7daf102
data/CHANGELOG.md CHANGED
@@ -1,7 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 9.2.0
4
+
5
+ **Changes:**
6
+
7
+ - Slim down the default request context to `headers`, `ip` and `library`; the remaining data is already available via `headers`.
8
+ - Remove the internal `Castle::ClientId::Extract` service and the now-unused `cookies` plumbing in `Castle::Context::GetDefault`.
9
+ - No longer read the API secret from the `CASTLE_API_SECRET` environment variable automatically; set `Castle.api_secret` explicitly (for example `Castle.api_secret = ENV.fetch('CASTLE_API_SECRET')`).
10
+
11
+ ## 9.1.0
12
+
13
+ **Enhancements:**
14
+
15
+ - Add Events API support (enterprise) — three new client methods for querying event data:
16
+ - `events_schema` — `GET /v1/events/schema`
17
+ - `query_events` — `POST /v1/events/query`
18
+ - `group_events` — `POST /v1/events/group`
19
+
20
+ **Housekeeping:**
21
+
22
+ - Remove unused `Castle::Validators::NotSupported` (dead code)
23
+ - Remove unused `Session::HTTPS_SCHEME` constant; inline the comparison in `GetConnection`
24
+ - Replace deprecated `:mingw, :x64_mingw` Bundler platforms with `:windows`
25
+ - Bump Bundler 2.6.9 → 2.7.2
26
+ - Bump json 2.19.5 → 2.19.7
27
+
3
28
  ## master
4
29
 
30
+ - Bump dependencies (rack 3.1.19 → 3.2.6, rake, rspec-\*, timecop, simplecov-html, diff-lcs)
31
+ - Bump Ruby to 3.4.9 (zlib CVE-2026-27820)
32
+ - Bump Node.js to 24.16.0 in `.tool-versions`
33
+ - Repair `yarn format:check`: add `syntax_tree` to the dev group (required by `@prettier/plugin-ruby` 4.x), reformat 11 spec files, and disable rubocop cops that conflict with prettier-ruby (`Layout/SpaceInsideHashLiteralBraces`, `Style/EmptyMethod`)
34
+
5
35
  ## 9.0.0
6
36
 
7
37
  **BREAKING CHANGES:**
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module Events
6
+ # Sends POST /events/group request
7
+ module Group
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::Events::Group.build(options), {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module Events
6
+ # Sends POST /events/query request
7
+ module Query
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::Events::Query.build(options), {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module API
5
+ module Events
6
+ # Sends GET /events/schema request
7
+ module Schema
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Hash]
11
+ def call(options = {})
12
+ options = Castle::Utils::DeepSymbolizeKeys.call(options || {})
13
+ http = options.delete(:http)
14
+ config = options.delete(:config) || Castle.config
15
+
16
+ Castle::API.call(Castle::Commands::Events::Schema.build(options), {}, http, config)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
data/lib/castle/client.rb CHANGED
@@ -3,6 +3,7 @@
3
3
  module Castle
4
4
  # Castle's client.
5
5
  class Client
6
+ include Castle::ClientActions::Events
6
7
  include Castle::ClientActions::ListItems
7
8
  include Castle::ClientActions::Lists
8
9
  include Castle::ClientActions::Privacy
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module ClientActions
5
+ # Client actions for the Events API
6
+ module Events
7
+ # @param options [Hash]
8
+ def events_schema(options = {})
9
+ Castle::API::Events::Schema.call(options)
10
+ end
11
+
12
+ # @param options [Hash]
13
+ def query_events(options = {})
14
+ Castle::API::Events::Query.call(options)
15
+ end
16
+
17
+ # @param options [Hash]
18
+ def group_events(options = {})
19
+ Castle::API::Events::Group.call(options)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module Commands
5
+ module Events
6
+ # Builds the command to query aggregated events
7
+ class Group
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Castle::Command]
11
+ def build(options = {})
12
+ options[:filters]&.each { |f| Castle::Validators::Present.call(f, %i[field op value]) }
13
+ Castle::Validators::Present.call(options[:sort], %i[field order]) if options[:sort]
14
+
15
+ Castle::Command.new('events/group', options, :post)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module Commands
5
+ module Events
6
+ # Builds the command to query raw events
7
+ class Query
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Castle::Command]
11
+ def build(options = {})
12
+ options[:filters]&.each { |f| Castle::Validators::Present.call(f, %i[field op value]) }
13
+ Castle::Validators::Present.call(options[:sort], %i[field order]) if options[:sort]
14
+
15
+ Castle::Command.new('events/query', options, :post)
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Castle
4
+ module Commands
5
+ module Events
6
+ # Builds the command to get the events schema
7
+ class Schema
8
+ class << self
9
+ # @param options [Hash]
10
+ # @return [Castle::Command]
11
+ def build(_options = {})
12
+ Castle::Command.new('events/schema', nil, :get)
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -69,7 +69,7 @@ module Castle
69
69
  self.base_url = BASE_URL
70
70
  self.allowlisted = [].freeze
71
71
  self.denylisted = [].freeze
72
- self.api_secret = ENV.fetch('CASTLE_API_SECRET', '')
72
+ self.api_secret = ''
73
73
  self.ip_headers = [].freeze
74
74
  self.trusted_proxies = [].freeze
75
75
  self.trust_proxy_chain = false
@@ -3,50 +3,21 @@
3
3
  module Castle
4
4
  module Context
5
5
  class GetDefault
6
- def initialize(request, cookies = nil)
6
+ def initialize(request)
7
7
  @pre_headers = Castle::Headers::Filter.new(request).call
8
- @cookies = cookies || request.cookies
9
- @request = request
10
8
  end
11
9
 
12
10
  def call
13
- {
14
- client_id: client_id,
15
- active: true,
16
- headers: headers,
17
- ip: ip,
18
- library: {
19
- name: 'castle-rb',
20
- version: Castle::VERSION
21
- }
22
- }.tap do |result|
23
- result[:locale] = locale if locale
24
- result[:user_agent] = user_agent if user_agent
25
- end
11
+ { headers: headers, ip: ip, library: { name: 'castle-rb', version: Castle::VERSION } }
26
12
  end
27
13
 
28
14
  private
29
15
 
30
- # @return [String]
31
- def locale
32
- @pre_headers['Accept-Language']
33
- end
34
-
35
- # @return [String]
36
- def user_agent
37
- @pre_headers['User-Agent']
38
- end
39
-
40
16
  # @return [String]
41
17
  def ip
42
18
  Castle::IPs::Extract.new(@pre_headers).call
43
19
  end
44
20
 
45
- # @return [String]
46
- def client_id
47
- Castle::ClientId::Extract.new(@pre_headers, @cookies).call
48
- end
49
-
50
21
  # formatted and filtered headers
51
22
  # @return [Hash]
52
23
  def headers
@@ -9,7 +9,7 @@ module Castle
9
9
  # @param options [Hash]
10
10
  # @return [Hash]
11
11
  def call(request, options = {})
12
- default_context = Castle::Context::GetDefault.new(request, options[:cookies]).call
12
+ default_context = Castle::Context::GetDefault.new(request).call
13
13
  Castle::Context::Merge.call(default_context, options[:context])
14
14
  end
15
15
  end
@@ -4,8 +4,6 @@ module Castle
4
4
  module Core
5
5
  # this module returns a new configured Net::HTTP object
6
6
  module GetConnection
7
- HTTPS_SCHEME = 'https'
8
-
9
7
  class << self
10
8
  # @param config [Castle::Configuration, Castle::SingletonConfiguration]
11
9
  # @return [Net::HTTP]
@@ -18,7 +16,7 @@ module Castle
18
16
  http.open_timeout = timeout_seconds
19
17
  http.read_timeout = timeout_seconds
20
18
 
21
- if config.base_url.scheme == HTTPS_SCHEME
19
+ if config.base_url.scheme == 'https'
22
20
  http.use_ssl = true
23
21
  http.verify_mode = OpenSSL::SSL::VERIFY_PEER
24
22
  end
@@ -5,8 +5,6 @@ module Castle
5
5
  # and provides start method for persistent connection usage
6
6
  # when there is a need of sending multiple requests at once
7
7
  module Session
8
- HTTPS_SCHEME = 'https'
9
-
10
8
  class << self
11
9
  def call(&block)
12
10
  return unless block
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Castle
4
- VERSION = '9.0.0'
4
+ VERSION = '9.2.0'
5
5
  end
data/lib/castle.rb CHANGED
@@ -14,7 +14,6 @@
14
14
  castle/utils/get_timestamp
15
15
  castle/utils/secure_compare
16
16
  castle/validators/present
17
- castle/validators/not_supported
18
17
  castle/webhooks/verify
19
18
  castle/context/merge
20
19
  castle/context/sanitize
@@ -37,6 +36,9 @@
37
36
  castle/commands/list_items/query
38
37
  castle/commands/list_items/unarchive
39
38
  castle/commands/list_items/update
39
+ castle/commands/events/schema
40
+ castle/commands/events/query
41
+ castle/commands/events/group
40
42
  castle/commands/privacy/request_data
41
43
  castle/commands/privacy/delete_data
42
44
  castle/api/filter
@@ -56,6 +58,9 @@
56
58
  castle/api/list_items/query
57
59
  castle/api/list_items/unarchive
58
60
  castle/api/list_items/update
61
+ castle/api/events/schema
62
+ castle/api/events/query
63
+ castle/api/events/group
59
64
  castle/api/privacy/request_data
60
65
  castle/api/privacy/delete_data
61
66
  castle/payload/prepare
@@ -64,6 +69,7 @@
64
69
  castle/logger
65
70
  castle/failover/prepare_response
66
71
  castle/failover/strategy
72
+ castle/client_actions/events
67
73
  castle/client_actions/lists
68
74
  castle/client_actions/list_items
69
75
  castle/client_actions/privacy
@@ -72,7 +78,6 @@
72
78
  castle/headers/format
73
79
  castle/headers/extract
74
80
  castle/secure_mode
75
- castle/client_id/extract
76
81
  castle/ips/extract
77
82
  castle/core/get_connection
78
83
  castle/core/process_response
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: castle-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.0.0
4
+ version: 9.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johan Brissmyr
@@ -40,6 +40,9 @@ files:
40
40
  - lib/castle-rb.rb
41
41
  - lib/castle.rb
42
42
  - lib/castle/api.rb
43
+ - lib/castle/api/events/group.rb
44
+ - lib/castle/api/events/query.rb
45
+ - lib/castle/api/events/schema.rb
43
46
  - lib/castle/api/filter.rb
44
47
  - lib/castle/api/list_items/archive.rb
45
48
  - lib/castle/api/list_items/count.rb
@@ -60,11 +63,14 @@ files:
60
63
  - lib/castle/api/privacy/request_data.rb
61
64
  - lib/castle/api/risk.rb
62
65
  - lib/castle/client.rb
66
+ - lib/castle/client_actions/events.rb
63
67
  - lib/castle/client_actions/list_items.rb
64
68
  - lib/castle/client_actions/lists.rb
65
69
  - lib/castle/client_actions/privacy.rb
66
- - lib/castle/client_id/extract.rb
67
70
  - lib/castle/command.rb
71
+ - lib/castle/commands/events/group.rb
72
+ - lib/castle/commands/events/query.rb
73
+ - lib/castle/commands/events/schema.rb
68
74
  - lib/castle/commands/filter.rb
69
75
  - lib/castle/commands/list_items/archive.rb
70
76
  - lib/castle/commands/list_items/count.rb
@@ -113,7 +119,6 @@ files:
113
119
  - lib/castle/utils/get_timestamp.rb
114
120
  - lib/castle/utils/merge.rb
115
121
  - lib/castle/utils/secure_compare.rb
116
- - lib/castle/validators/not_supported.rb
117
122
  - lib/castle/validators/present.rb
118
123
  - lib/castle/verdict.rb
119
124
  - lib/castle/version.rb
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Castle
4
- module ClientId
5
- # used for extraction of cookies and headers from the request
6
- class Extract
7
- # @param headers [Hash]
8
- # @param cookies [NilClass|Hash]
9
- def initialize(headers, cookies)
10
- @headers = headers
11
- @cookies = cookies || {}
12
- end
13
-
14
- # extracts client id
15
- # @return [String]
16
- def call
17
- @headers['X-Castle-Client-Id'] || @cookies['__cid'] || ''
18
- end
19
- end
20
- end
21
- end
@@ -1,18 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Castle
4
- module Validators
5
- # Checks if required keys are supported
6
- class NotSupported
7
- class << self
8
- def call(options, keys)
9
- keys.each do |key|
10
- next unless options.key?(key)
11
-
12
- raise Castle::InvalidParametersError, "#{key} is/are not supported"
13
- end
14
- end
15
- end
16
- end
17
- end
18
- end