castle-rb 5.0.0 → 6.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +107 -33
- data/lib/castle.rb +46 -22
- data/lib/castle/api.rb +22 -13
- data/lib/castle/api/approve_device.rb +25 -0
- data/lib/castle/api/authenticate.rb +34 -0
- data/lib/castle/api/end_impersonation.rb +29 -0
- data/lib/castle/api/get_device.rb +25 -0
- data/lib/castle/api/get_devices_for_user.rb +25 -0
- data/lib/castle/api/identify.rb +26 -0
- data/lib/castle/api/report_device.rb +25 -0
- data/lib/castle/api/review.rb +24 -0
- data/lib/castle/api/start_impersonation.rb +29 -0
- data/lib/castle/api/track.rb +26 -0
- data/lib/castle/client.rb +48 -62
- data/lib/castle/{extractors/client_id.rb → client_id/extract.rb} +2 -2
- data/lib/castle/commands/approve_device.rb +21 -0
- data/lib/castle/commands/authenticate.rb +13 -13
- data/lib/castle/commands/end_impersonation.rb +25 -0
- data/lib/castle/commands/get_device.rb +21 -0
- data/lib/castle/commands/get_devices_for_user.rb +21 -0
- data/lib/castle/commands/identify.rb +12 -13
- data/lib/castle/commands/report_device.rb +21 -0
- data/lib/castle/commands/review.rb +6 -3
- data/lib/castle/commands/start_impersonation.rb +25 -0
- data/lib/castle/commands/track.rb +12 -13
- data/lib/castle/configuration.rb +17 -19
- data/lib/castle/context/{default.rb → get_default.rb} +5 -6
- data/lib/castle/context/{merger.rb → merge.rb} +3 -3
- data/lib/castle/context/prepare.rb +18 -0
- data/lib/castle/context/{sanitizer.rb → sanitize.rb} +1 -1
- data/lib/castle/core/get_connection.rb +25 -0
- data/lib/castle/{api/response.rb → core/process_response.rb} +4 -2
- data/lib/castle/core/process_webhook.rb +20 -0
- data/lib/castle/core/send_request.rb +50 -0
- data/lib/castle/errors.rb +2 -0
- data/lib/castle/events.rb +1 -1
- data/lib/castle/failover/prepare_response.rb +23 -0
- data/lib/castle/failover/strategy.rb +20 -0
- data/lib/castle/{extractors/headers.rb → headers/extract.rb} +8 -6
- data/lib/castle/headers/filter.rb +37 -0
- data/lib/castle/headers/format.rb +24 -0
- data/lib/castle/{extractors/ip.rb → ip/extract.rb} +8 -7
- data/lib/castle/logger.rb +19 -0
- data/lib/castle/payload/prepare.rb +27 -0
- data/lib/castle/secure_mode.rb +6 -2
- data/lib/castle/session.rb +18 -0
- data/lib/castle/singleton_configuration.rb +9 -0
- data/lib/castle/utils/clean_invalid_chars.rb +24 -0
- data/lib/castle/utils/clone.rb +15 -0
- data/lib/castle/utils/deep_symbolize_keys.rb +45 -0
- data/lib/castle/utils/get_timestamp.rb +15 -0
- data/lib/castle/utils/{merger.rb → merge.rb} +3 -3
- data/lib/castle/utils/secure_compare.rb +22 -0
- data/lib/castle/validators/not_supported.rb +1 -0
- data/lib/castle/validators/present.rb +1 -0
- data/lib/castle/verdict.rb +13 -0
- data/lib/castle/version.rb +1 -1
- data/lib/castle/webhooks/verify.rb +43 -0
- data/spec/integration/rails/rails_spec.rb +33 -7
- data/spec/integration/rails/support/application.rb +3 -1
- data/spec/integration/rails/support/home_controller.rb +47 -5
- data/spec/lib/castle/api/approve_device_spec.rb +21 -0
- data/spec/lib/castle/api/authenticate_spec.rb +140 -0
- data/spec/lib/castle/api/end_impersonation_spec.rb +59 -0
- data/spec/lib/castle/api/get_device_spec.rb +19 -0
- data/spec/lib/castle/api/get_devices_for_user_spec.rb +19 -0
- data/spec/lib/castle/api/identify_spec.rb +68 -0
- data/spec/lib/castle/api/report_device_spec.rb +21 -0
- data/spec/lib/castle/{review_spec.rb → api/review_spec.rb} +3 -3
- data/spec/lib/castle/api/start_impersonation_spec.rb +59 -0
- data/spec/lib/castle/api/track_spec.rb +68 -0
- data/spec/lib/castle/api_spec.rb +16 -1
- data/spec/lib/castle/{extractors/client_id_spec.rb → client_id/extract_spec.rb} +2 -2
- data/spec/lib/castle/client_spec.rb +39 -21
- data/spec/lib/castle/commands/approve_device_spec.rb +24 -0
- data/spec/lib/castle/commands/authenticate_spec.rb +7 -16
- data/spec/lib/castle/commands/end_impersonation_spec.rb +82 -0
- data/spec/lib/castle/commands/get_device_spec.rb +24 -0
- data/spec/lib/castle/commands/get_devices_for_user_spec.rb +24 -0
- data/spec/lib/castle/commands/identify_spec.rb +5 -16
- data/spec/lib/castle/commands/report_device_spec.rb +24 -0
- data/spec/lib/castle/commands/review_spec.rb +1 -1
- data/spec/lib/castle/commands/{impersonate_spec.rb → start_impersonation_spec.rb} +7 -32
- data/spec/lib/castle/commands/track_spec.rb +5 -16
- data/spec/lib/castle/configuration_spec.rb +9 -138
- data/spec/lib/castle/context/{default_spec.rb → get_default_spec.rb} +1 -2
- data/spec/lib/castle/context/{merger_spec.rb → merge_spec.rb} +1 -1
- data/spec/lib/castle/context/prepare_spec.rb +44 -0
- data/spec/lib/castle/context/{sanitizer_spec.rb → sanitize_spec.rb} +1 -1
- data/spec/lib/castle/{api/connection_spec.rb → core/get_connection_spec.rb} +3 -3
- data/spec/lib/castle/{api/response_spec.rb → core/process_response_spec.rb} +56 -1
- data/spec/lib/castle/core/process_webhook_spec.rb +46 -0
- data/spec/lib/castle/{api/request_spec.rb → core/send_request_spec.rb} +20 -16
- data/spec/lib/castle/failover/strategy_spec.rb +12 -0
- data/spec/lib/castle/{extractors/headers_spec.rb → headers/extract_spec.rb} +7 -7
- data/spec/lib/castle/{headers_filter_spec.rb → headers/filter_spec.rb} +3 -3
- data/spec/lib/castle/headers/format_spec.rb +25 -0
- data/spec/lib/castle/{extractors/ip_spec.rb → ip/extract_spec.rb} +1 -1
- data/spec/lib/castle/logger_spec.rb +42 -0
- data/spec/lib/castle/payload/prepare_spec.rb +54 -0
- data/spec/lib/castle/{api/session_spec.rb → session_spec.rb} +6 -4
- data/spec/lib/castle/singleton_configuration_spec.rb +18 -0
- data/spec/lib/castle/utils/clean_invalid_chars_spec.rb +69 -0
- data/spec/lib/castle/utils/{cloner_spec.rb → clone_spec.rb} +3 -3
- data/spec/lib/castle/utils/deep_symbolize_keys_spec.rb +50 -0
- data/spec/lib/castle/utils/{timestamp_spec.rb → get_timestamp_spec.rb} +1 -1
- data/spec/lib/castle/utils/{merger_spec.rb → merge_spec.rb} +3 -3
- data/spec/lib/castle/verdict_spec.rb +9 -0
- data/spec/lib/castle/webhooks/verify_spec.rb +69 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/support/shared_examples/configuration.rb +129 -0
- metadata +129 -57
- data/lib/castle/api/connection.rb +0 -24
- data/lib/castle/api/request.rb +0 -42
- data/lib/castle/api/session.rb +0 -20
- data/lib/castle/commands/impersonate.rb +0 -26
- data/lib/castle/failover_auth_response.rb +0 -21
- data/lib/castle/headers_filter.rb +0 -35
- data/lib/castle/headers_formatter.rb +0 -22
- data/lib/castle/review.rb +0 -11
- data/lib/castle/utils.rb +0 -55
- data/lib/castle/utils/cloner.rb +0 -11
- data/lib/castle/utils/timestamp.rb +0 -12
- data/spec/lib/castle/headers_formatter_spec.rb +0 -25
- data/spec/lib/castle/utils_spec.rb +0 -156
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: castle-rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johan Brissmyr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -34,79 +34,127 @@ files:
|
|
34
34
|
- lib/castle-rb.rb
|
35
35
|
- lib/castle.rb
|
36
36
|
- lib/castle/api.rb
|
37
|
-
- lib/castle/api/
|
38
|
-
- lib/castle/api/
|
39
|
-
- lib/castle/api/
|
40
|
-
- lib/castle/api/
|
37
|
+
- lib/castle/api/approve_device.rb
|
38
|
+
- lib/castle/api/authenticate.rb
|
39
|
+
- lib/castle/api/end_impersonation.rb
|
40
|
+
- lib/castle/api/get_device.rb
|
41
|
+
- lib/castle/api/get_devices_for_user.rb
|
42
|
+
- lib/castle/api/identify.rb
|
43
|
+
- lib/castle/api/report_device.rb
|
44
|
+
- lib/castle/api/review.rb
|
45
|
+
- lib/castle/api/start_impersonation.rb
|
46
|
+
- lib/castle/api/track.rb
|
41
47
|
- lib/castle/client.rb
|
48
|
+
- lib/castle/client_id/extract.rb
|
42
49
|
- lib/castle/command.rb
|
50
|
+
- lib/castle/commands/approve_device.rb
|
43
51
|
- lib/castle/commands/authenticate.rb
|
52
|
+
- lib/castle/commands/end_impersonation.rb
|
53
|
+
- lib/castle/commands/get_device.rb
|
54
|
+
- lib/castle/commands/get_devices_for_user.rb
|
44
55
|
- lib/castle/commands/identify.rb
|
45
|
-
- lib/castle/commands/
|
56
|
+
- lib/castle/commands/report_device.rb
|
46
57
|
- lib/castle/commands/review.rb
|
58
|
+
- lib/castle/commands/start_impersonation.rb
|
47
59
|
- lib/castle/commands/track.rb
|
48
60
|
- lib/castle/configuration.rb
|
49
|
-
- lib/castle/context/
|
50
|
-
- lib/castle/context/
|
51
|
-
- lib/castle/context/
|
61
|
+
- lib/castle/context/get_default.rb
|
62
|
+
- lib/castle/context/merge.rb
|
63
|
+
- lib/castle/context/prepare.rb
|
64
|
+
- lib/castle/context/sanitize.rb
|
65
|
+
- lib/castle/core/get_connection.rb
|
66
|
+
- lib/castle/core/process_response.rb
|
67
|
+
- lib/castle/core/process_webhook.rb
|
68
|
+
- lib/castle/core/send_request.rb
|
52
69
|
- lib/castle/errors.rb
|
53
70
|
- lib/castle/events.rb
|
54
|
-
- lib/castle/
|
55
|
-
- lib/castle/
|
56
|
-
- lib/castle/
|
57
|
-
- lib/castle/
|
58
|
-
- lib/castle/
|
59
|
-
- lib/castle/
|
60
|
-
- lib/castle/
|
71
|
+
- lib/castle/failover/prepare_response.rb
|
72
|
+
- lib/castle/failover/strategy.rb
|
73
|
+
- lib/castle/headers/extract.rb
|
74
|
+
- lib/castle/headers/filter.rb
|
75
|
+
- lib/castle/headers/format.rb
|
76
|
+
- lib/castle/ip/extract.rb
|
77
|
+
- lib/castle/logger.rb
|
78
|
+
- lib/castle/payload/prepare.rb
|
61
79
|
- lib/castle/secure_mode.rb
|
80
|
+
- lib/castle/session.rb
|
81
|
+
- lib/castle/singleton_configuration.rb
|
62
82
|
- lib/castle/support/hanami.rb
|
63
83
|
- lib/castle/support/padrino.rb
|
64
84
|
- lib/castle/support/rails.rb
|
65
85
|
- lib/castle/support/sinatra.rb
|
66
|
-
- lib/castle/utils.rb
|
67
|
-
- lib/castle/utils/
|
68
|
-
- lib/castle/utils/
|
69
|
-
- lib/castle/utils/
|
86
|
+
- lib/castle/utils/clean_invalid_chars.rb
|
87
|
+
- lib/castle/utils/clone.rb
|
88
|
+
- lib/castle/utils/deep_symbolize_keys.rb
|
89
|
+
- lib/castle/utils/get_timestamp.rb
|
90
|
+
- lib/castle/utils/merge.rb
|
91
|
+
- lib/castle/utils/secure_compare.rb
|
70
92
|
- lib/castle/validators/not_supported.rb
|
71
93
|
- lib/castle/validators/present.rb
|
94
|
+
- lib/castle/verdict.rb
|
72
95
|
- lib/castle/version.rb
|
96
|
+
- lib/castle/webhooks/verify.rb
|
73
97
|
- spec/integration/rails/rails_spec.rb
|
74
98
|
- spec/integration/rails/support/all.rb
|
75
99
|
- spec/integration/rails/support/application.rb
|
76
100
|
- spec/integration/rails/support/home_controller.rb
|
77
|
-
- spec/lib/castle/api/
|
78
|
-
- spec/lib/castle/api/
|
79
|
-
- spec/lib/castle/api/
|
80
|
-
- spec/lib/castle/api/
|
101
|
+
- spec/lib/castle/api/approve_device_spec.rb
|
102
|
+
- spec/lib/castle/api/authenticate_spec.rb
|
103
|
+
- spec/lib/castle/api/end_impersonation_spec.rb
|
104
|
+
- spec/lib/castle/api/get_device_spec.rb
|
105
|
+
- spec/lib/castle/api/get_devices_for_user_spec.rb
|
106
|
+
- spec/lib/castle/api/identify_spec.rb
|
107
|
+
- spec/lib/castle/api/report_device_spec.rb
|
108
|
+
- spec/lib/castle/api/review_spec.rb
|
109
|
+
- spec/lib/castle/api/start_impersonation_spec.rb
|
110
|
+
- spec/lib/castle/api/track_spec.rb
|
81
111
|
- spec/lib/castle/api_spec.rb
|
112
|
+
- spec/lib/castle/client_id/extract_spec.rb
|
82
113
|
- spec/lib/castle/client_spec.rb
|
83
114
|
- spec/lib/castle/command_spec.rb
|
115
|
+
- spec/lib/castle/commands/approve_device_spec.rb
|
84
116
|
- spec/lib/castle/commands/authenticate_spec.rb
|
117
|
+
- spec/lib/castle/commands/end_impersonation_spec.rb
|
118
|
+
- spec/lib/castle/commands/get_device_spec.rb
|
119
|
+
- spec/lib/castle/commands/get_devices_for_user_spec.rb
|
85
120
|
- spec/lib/castle/commands/identify_spec.rb
|
86
|
-
- spec/lib/castle/commands/
|
121
|
+
- spec/lib/castle/commands/report_device_spec.rb
|
87
122
|
- spec/lib/castle/commands/review_spec.rb
|
123
|
+
- spec/lib/castle/commands/start_impersonation_spec.rb
|
88
124
|
- spec/lib/castle/commands/track_spec.rb
|
89
125
|
- spec/lib/castle/configuration_spec.rb
|
90
|
-
- spec/lib/castle/context/
|
91
|
-
- spec/lib/castle/context/
|
92
|
-
- spec/lib/castle/context/
|
126
|
+
- spec/lib/castle/context/get_default_spec.rb
|
127
|
+
- spec/lib/castle/context/merge_spec.rb
|
128
|
+
- spec/lib/castle/context/prepare_spec.rb
|
129
|
+
- spec/lib/castle/context/sanitize_spec.rb
|
130
|
+
- spec/lib/castle/core/get_connection_spec.rb
|
131
|
+
- spec/lib/castle/core/process_response_spec.rb
|
132
|
+
- spec/lib/castle/core/process_webhook_spec.rb
|
133
|
+
- spec/lib/castle/core/send_request_spec.rb
|
93
134
|
- spec/lib/castle/events_spec.rb
|
94
|
-
- spec/lib/castle/
|
95
|
-
- spec/lib/castle/
|
96
|
-
- spec/lib/castle/
|
97
|
-
- spec/lib/castle/
|
98
|
-
- spec/lib/castle/
|
99
|
-
- spec/lib/castle/
|
135
|
+
- spec/lib/castle/failover/strategy_spec.rb
|
136
|
+
- spec/lib/castle/headers/extract_spec.rb
|
137
|
+
- spec/lib/castle/headers/filter_spec.rb
|
138
|
+
- spec/lib/castle/headers/format_spec.rb
|
139
|
+
- spec/lib/castle/ip/extract_spec.rb
|
140
|
+
- spec/lib/castle/logger_spec.rb
|
141
|
+
- spec/lib/castle/payload/prepare_spec.rb
|
100
142
|
- spec/lib/castle/secure_mode_spec.rb
|
101
|
-
- spec/lib/castle/
|
102
|
-
- spec/lib/castle/
|
103
|
-
- spec/lib/castle/utils/
|
104
|
-
- spec/lib/castle/
|
143
|
+
- spec/lib/castle/session_spec.rb
|
144
|
+
- spec/lib/castle/singleton_configuration_spec.rb
|
145
|
+
- spec/lib/castle/utils/clean_invalid_chars_spec.rb
|
146
|
+
- spec/lib/castle/utils/clone_spec.rb
|
147
|
+
- spec/lib/castle/utils/deep_symbolize_keys_spec.rb
|
148
|
+
- spec/lib/castle/utils/get_timestamp_spec.rb
|
149
|
+
- spec/lib/castle/utils/merge_spec.rb
|
105
150
|
- spec/lib/castle/validators/not_supported_spec.rb
|
106
151
|
- spec/lib/castle/validators/present_spec.rb
|
152
|
+
- spec/lib/castle/verdict_spec.rb
|
107
153
|
- spec/lib/castle/version_spec.rb
|
154
|
+
- spec/lib/castle/webhooks/verify_spec.rb
|
108
155
|
- spec/lib/castle_spec.rb
|
109
156
|
- spec/spec_helper.rb
|
157
|
+
- spec/support/shared_examples/configuration.rb
|
110
158
|
homepage: https://castle.io
|
111
159
|
licenses:
|
112
160
|
- MIT
|
@@ -136,35 +184,59 @@ test_files:
|
|
136
184
|
- spec/integration/rails/support/all.rb
|
137
185
|
- spec/integration/rails/support/home_controller.rb
|
138
186
|
- spec/integration/rails/rails_spec.rb
|
187
|
+
- spec/support/shared_examples/configuration.rb
|
139
188
|
- spec/lib/castle_spec.rb
|
140
|
-
- spec/lib/castle/
|
141
|
-
- spec/lib/castle/
|
189
|
+
- spec/lib/castle/session_spec.rb
|
190
|
+
- spec/lib/castle/verdict_spec.rb
|
142
191
|
- spec/lib/castle/client_spec.rb
|
143
|
-
- spec/lib/castle/context/
|
144
|
-
- spec/lib/castle/context/
|
145
|
-
- spec/lib/castle/context/
|
192
|
+
- spec/lib/castle/context/get_default_spec.rb
|
193
|
+
- spec/lib/castle/context/prepare_spec.rb
|
194
|
+
- spec/lib/castle/context/sanitize_spec.rb
|
195
|
+
- spec/lib/castle/context/merge_spec.rb
|
196
|
+
- spec/lib/castle/core/get_connection_spec.rb
|
197
|
+
- spec/lib/castle/core/process_webhook_spec.rb
|
198
|
+
- spec/lib/castle/core/send_request_spec.rb
|
199
|
+
- spec/lib/castle/core/process_response_spec.rb
|
146
200
|
- spec/lib/castle/api_spec.rb
|
201
|
+
- spec/lib/castle/logger_spec.rb
|
202
|
+
- spec/lib/castle/client_id/extract_spec.rb
|
147
203
|
- spec/lib/castle/configuration_spec.rb
|
148
204
|
- spec/lib/castle/version_spec.rb
|
149
|
-
- spec/lib/castle/
|
150
|
-
- spec/lib/castle/utils/
|
151
|
-
- spec/lib/castle/utils/
|
205
|
+
- spec/lib/castle/payload/prepare_spec.rb
|
206
|
+
- spec/lib/castle/utils/clean_invalid_chars_spec.rb
|
207
|
+
- spec/lib/castle/utils/deep_symbolize_keys_spec.rb
|
208
|
+
- spec/lib/castle/utils/get_timestamp_spec.rb
|
209
|
+
- spec/lib/castle/utils/clone_spec.rb
|
210
|
+
- spec/lib/castle/utils/merge_spec.rb
|
152
211
|
- spec/lib/castle/command_spec.rb
|
153
|
-
- spec/lib/castle/
|
154
|
-
- spec/lib/castle/
|
155
|
-
- spec/lib/castle/
|
156
|
-
- spec/lib/castle/api/
|
157
|
-
- spec/lib/castle/api/
|
212
|
+
- spec/lib/castle/headers/format_spec.rb
|
213
|
+
- spec/lib/castle/headers/extract_spec.rb
|
214
|
+
- spec/lib/castle/headers/filter_spec.rb
|
215
|
+
- spec/lib/castle/api/review_spec.rb
|
216
|
+
- spec/lib/castle/api/report_device_spec.rb
|
217
|
+
- spec/lib/castle/api/authenticate_spec.rb
|
218
|
+
- spec/lib/castle/api/track_spec.rb
|
219
|
+
- spec/lib/castle/api/get_device_spec.rb
|
220
|
+
- spec/lib/castle/api/start_impersonation_spec.rb
|
221
|
+
- spec/lib/castle/api/approve_device_spec.rb
|
222
|
+
- spec/lib/castle/api/get_devices_for_user_spec.rb
|
223
|
+
- spec/lib/castle/api/end_impersonation_spec.rb
|
224
|
+
- spec/lib/castle/api/identify_spec.rb
|
158
225
|
- spec/lib/castle/commands/review_spec.rb
|
226
|
+
- spec/lib/castle/commands/report_device_spec.rb
|
159
227
|
- spec/lib/castle/commands/authenticate_spec.rb
|
160
228
|
- spec/lib/castle/commands/track_spec.rb
|
161
|
-
- spec/lib/castle/commands/
|
229
|
+
- spec/lib/castle/commands/get_device_spec.rb
|
230
|
+
- spec/lib/castle/commands/start_impersonation_spec.rb
|
231
|
+
- spec/lib/castle/commands/approve_device_spec.rb
|
232
|
+
- spec/lib/castle/commands/get_devices_for_user_spec.rb
|
233
|
+
- spec/lib/castle/commands/end_impersonation_spec.rb
|
162
234
|
- spec/lib/castle/commands/identify_spec.rb
|
163
235
|
- spec/lib/castle/validators/not_supported_spec.rb
|
164
236
|
- spec/lib/castle/validators/present_spec.rb
|
165
|
-
- spec/lib/castle/
|
166
|
-
- spec/lib/castle/
|
167
|
-
- spec/lib/castle/
|
168
|
-
- spec/lib/castle/utils_spec.rb
|
237
|
+
- spec/lib/castle/webhooks/verify_spec.rb
|
238
|
+
- spec/lib/castle/ip/extract_spec.rb
|
239
|
+
- spec/lib/castle/failover/strategy_spec.rb
|
169
240
|
- spec/lib/castle/secure_mode_spec.rb
|
241
|
+
- spec/lib/castle/singleton_configuration_spec.rb
|
170
242
|
- spec/lib/castle/events_spec.rb
|
@@ -1,24 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Castle
|
4
|
-
module API
|
5
|
-
# this module returns a new configured Net::HTTP object
|
6
|
-
module Connection
|
7
|
-
HTTPS_SCHEME = 'https'
|
8
|
-
|
9
|
-
class << self
|
10
|
-
def call
|
11
|
-
http = Net::HTTP.new(Castle.config.url.host, Castle.config.url.port)
|
12
|
-
http.read_timeout = Castle.config.request_timeout / 1000.0
|
13
|
-
|
14
|
-
if Castle.config.url.scheme == HTTPS_SCHEME
|
15
|
-
http.use_ssl = true
|
16
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
17
|
-
end
|
18
|
-
|
19
|
-
http
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
data/lib/castle/api/request.rb
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Castle
|
4
|
-
module API
|
5
|
-
# this class is responsible for making requests to api
|
6
|
-
module Request
|
7
|
-
# Default headers that we add to passed ones
|
8
|
-
DEFAULT_HEADERS = {
|
9
|
-
'Content-Type' => 'application/json'
|
10
|
-
}.freeze
|
11
|
-
|
12
|
-
private_constant :DEFAULT_HEADERS
|
13
|
-
|
14
|
-
class << self
|
15
|
-
def call(command, api_secret, headers, http = nil)
|
16
|
-
(http || Castle::API::Connection.call).request(
|
17
|
-
build(
|
18
|
-
command,
|
19
|
-
headers.merge(DEFAULT_HEADERS),
|
20
|
-
api_secret
|
21
|
-
)
|
22
|
-
)
|
23
|
-
end
|
24
|
-
|
25
|
-
def build(command, headers, api_secret)
|
26
|
-
request_obj = Net::HTTP.const_get(
|
27
|
-
command.method.to_s.capitalize
|
28
|
-
).new("#{Castle.config.url.path}/#{command.path}", headers)
|
29
|
-
|
30
|
-
unless command.method == :get
|
31
|
-
request_obj.body = ::Castle::Utils.replace_invalid_characters(
|
32
|
-
command.data
|
33
|
-
).to_json
|
34
|
-
end
|
35
|
-
|
36
|
-
request_obj.basic_auth('', api_secret)
|
37
|
-
request_obj
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
data/lib/castle/api/session.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Castle
|
4
|
-
module API
|
5
|
-
# this module uses the Connection object
|
6
|
-
# and provides start method for persistent connection usage
|
7
|
-
# when there is a need of sending multiple requests at once
|
8
|
-
module Session
|
9
|
-
HTTPS_SCHEME = 'https'
|
10
|
-
|
11
|
-
class << self
|
12
|
-
def call(&block)
|
13
|
-
return unless block_given?
|
14
|
-
|
15
|
-
Connection.call.start(&block)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Castle
|
4
|
-
module Commands
|
5
|
-
# builder for impersonate command
|
6
|
-
class Impersonate
|
7
|
-
def initialize(context)
|
8
|
-
@context = context
|
9
|
-
end
|
10
|
-
|
11
|
-
def build(options = {})
|
12
|
-
Castle::Validators::Present.call(options, %i[user_id])
|
13
|
-
context = Castle::Context::Merger.call(@context, options[:context])
|
14
|
-
context = Castle::Context::Sanitizer.call(context)
|
15
|
-
|
16
|
-
Castle::Validators::Present.call(context, %i[user_agent ip])
|
17
|
-
|
18
|
-
Castle::Command.new(
|
19
|
-
'impersonate',
|
20
|
-
options.merge(context: context, sent_at: Castle::Utils::Timestamp.call),
|
21
|
-
options[:reset] ? :delete : :post
|
22
|
-
)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Castle
|
4
|
-
# generate failover authentication response
|
5
|
-
class FailoverAuthResponse
|
6
|
-
def initialize(user_id, strategy: Castle.config.failover_strategy, reason:)
|
7
|
-
@strategy = strategy
|
8
|
-
@reason = reason
|
9
|
-
@user_id = user_id
|
10
|
-
end
|
11
|
-
|
12
|
-
def generate
|
13
|
-
{
|
14
|
-
action: @strategy.to_s,
|
15
|
-
user_id: @user_id,
|
16
|
-
failover: true,
|
17
|
-
failover_reason: @reason
|
18
|
-
}
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Castle
|
4
|
-
# used for preparing valuable headers list
|
5
|
-
class HeadersFilter
|
6
|
-
# headers filter
|
7
|
-
# HTTP_ - this is how Rack prefixes incoming HTTP headers
|
8
|
-
# CONTENT_LENGTH - for responses without Content-Length or Transfer-Encoding header
|
9
|
-
# REMOTE_ADDR - ip address header returned by web server
|
10
|
-
VALUABLE_HEADERS = /^
|
11
|
-
HTTP(?:_|-).*|
|
12
|
-
CONTENT(?:_|-)LENGTH|
|
13
|
-
REMOTE(?:_|-)ADDR
|
14
|
-
$/xi.freeze
|
15
|
-
|
16
|
-
private_constant :VALUABLE_HEADERS
|
17
|
-
|
18
|
-
# @param request [Rack::Request]
|
19
|
-
def initialize(request)
|
20
|
-
@request_env = request.env
|
21
|
-
@formatter = HeadersFormatter
|
22
|
-
end
|
23
|
-
|
24
|
-
# Serialize HTTP headers
|
25
|
-
# @return [Hash]
|
26
|
-
def call
|
27
|
-
@request_env.keys.each_with_object({}) do |header_name, acc|
|
28
|
-
next unless header_name.match(VALUABLE_HEADERS)
|
29
|
-
|
30
|
-
formatted_name = @formatter.call(header_name)
|
31
|
-
acc[formatted_name] = @request_env[header_name]
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Castle
|
4
|
-
# formats header name
|
5
|
-
class HeadersFormatter
|
6
|
-
class << self
|
7
|
-
# @param header [String]
|
8
|
-
# @return [String]
|
9
|
-
def call(header)
|
10
|
-
format(header.to_s.gsub(/^HTTP(?:_|-)/i, ''))
|
11
|
-
end
|
12
|
-
|
13
|
-
private
|
14
|
-
|
15
|
-
# @param header [String]
|
16
|
-
# @return [String]
|
17
|
-
def format(header)
|
18
|
-
header.split(/_|-/).map(&:capitalize).join('-')
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|