Skip to content

Commit

Permalink
Remove spawn and code linting
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Aug 6, 2023
1 parent cc200a6 commit 90c4b98
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 147 deletions.
8 changes: 3 additions & 5 deletions src/analyzer/analyzers/analyzer_django.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ class AnalyzerDjango < Analyzer
def analyze
# Public Dir Analysis
Dir.glob("#{@base_path}/static/**/*") do |file|
spawn do
next if File.directory?(file)
relative_path = file.sub("#{@base_path}/static/", "")
@result << Endpoint.new("#{@url}/#{relative_path}", "GET")
end
next if File.directory?(file)
relative_path = file.sub("#{@base_path}/static/", "")
@result << Endpoint.new("#{@url}/#{relative_path}", "GET")
end

# urls.py Analysis
Expand Down
10 changes: 4 additions & 6 deletions src/analyzer/analyzers/analyzer_example.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ class AnalyzerExample < Analyzer
def analyze
# Source Analysis
Dir.glob("#{base_path}/**/*") do |path|
spawn do
next if File.directory?(path)
if File.exists?(path)
File.open(path, "r") do |file|
file.each_line do |_|
end
next if File.directory?(path)
if File.exists?(path)
File.open(path, "r") do |file|
file.each_line do |_|
end
end
end
Expand Down
58 changes: 28 additions & 30 deletions src/analyzer/analyzers/analyzer_express.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,40 +14,38 @@ def analyzer_express(options : Hash(Symbol, String))

# Source Analysis
Dir.glob("#{base_path}/**/*") do |path|
spawn do
next if File.directory?(path)
if File.exists?(path)
File.open(path, "r") do |file|
file.each_line do |line|
if line.includes? ".get('/"
api_path = express_get_endpoint(line)
if api_path != ""
result << Endpoint.new(api_path, "GET")
end
next if File.directory?(path)
if File.exists?(path)
File.open(path, "r") do |file|
file.each_line do |line|
if line.includes? ".get('/"
api_path = express_get_endpoint(line)
if api_path != ""
result << Endpoint.new(api_path, "GET")
end
if line.includes? ".post('/"
api_path = express_get_endpoint(line)
if api_path != ""
result << Endpoint.new(api_path, "POST")
end
end
if line.includes? ".post('/"
api_path = express_get_endpoint(line)
if api_path != ""
result << Endpoint.new(api_path, "POST")
end
if line.includes? ".put('/"
api_path = express_get_endpoint(line)
if api_path != ""
result << Endpoint.new(api_path, "PUT")
end
end
if line.includes? ".put('/"
api_path = express_get_endpoint(line)
if api_path != ""
result << Endpoint.new(api_path, "PUT")
end
if line.includes? ".delete('/"
api_path = express_get_endpoint(line)
if api_path != ""
result << Endpoint.new(api_path, "DELETE")
end
end
if line.includes? ".delete('/"
api_path = express_get_endpoint(line)
if api_path != ""
result << Endpoint.new(api_path, "DELETE")
end
if line.includes? ".patch('/"
api_path = express_get_endpoint(line)
if api_path != ""
result << Endpoint.new(api_path, "PATCH")
end
end
if line.includes? ".patch('/"
api_path = express_get_endpoint(line)
if api_path != ""
result << Endpoint.new(api_path, "PATCH")
end
end
end
Expand Down
22 changes: 10 additions & 12 deletions src/analyzer/analyzers/analyzer_flask.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ class AnalyzerFlask < Analyzer
def analyze
# Source Analysis
Dir.glob("#{base_path}/**/*") do |path|
spawn do
next if File.directory?(path)
if File.exists?(path) && File.extname(path) == ".py"
File.open(path, "r") do |file|
file.each_line do |line|
line.strip.scan(/@app\.route\((.*)\)/) do |match|
if match.size > 0
splited = match[0].split("(")
if splited.size > 1
endpoint_path = splited[1].gsub("\"", "").gsub("'", "").gsub(")", "").gsub(" ", "")
result << Endpoint.new("#{url}#{endpoint_path}", "GET")
end
next if File.directory?(path)
if File.exists?(path) && File.extname(path) == ".py"
File.open(path, "r") do |file|
file.each_line do |line|
line.strip.scan(/@app\.route\((.*)\)/) do |match|
if match.size > 0
splited = match[0].split("(")
if splited.size > 1
endpoint_path = splited[1].gsub("\"", "").gsub("'", "").gsub(")", "").gsub(" ", "")
result << Endpoint.new("#{url}#{endpoint_path}", "GET")
end
end
end
Expand Down
18 changes: 8 additions & 10 deletions src/analyzer/analyzers/analyzer_go_echo.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ class AnalyzerGoEcho < Analyzer
def analyze
# Source Analysis
Dir.glob("#{base_path}/**/*") do |path|
spawn do
next if File.directory?(path)
if File.exists?(path) && File.extname(path) == ".go"
File.open(path, "r") do |file|
file.each_line do |line|
if line.includes?(".GET(") || line.includes?(".POST(") || line.includes?(".PUT(") || line.includes?(".DELETE(")
get_route_path_go_echo(line).tap do |route_path|
if route_path.size > 0
result << Endpoint.new("#{url}#{route_path}", line.split(".")[1].split("(")[0])
end
next if File.directory?(path)
if File.exists?(path) && File.extname(path) == ".go"
File.open(path, "r") do |file|
file.each_line do |line|
if line.includes?(".GET(") || line.includes?(".POST(") || line.includes?(".PUT(") || line.includes?(".DELETE(")
get_route_path_go_echo(line).tap do |route_path|
if route_path.size > 0
result << Endpoint.new("#{url}#{route_path}", line.split(".")[1].split("(")[0])
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions src/analyzer/analyzers/analyzer_kemal.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AnalyzerKemal < Analyzer
return Param.new(param, "", "body")
end

