mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Refactor Grape framework code for improved readability and consistency
This commit is contained in:
@@ -115,7 +115,7 @@ class GrapeEndpoint extends DataFlow::CallNode {
|
||||
* Grape parameters available via the `params` method within an endpoint.
|
||||
*/
|
||||
class GrapeParamsSource extends Http::Server::RequestInputAccess::Range {
|
||||
GrapeParamsSource() {
|
||||
GrapeParamsSource() {
|
||||
this.asExpr().getExpr() instanceof GrapeParamsCall
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import codeql.ruby.AST
|
||||
|
||||
query predicate grapeAPIClasses(GrapeAPIClass api) { any() }
|
||||
|
||||
query predicate grapeEndpoints(GrapeAPIClass api, GrapeEndpoint endpoint, string method, string path) {
|
||||
query predicate grapeEndpoints(GrapeAPIClass api, GrapeEndpoint endpoint, string method, string path) {
|
||||
endpoint = api.getAnEndpoint() and
|
||||
method = endpoint.getHttpMethod() and
|
||||
path = endpoint.getPath()
|
||||
|
||||
@@ -9,7 +9,7 @@ class MyAPI < Grape::API
|
||||
user_agent = headers['User-Agent']
|
||||
"Hello #{name}!"
|
||||
end
|
||||
|
||||
|
||||
desc 'Post endpoint with params'
|
||||
params do
|
||||
requires :message, type: String
|
||||
@@ -18,36 +18,36 @@ class MyAPI < Grape::API
|
||||
msg = params[:message]
|
||||
{ status: 'received', message: msg }
|
||||
end
|
||||
|
||||
|
||||
desc 'Put endpoint accessing request'
|
||||
put '/update/:id' do
|
||||
id = params[:id]
|
||||
body = request.body.read
|
||||
{ id: id, body: body }
|
||||
end
|
||||
|
||||
desc 'Delete endpoint'
|
||||
|
||||
desc 'Delete endpoint'
|
||||
delete '/items/:id' do
|
||||
params[:id]
|
||||
end
|
||||
|
||||
|
||||
desc 'Patch endpoint'
|
||||
patch '/items/:id' do
|
||||
params[:id]
|
||||
end
|
||||
|
||||
|
||||
desc 'Head endpoint'
|
||||
head '/status' do
|
||||
# Just return status
|
||||
end
|
||||
|
||||
|
||||
desc 'Options endpoint'
|
||||
options '/info' do
|
||||
headers['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS'
|
||||
end
|
||||
end
|
||||
|
||||
class AdminAPI < Grape::API
|
||||
class AdminAPI < Grape::API
|
||||
get '/admin' do
|
||||
params[:token]
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user