class AnalyzerDjango

Defined in:

analyzer/analyzers/analyzer_python_django.cr

Constant Summary

REGEX_INCLUDE_URLS = /include\s*\(\s*r?['"]([^'"\\]*)['"]/
REGEX_ROOT_URLCONF = /\s*ROOT_URLCONF\s*=\s*r?['"]([^'"\\]*)['"]/

Regular expressions for extracting Django URL configurations

REGEX_ROUTE_MAPPING = /(?:url|path|register)\s*\(\s*r?['"]([^"']*)['"][^,]*,\s*([^),]*)/
REQUEST_PARAM_FIELD_MAP = {"GET" => {["GET"], "query"}, "POST" => {["POST"], "form"}, "COOKIES" => {nil, "cookie"}, "META" => {nil, "header"}, "data" => {["POST", "PUT", "PATCH"], "form"}}

Map request parameters to their respective fields

REQUEST_PARAM_TYPE_MAP = {"query" => nil, "form" => ["GET", "POST", "PUT", "PATCH"], "cookie" => nil, "header" => nil}

Map request parameter types to HTTP methods

Instance Method Summary

Instance methods inherited from class AnalyzerPython

find_imported_modules(app_base_path : String, file_path : String, content : String | Nil = nil) : Hash(String, Tuple(String, Int32)) find_imported_modules, find_imported_package(package_path : String, dotted_as_names : String) : Array(Tuple(String, String, Int32)) find_imported_package, find_json_params(codeblock_lines : Array(String), json_var_names : Array(String)) : Array(Param) find_json_params, parse_code_block(data : String | Array(String), after : Regex | Nil = nil) : String | Nil parse_code_block, parse_function_def(source_lines : Array(String), start_index : Int32) : FunctionDefinition | Nil parse_function_def, return_literal_value(data : String) : String return_literal_value

Instance methods inherited from class Analyzer

analyze analyze, base_path : String base_path, logger : NoirLogger logger, result : Array(Endpoint) result, url : String url

Constructor methods inherited from class Analyzer

new(options : Hash(String, String)) new

Macros inherited from class Analyzer

define_getter_methods(names) define_getter_methods

Instance Method Detail

def analyze #

[View source]
def extract_endpoints(django_urls : DjangoUrls) : Array(Endpoint) #

Extract endpoints from a Django URL configuration file


[View source]
def extract_endpoints_from_file(url : String, filepath : String, function_or_class_name : String) #

Extract endpoints from a given file


[View source]
def extract_params_from_line(line : String, endpoint_methods : Array(String)) #

Extract parameters from a line of code


[View source]
def filter_params(method : String, params : Array(Param)) #

Filter parameters based on HTTP method


[View source]
def find_root_django_urls : Array(DjangoUrls) #

Find all root Django URLs


[View source]