Skip to content

Commit

Permalink
Refactor code to use YAML::Any for all options
Browse files Browse the repository at this point in the history
  • Loading branch information
hahwul committed Sep 18, 2024
1 parent a6641c1 commit ccd046d
Show file tree
Hide file tree
Showing 52 changed files with 171 additions and 177 deletions.
12 changes: 6 additions & 6 deletions docs/_advanced/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ layout: page
base: ""

# Whether to use color in the output
color: "yes"
color: true

# The configuration file to use
config_file: ""
Expand All @@ -40,7 +40,7 @@ config_file: ""
concurrency: "100"

# Whether to enable debug mode
debug: "no"
debug: false

# Technologies to exclude
exclude_techs: ""
Expand All @@ -49,10 +49,10 @@ exclude_techs: ""
format: "plain"

# Whether to include the path in the output
include_path: "no"
include_path: false

# Whether to disable logging
nolog: "no"
nolog: false

# The output file to write to
output: ""
Expand All @@ -64,7 +64,7 @@ send_es: ""
send_proxy: ""

# Whether to send a request
send_req: "no"
send_req: false

# Whether to send headers with the request
send_with_headers: ""
Expand All @@ -85,7 +85,7 @@ use_filters: ""
use_matchers: ""

# Whether to use all taggers
all_taggers: "no"
all_taggers: false

# The taggers to use
use_taggers: ""
Expand Down
2 changes: 1 addition & 1 deletion spec/functional_test/func_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class FunctionalTester
config_init = ConfigInitializer.new
noir_options = config_init.default_options
noir_options["base"] = "./spec/functional_test/#{@path}"
noir_options["nolog"] = "yes"
noir_options["nolog"] = true

if !expected_count.nil?
@expected_count = expected_count
Expand Down
2 changes: 1 addition & 1 deletion spec/unit_test/models/deliver_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe "Initialize" do
options = config_init.default_options
options["base"] = "noir"
options["send_proxy"] = "http://localhost:8090"
options["nolog"] = "yes"
options["nolog"] = true

it "Deliver" do
object = Deliver.new options
Expand Down
2 changes: 1 addition & 1 deletion spec/unit_test/models/noir_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe "Methods" do
options = config_init.default_options
options["base"] = "noir"
options["url"] = "https://www.hahwul.com"
options["nolog"] = "yes"
options["nolog"] = true
runner = NoirRunner.new(options)

runner.endpoints << Endpoint.new("/abcd", "GET")
Expand Down
8 changes: 4 additions & 4 deletions spec/unit_test/utils/utils_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ describe "get_symbol" do
end

describe "str_to_bool" do
it "yes" do
str_to_bool("yes").should eq(true)
it true do
str_to_bool(true).should eq(true)
end
it "no" do
str_to_bool("no").should eq(false)
it false do
str_to_bool(false).should eq(false)
end
it "any string" do
str_to_bool("hahwul").should eq(false)
Expand Down
60 changes: 30 additions & 30 deletions src/analyzer/analyzer.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@ require "./analyzers/file_analyzers/*"

def initialize_analyzers(logger : NoirLogger)
# Initializing analyzers
analyzers = {} of String => Proc(Hash(String, String), Array(Endpoint))
analyzers = {} of String => Proc(Hash(String, YAML::Any), Array(Endpoint))

