-
Notifications
You must be signed in to change notification settings - Fork 399
Fix AppSec Sinatra contrib types #5275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ def watch | |
|
|
||
| def watch_request_dispatch(gateway = Instrumentation.gateway) | ||
| gateway.watch('sinatra.request.dispatch', :appsec) do |stack, gateway_request| | ||
| context = gateway_request.env[AppSec::Ext::CONTEXT_KEY] | ||
| context = gateway_request.env[AppSec::Ext::CONTEXT_KEY] # : Context | ||
|
|
||
| persistent_data = { | ||
| 'server.request.body' => gateway_request.form_hash | ||
|
|
@@ -49,8 +49,9 @@ def watch_request_dispatch(gateway = Instrumentation.gateway) | |
| end | ||
|
|
||
| def watch_request_routed(gateway = Instrumentation.gateway) | ||
| gateway.watch('sinatra.request.routed', :appsec) do |stack, (gateway_request, gateway_route_params)| | ||
| context = gateway_request.env[AppSec::Ext::CONTEXT_KEY] | ||
| gateway.watch('sinatra.request.routed', :appsec) do |stack, args| | ||
| gateway_request, gateway_route_params = args # : [Gateway::Request, Gateway::RouteParams] | ||
|
Comment on lines
+52
to
+53
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's annoying that you have to do this, just to add a type annotation. 😢 |
||
| context = gateway_request.env[AppSec::Ext::CONTEXT_KEY] # : Context | ||
|
|
||
| persistent_data = { | ||
| 'server.request.path_params' => gateway_route_params.params | ||
|
|
@@ -75,7 +76,7 @@ def watch_request_routed(gateway = Instrumentation.gateway) | |
|
|
||
| def watch_response_body_json(gateway = Instrumentation.gateway) | ||
| gateway.watch('sinatra.response.body.json', :appsec) do |stack, container| | ||
| context = container.context | ||
| context = container.context # : Context | ||
|
|
||
| persistent_data = { | ||
| 'server.response.body' => container.data | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| module Datadog | ||
| module AppSec | ||
| module Contrib | ||
| module Sinatra | ||
| type rack_env = ::Hash[::String, top] | ||
| type rack_response = [::Integer, ::Hash[::String, ::String], ::Array[::String]] | ||
| type rack_app = ^(rack_env) -> rack_response | ||
| end | ||
| end | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,7 +6,7 @@ module Datadog | |
| type final_call_result = untyped | ||
| type final_call = ^() -> final_call_result | ||
| type stack = ::Proc | ||
| type argument = Gateway::Argument | ::String | ||
| type argument = Gateway::Argument | ::String | ::Array[Gateway::Argument] | ||
|
|
||
| type stack_result = ::Array[nil | middleware_result | final_call_result] | ||
|
|
||
|
|
@@ -17,7 +17,10 @@ module Datadog | |
|
|
||
| def push: (::String name, argument env) ?{ () -> final_call_result } -> stack_result | ||
|
|
||
| def watch: (::String name, ::Symbol key) { (stack next, argument env) -> stack_result } -> void | ||
| def watch: ("sinatra.request.dispatch", ::Symbol key) { (stack, ::Datadog::AppSec::Contrib::Sinatra::Gateway::Request) -> stack_result } -> void | ||
| | ("sinatra.request.routed", ::Symbol key) { (stack, [::Datadog::AppSec::Contrib::Sinatra::Gateway::Request, ::Datadog::AppSec::Contrib::Sinatra::Gateway::RouteParams]) -> stack_result } -> void | ||
| | ("sinatra.response.body.json", ::Symbol key) { (stack, Gateway::DataContainer) -> stack_result } -> void | ||
| | (::String name, ::Symbol key) { (stack, argument) -> stack_result } -> void | ||
|
Comment on lines
+20
to
+23
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Strech what do you think of this approach?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess our "dynamically-typed" language loses its charm in RBS signatures. But regarding this change, I don't see how it could be made much better, it looks ok I think. The only thing we could theoretically do is move each argument type (or signature) to the integration package: e.g. declare a type for |
||
|
|
||
| def pushed?: (::String name) -> bool | ||
| end | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| module Rack | ||
| class Request | ||
| def initialize: (::Hash[::String, top] env) -> void | ||
|
|
||
| def env: () -> ::Hash[::String, top] | ||
|
|
||
| def params: () -> ::Hash[::String, top] | ||
|
|
||
| def body: () -> top | ||
|
|
||
| def get?: () -> bool | ||
|
|
||
| def post?: () -> bool | ||
|
|
||
| def path: () -> ::String | ||
| end | ||
| end |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,4 +5,7 @@ module Sinatra | |
|
|
||
| class Base | ||
| end | ||
|
|
||
| module JSON | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry if I'm out of the loop: is this the "new" syntax for type overrides?
# : ...