return Param.new("", "", "")
Param.new("", "", "")
end

def line_to_endpoint(content : String) : Endpoint
Expand Down Expand Up @@ -99,7 +99,7 @@ class AnalyzerKemal < Analyzer
end
end

return Endpoint.new("", "")
Endpoint.new("", "")
end
end

Expand Down
54 changes: 26 additions & 28 deletions src/analyzer/analyzers/analyzer_php_pure.cr
Original file line number Diff line number Diff line change
Expand Up @@ -5,40 +5,38 @@ class AnalyzerPhpPure < Analyzer
def analyze
# Source Analysis
Dir.glob("#{base_path}/**/*") do |path|
spawn do
next if File.directory?(path)
if base_path[-1].to_s == "/"
relative_path = path.sub("#{base_path}", "").sub("./", "").sub("//", "/")
else
relative_path = path.sub("#{base_path}/", "").sub("./", "").sub("//", "/")
end
relative_path = remove_start_slash(relative_path)
next if File.directory?(path)
if base_path[-1].to_s == "/"
relative_path = path.sub("#{base_path}", "").sub("./", "").sub("//", "/")
else
relative_path = path.sub("#{base_path}/", "").sub("./", "").sub("//", "/")
end
relative_path = remove_start_slash(relative_path)

if File.exists?(path) && File.extname(path) == ".php"
File.open(path, "r") do |file|
params_query = [] of Param
params_body = [] of Param
methods = [] of String
if File.exists?(path) && File.extname(path) == ".php"
File.open(path, "r") do |file|
params_query = [] of Param
params_body = [] of Param
methods = [] of String

file.each_line do |line|
match = line.strip.match(%r{.*\$_(.*?)\['(.*?)'\];})
file.each_line do |line|
match = line.strip.match(%r{.*\$_(.*?)\['(.*?)'\];})

if match
method = match[1]
param_name = match[2]
if match
method = match[1]
param_name = match[2]

methods = methods | [method]
params_query << Param.new(param_name, "string", "query")
params_body << Param.new(param_name, "string", "form")
end
rescue
next
methods = methods | [method]
params_query << Param.new(param_name, "string", "query")
params_body << Param.new(param_name, "string", "form")
end
methods.each do |method|
result << Endpoint.new("#{url}/#{relative_path}", method, params_body)
end
result << Endpoint.new("#{url}/#{relative_path}", "GET", params_query)
rescue
next
end
methods.each do |method|
result << Endpoint.new("#{url}/#{relative_path}", method, params_body)
end
result << Endpoint.new("#{url}/#{relative_path}", "GET", params_query)
end
end
end
Expand Down
8 changes: 3 additions & 5 deletions src/analyzer/analyzers/analyzer_rails.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ class AnalyzerRails < Analyzer
def analyze
# Public Dir Analysis
Dir.glob("#{@base_path}/public/**/*") do |file|
spawn do
next if File.directory?(file)
relative_path = file.sub("#{@base_path}/public/", "")
@result << Endpoint.new("#{@url}/#{relative_path}", "GET")
end
next if File.directory?(file)
relative_path = file.sub("#{@base_path}/public/", "")
@result << Endpoint.new("#{@url}/#{relative_path}", "GET")
end

# Config Analysis
Expand Down
22 changes: 11 additions & 11 deletions src/analyzer/analyzers/analyzer_sinatra.cr
Original file line number Diff line number Diff line change
Expand Up @@ -34,54 +34,54 @@ class AnalyzerSinatra < Analyzer
param = content.split("param[")[1].split("]")[0].gsub("\"", "").gsub("'", "")
return Param.new(param, "", "query")
end
return Param.new("", "", "")

Param.new("", "", "")
end

def line_to_endpoint(content : String) : Endpoint
content.scan(/get\s+['"](.+?)['"]/) do |match|
if match.size > 1
return Endpoint.new("#{@url}#{match[1]}", "GET")
end
end

content.scan(/post\s+['"](.+?)['"]/) do |match|
if match.size > 1
return Endpoint.new("#{@url}#{match[1]}", "POST")
end
end

content.scan(/put\s+['"](.+?)['"]/) do |match|
if match.size > 1
return Endpoint.new("#{@url}#{match[1]}", "PUT")
end
end

content.scan(/delete\s+['"](.+?)['"]/) do |match|
if match.size > 1
return Endpoint.new("#{@url}#{match[1]}", "DELETE")
end
end

content.scan(/patch\s+['"](.+?)['"]/) do |match|
if match.size > 1
return Endpoint.new("#{@url}#{match[1]}", "PATCH")
end
end

content.scan(/head\s+['"](.+?)['"]/) do |match|
if match.size > 1
return Endpoint.new("#{@url}#{match[1]}", "HEAD")
end
end

content.scan(/options\s+['"](.+?)['"]/) do |match|
if match.size > 1
return Endpoint.new("#{@url}#{match[1]}", "OPTIONS")
end
end
return Endpoint.new("", "")

Endpoint.new("", "")
end
end

Expand Down
Loading

0 comments on commit 90c4b98

Please sign in to comment.