Class: SecurityPentestPlanner::OpenAPIParser
- Inherits:
-
Object
- Object
- SecurityPentestPlanner::OpenAPIParser
show all
- Defined in:
- lib/security_pentest_planner/openapi_parser.rb
Defined Under Namespace
Classes: Endpoint, Parameter
Constant Summary
collapse
/tenant/i
- DATE_PARAM_PATTERN =
/date|start|end|from|to|period|range/i
/timezone|time_zone|tz/i
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(content, source_path: nil) ⇒ OpenAPIParser
Returns a new instance of OpenAPIParser.
57
58
59
60
|
# File 'lib/security_pentest_planner/openapi_parser.rb', line 57
def initialize(content, source_path: nil)
@raw = content
@source_path = source_path
end
|
Instance Attribute Details
#raw ⇒ Object
Returns the value of attribute raw.
55
56
57
|
# File 'lib/security_pentest_planner/openapi_parser.rb', line 55
def raw
@raw
end
|
#source_path ⇒ Object
Returns the value of attribute source_path.
55
56
57
|
# File 'lib/security_pentest_planner/openapi_parser.rb', line 55
def source_path
@source_path
end
|
Class Method Details
.parse_file(path) ⇒ Object
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/security_pentest_planner/openapi_parser.rb', line 62
def self.parse_file(path)
content = File.read(path)
parsed = case File.extname(path).downcase
when ".yaml", ".yml" then YAML.safe_load(content, aliases: true)
when ".json" then JSON.parse(content)
else
raise ParseError, "Unsupported file extension: #{path}. Use .yaml, .yml or .json"
end
new(parsed, source_path: path)
end
|
Instance Method Details
#endpoints ⇒ Object
89
90
91
|
# File 'lib/security_pentest_planner/openapi_parser.rb', line 89
def endpoints
@endpoints ||= build_endpoints
end
|
#parameters_for(endpoint) ⇒ Object
93
94
95
96
97
|
# File 'lib/security_pentest_planner/openapi_parser.rb', line 93
def parameters_for(endpoint)
global = Array(raw.dig("paths", endpoint.path, "parameters"))
local = Array(endpoint.parameters)
merge_parameters(global + local)
end
|
#security_schemes ⇒ Object
85
86
87
|
# File 'lib/security_pentest_planner/openapi_parser.rb', line 85
def security_schemes
raw.dig("components", "securitySchemes") || {}
end
|
#servers ⇒ Object
81
82
83
|
# File 'lib/security_pentest_planner/openapi_parser.rb', line 81
def servers
Array(raw["servers"]).map { |s| s["url"] }.compact
end
|
#title ⇒ Object
73
74
75
|
# File 'lib/security_pentest_planner/openapi_parser.rb', line 73
def title
info["title"]
end
|
#version ⇒ Object
77
78
79
|
# File 'lib/security_pentest_planner/openapi_parser.rb', line 77
def version
info["version"]
end
|