# Mapping analyzers to their respective functions
analyzers["c#-aspnet-mvc"] = ->analyzer_cs_aspnet_mvc(Hash(String, String))
analyzers["crystal_kemal"] = ->analyzer_crystal_kemal(Hash(String, String))
analyzers["crystal_lucky"] = ->analyzer_crystal_lucky(Hash(String, String))
analyzers["elixir_phoenix"] = ->analyzer_elixir_phoenix(Hash(String, String))
analyzers["go_beego"] = ->analyzer_go_beego(Hash(String, String))
analyzers["go_echo"] = ->analyzer_go_echo(Hash(String, String))
analyzers["go_fiber"] = ->analyzer_go_fiber(Hash(String, String))
analyzers["go_gin"] = ->analyzer_go_gin(Hash(String, String))
analyzers["har"] = ->analyzer_har(Hash(String, String))
analyzers["java_armeria"] = ->analyzer_armeria(Hash(String, String))
analyzers["java_jsp"] = ->analyzer_jsp(Hash(String, String))
analyzers["java_spring"] = ->analyzer_java_spring(Hash(String, String))
analyzers["js_express"] = ->analyzer_express(Hash(String, String))
analyzers["js_restify"] = ->analyzer_restify(Hash(String, String))
analyzers["kotlin_spring"] = ->analyzer_kotlin_spring(Hash(String, String))
analyzers["oas2"] = ->analyzer_oas2(Hash(String, String))
analyzers["oas3"] = ->analyzer_oas3(Hash(String, String))
analyzers["php_pure"] = ->analyzer_php_pure(Hash(String, String))
analyzers["python_django"] = ->analyzer_python_django(Hash(String, String))
analyzers["python_fastapi"] = ->analyzer_python_fastapi(Hash(String, String))
analyzers["python_flask"] = ->analyzer_python_flask(Hash(String, String))
analyzers["raml"] = ->analyzer_raml(Hash(String, String))
analyzers["ruby_hanami"] = ->analyzer_ruby_hanami(Hash(String, String))
analyzers["ruby_rails"] = ->analyzer_ruby_rails(Hash(String, String))
analyzers["ruby_sinatra"] = ->analyzer_ruby_sinatra(Hash(String, String))
analyzers["rust_axum"] = ->analyzer_rust_axum(Hash(String, String))
analyzers["rust_rocket"] = ->analyzer_rust_rocket(Hash(String, String))
analyzers["c#-aspnet-mvc"] = ->analyzer_cs_aspnet_mvc(Hash(String, YAML::Any))
analyzers["crystal_kemal"] = ->analyzer_crystal_kemal(Hash(String, YAML::Any))
analyzers["crystal_lucky"] = ->analyzer_crystal_lucky(Hash(String, YAML::Any))
analyzers["elixir_phoenix"] = ->analyzer_elixir_phoenix(Hash(String, YAML::Any))
analyzers["go_beego"] = ->analyzer_go_beego(Hash(String, YAML::Any))
analyzers["go_echo"] = ->analyzer_go_echo(Hash(String, YAML::Any))
analyzers["go_fiber"] = ->analyzer_go_fiber(Hash(String, YAML::Any))
analyzers["go_gin"] = ->analyzer_go_gin(Hash(String, YAML::Any))
analyzers["har"] = ->analyzer_har(Hash(String, YAML::Any))
analyzers["java_armeria"] = ->analyzer_armeria(Hash(String, YAML::Any))
analyzers["java_jsp"] = ->analyzer_jsp(Hash(String, YAML::Any))
analyzers["java_spring"] = ->analyzer_java_spring(Hash(String, YAML::Any))
analyzers["js_express"] = ->analyzer_express(Hash(String, YAML::Any))
analyzers["js_restify"] = ->analyzer_restify(Hash(String, YAML::Any))
analyzers["kotlin_spring"] = ->analyzer_kotlin_spring(Hash(String, YAML::Any))
analyzers["oas2"] = ->analyzer_oas2(Hash(String, YAML::Any))
analyzers["oas3"] = ->analyzer_oas3(Hash(String, YAML::Any))
analyzers["php_pure"] = ->analyzer_php_pure(Hash(String, YAML::Any))
analyzers["python_django"] = ->analyzer_python_django(Hash(String, YAML::Any))
analyzers["python_fastapi"] = ->analyzer_python_fastapi(Hash(String, YAML::Any))
analyzers["python_flask"] = ->analyzer_python_flask(Hash(String, YAML::Any))
analyzers["raml"] = ->analyzer_raml(Hash(String, YAML::Any))
analyzers["ruby_hanami"] = ->analyzer_ruby_hanami(Hash(String, YAML::Any))
analyzers["ruby_rails"] = ->analyzer_ruby_rails(Hash(String, YAML::Any))
analyzers["ruby_sinatra"] = ->analyzer_ruby_sinatra(Hash(String, YAML::Any))
analyzers["rust_axum"] = ->analyzer_rust_axum(Hash(String, YAML::Any))
analyzers["rust_rocket"] = ->analyzer_rust_rocket(Hash(String, YAML::Any))

logger.success "#{analyzers.size} Analyzers initialized"
logger.debug "Analyzers:"
Expand All @@ -42,7 +42,7 @@ def initialize_analyzers(logger : NoirLogger)
analyzers
end

def analysis_endpoints(options : Hash(String, String), techs, logger : NoirLogger)
def analysis_endpoints(options : Hash(String, YAML::Any), techs, logger : NoirLogger)
result = [] of Endpoint
file_analyzer = FileAnalyzer.new options
logger.info "Initializing analyzers"
Expand All @@ -57,7 +57,7 @@ def analysis_endpoints(options : Hash(String, String), techs, logger : NoirLogge

techs.each do |tech|
if analyzer.has_key?(tech)
if NoirTechs.similar_to_tech(options["exclude_techs"]).includes?(tech)
if NoirTechs.similar_to_tech(options["exclude_techs"].to_s).includes?(tech)
logger.sub "➔ Skipping #{tech} analysis"
next
end
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_armeria.cr
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class AnalyzerArmeria < Analyzer
end
end

def analyzer_armeria(options : Hash(String, String))
def analyzer_armeria(options : Hash(String, YAML::Any))
instance = AnalyzerArmeria.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_crystal_kemal.cr
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ class AnalyzerCrystalKemal < Analyzer
end
end

def analyzer_crystal_kemal(options : Hash(String, String))
def analyzer_crystal_kemal(options : Hash(String, YAML::Any))
instance = AnalyzerCrystalKemal.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_crystal_lucky.cr
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class AnalyzerCrystalLucky < Analyzer
end
end

def analyzer_crystal_lucky(options : Hash(String, String))
def analyzer_crystal_lucky(options : Hash(String, YAML::Any))
instance = AnalyzerCrystalLucky.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_cs_aspnet_mvc.cr
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class AnalyzerCsAspNetMvc < Analyzer
end
end

def analyzer_cs_aspnet_mvc(options : Hash(String, String))
def analyzer_cs_aspnet_mvc(options : Hash(String, YAML::Any))
instance = AnalyzerCsAspNetMvc.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_elixir_phoenix.cr
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class AnalyzerElixirPhoenix < Analyzer
end
end

def analyzer_elixir_phoenix(options : Hash(String, String))
def analyzer_elixir_phoenix(options : Hash(String, YAML::Any))
instance = AnalyzerElixirPhoenix.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_example.cr
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AnalyzerExample < Analyzer
end
end

def analyzer_example(options : Hash(String, String))
def analyzer_example(options : Hash(String, YAML::Any))
instance = AnalyzerExample.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_express.cr
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class AnalyzerExpress < Analyzer
end
end

def analyzer_express(options : Hash(String, String))
def analyzer_express(options : Hash(String, YAML::Any))
instance = AnalyzerExpress.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_go_beego.cr
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class AnalyzerGoBeego < Analyzer
end
end

def analyzer_go_beego(options : Hash(String, String))
def analyzer_go_beego(options : Hash(String, YAML::Any))
instance = AnalyzerGoBeego.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_go_echo.cr
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class AnalyzerGoEcho < Analyzer
end
end

def analyzer_go_echo(options : Hash(String, String))
def analyzer_go_echo(options : Hash(String, YAML::Any))
instance = AnalyzerGoEcho.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_go_fiber.cr
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ class AnalyzerGoFiber < Analyzer
end
end

def analyzer_go_fiber(options : Hash(String, String))
def analyzer_go_fiber(options : Hash(String, YAML::Any))
instance = AnalyzerGoFiber.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_go_gin.cr
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class AnalyzerGoGin < Analyzer
end
end

def analyzer_go_gin(options : Hash(String, String))
def analyzer_go_gin(options : Hash(String, YAML::Any))
instance = AnalyzerGoGin.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_har.cr
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AnalyzerHar < Analyzer
end
end

def analyzer_har(options : Hash(String, String))
def analyzer_har(options : Hash(String, YAML::Any))
instance = AnalyzerHar.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_java_spring.cr
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ class AnalyzerJavaSpring < Analyzer
end
end

def analyzer_java_spring(options : Hash(String, String))
def analyzer_java_spring(options : Hash(String, YAML::Any))
instance = AnalyzerJavaSpring.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_jsp.cr
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class AnalyzerJsp < Analyzer
end
end

def analyzer_jsp(options : Hash(String, String))
def analyzer_jsp(options : Hash(String, YAML::Any))
instance = AnalyzerJsp.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_kotlin_spring.cr
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ class AnalyzerKotlinSpring < Analyzer
end

# Function to instantiate and run the AnalyzerKotlinSpring
def analyzer_kotlin_spring(options : Hash(String, String))
def analyzer_kotlin_spring(options : Hash(String, YAML::Any))
instance = AnalyzerKotlinSpring.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_oas2.cr
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class AnalyzerOAS2 < Analyzer
end
end

def analyzer_oas2(options : Hash(String, String))
def analyzer_oas2(options : Hash(String, YAML::Any))
instance = AnalyzerOAS2.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_oas3.cr
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class AnalyzerOAS3 < Analyzer
end
end

def analyzer_oas3(options : Hash(String, String))
def analyzer_oas3(options : Hash(String, YAML::Any))
instance = AnalyzerOAS3.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_php_pure.cr
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class AnalyzerPhpPure < Analyzer
end
end

def analyzer_php_pure(options : Hash(String, String))
def analyzer_php_pure(options : Hash(String, YAML::Any))
instance = AnalyzerPhpPure.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_python_django.cr
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class AnalyzerDjango < AnalyzerPython
end

# Main function to analyze a Django project
def analyzer_python_django(options : Hash(String, String))
def analyzer_python_django(options : Hash(String, YAML::Any))
instance = AnalyzerDjango.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_python_fastapi.cr
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ class Router
end

# Analyzer function for FastAPI
def analyzer_python_fastapi(options : Hash(String, String))
def analyzer_python_fastapi(options : Hash(String, YAML::Any))
instance = AnalyzerFastAPI.new(options)
instance.analyze
end
Expand Down
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_python_flask.cr
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ class AnalyzerFlask < AnalyzerPython
end

# Analyzer function for Flask
def analyzer_python_flask(options : Hash(String, String))
def analyzer_python_flask(options : Hash(String, YAML::Any))
instance = AnalyzerFlask.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_raml.cr
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AnalyzerRAML < Analyzer
end
end

def analyzer_raml(options : Hash(String, String))
def analyzer_raml(options : Hash(String, YAML::Any))
instance = AnalyzerRAML.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_restify.cr
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class AnalyzerRestify < Analyzer
end
end

def analyzer_restify(options : Hash(String, String))
def analyzer_restify(options : Hash(String, YAML::Any))
instance = AnalyzerRestify.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_ruby_hanami.cr
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class AnalyzerRubyHanami < Analyzer
end
end

def analyzer_ruby_hanami(options : Hash(String, String))
def analyzer_ruby_hanami(options : Hash(String, YAML::Any))
instance = AnalyzerRubyHanami.new(options)
instance.analyze
end
2 changes: 1 addition & 1 deletion src/analyzer/analyzers/analyzer_ruby_rails.cr
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class AnalyzerRubyRails < Analyzer
end
end

def analyzer_ruby_rails(options : Hash(String, String))
def analyzer_ruby_rails(options : Hash(String, YAML::Any))
instance = AnalyzerRubyRails.new(options)
instance.analyze
end
Loading

0 comments on commit ccd046d

Please sign in to comment.