Skip to content

Commit

Permalink
Merge pull request #1 from mort666/Alternate-Object
Browse files Browse the repository at this point in the history
Rewrite of API parsing and handling to eliminate the use of roxml
  • Loading branch information
mort666 committed Dec 20, 2012
2 parents 243f30a + ffef2d0 commit 9cfca6c
Show file tree
Hide file tree
Showing 11 changed files with 694 additions and 239 deletions.
107 changes: 75 additions & 32 deletions lib/veracode/api/builds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,46 +2,89 @@

module Veracode
module Result
module Builds
class AnalysisUnit < Base
xml_reader :analysis_type, :from => "@analysis_type"
xml_reader :status, :from => "@status"
xml_reader :published_date, :from => "@published_date"
module Builds
class AnalysisUnit < Base
api_field :analysis_type, :tag => :analysis_type
api_field :status, :tag => :status
api_field :published_date, :tag => :published_date
end

class Build < Base
xml_reader :version, :from => "@version"
xml_reader :build_id, :from => "@build_id"
xml_reader :submitter, :from => "@submitter"
xml_reader :platform, :from => "@platform"
xml_reader :lifecycle_stage, :from => "@lifecycle_stage"
xml_reader :results_ready, :from => "@results_ready"
xml_reader :policy_name, :from => "@policy_name"
xml_reader :policy_version, :from => "@policy_version"
xml_reader :policy_compliance_status, :from => "@policy_compliance_status"
xml_reader :rules_status, :from => "@rules_status"
xml_reader :grace_period_expired, :from => "@grace_period_expired"
xml_reader :scan_overdue, :from => "@scan_overdue"

xml_reader :analysis_units, :as => [AnalysisUnit]
class Build < Base
api_field :version, :tag => :version
api_field :build_id, :tag => :build_id
api_field :submitter, :tag => :submitter
api_field :platform, :tag => :platform
api_field :lifecycle_stage, :tag => :lifecycle_stage
api_field :policy_name, :tag => :policy_name
api_field :policy_version, :tag => :policy_version
api_field :policy_compliance_status, :tag => :policy_compliance_status
api_field :rules_status, :tag => :rules_status

def grace_period_expired?
@grace_period_expired ||= @xml_hash.grace_period_expired.to_bool
end

def scan_overdue?
@scan_overdue ||= @xml_hash.scan_overdue.to_bool
end

def results_ready?
@results_ready ||= @xml_hash.results_ready.to_bool
end

def analysis_units
@analysis_units ||= []
if @analysis_units.empty?
if @xml_hash.analysis_unit.class == Array
@analysis_units = @xml_hash.analysis_unit.map do |analysis_unit|
AnalysisUnit.new(analysis_unit)
end
else
@analysis_units << AnalysisUnit.new(@xml_hash.analysis_unit)
end
end
return @analysis_units
end
end

class Application < Base
xml_reader :app_name, :from => "@app_name"
xml_reader :app_id, :from => "@app_id"
xml_reader :industry_vertical, :from => "@industry_vertical"
xml_reader :assurance_level, :from => "@assurance_level"
xml_reader :business_criticality, :from => "business_criticality"
xml_reader :origin, :from => "@origin"
xml_reader :cots, :from => "@cots"
xml_reader :business_unit, :from => "@business_unit"
xml_reader :tags, :from => "@tags"
xml_reader :builds, :as => [Build]

api_field :app_name, :tag => :app_name
api_field :app_id, :tag => :app_id
api_field :industry_vertical, :tag => :industry_vertical
api_field :assurance_level, :tag => :assurance_level
api_field :business_criticality, :tag => :business_criticality
api_field :origin, :tag => :origin
api_field :business_unit, :tag => :business_unit
api_field :tags, :tag => :tags

def cots?
@cots ||= @xml_hash.cots.to_bool
end

def builds
@builds ||= []
if @builds.empty?
if @xml_hash.build.class == Array
@builds = @xml_hash.build.map do |build|
Build.new(build)
end
else
@builds << Build.new(@xml_hash.build)
end
end
return @builds
end
end

class Applications < Base
xml_reader :applications, :as => [Application]
def applications
@applications ||= []
if @applications.empty?
@applications = @xml_hash.applicationbuilds.application.map do |application|
Application.new(application)
end
end
end
end

end
Expand Down
197 changes: 144 additions & 53 deletions lib/veracode/api/detailed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,165 @@
module Veracode
module Result
class CWE < Base
xml_reader :cweid, :from => "@cweid"
xml_reader :cwename, :from => "@cwename"
xml_reader :pcirelated?, :from => "@pcirelated"
api_field :cweid, :tag => :cweid
api_field :cwename, :tag => :cwename

xml_reader :description, :as => [TextType]
xml_reader :staticflaws, :as => Flaws
xml_reader :dynamicflaws, :as => Flaws
xml_reader :manualflaws, :as => Flaws
def pcirelated?
@pcirelated ||= @xml_hash.pcirelated.to_bool
end

def description
@xml_hash.description.text.text
end

api_type_field :manualflaws, :tag => :manualflaws, :as => Flaws
api_type_field :dynamicflaws, :tag => :dynamicflaws, :as => Flaws
api_type_field :staticflaws, :tag => :staticflaws, :as => Flaws

end

class Category < Base
xml_reader :categoryid, :from => "@categoryid"
xml_reader :categoryname, :from => "@categoryname"
xml_reader :pcirelated?, :from => "pcirelated"
class Category < Base
api_field :categoryid, :tag => :categoryid
api_field :categoryname, :tag => :categoryname
api_type_field :desc, :tag => :desc, :as => Para
api_type_field :recommendations, :tag => :recommendations, :as => Para

def pcirelated?
@pcirelated ||= @xml_hash.pcirelated.to_bool
end

xml_reader :desc, :as => Para
xml_reader :recommendations, :as => Para
xml_reader :cwe, :as => [CWE]
def description
temp = self.desc.para.map do |para|
para.text
end

self.desc.para.map do |para|
if !para.bulletitem.nil?
x = para.bulletitem.each.map do |item|
"* " + item.text + "\r\n"
end
end
temp << x.join
end

return temp.join("\r\n\r\n").strip
end

def recommendation
temp = self.recommendations.para.map do |para|
para.text
end

self.recommendations.para.map do |para|
if !para.bulletitem.nil?
x = para.bulletitem.each.map do |item|
"* " + item.text + "\r\n"
end
end
temp << x.join
end

return temp.join("\r\n\r\n").strip
end

def cwe
@cwe ||= []
begin
if @cwe.empty?
if @xml_hash.cwe.class == Array
@cwe = @xml_hash.cwe.map do |c|
CWE.new(c)
end
else
@cwe << CWE.new(@xml_hash.cwe)
end
end
rescue NoMethodError
end

return @cwe
end
end

class Severity < Base
xml_reader :level, :from => "@level"
api_field :level, :tag => :level

xml_reader :categories, :as => [Category]
def categories
@categories ||= []
begin
if @categories.empty?
if @xml_hash.category.class == Array
@categories = @xml_hash.category.map do |sev|
Category.new(sev)
end
else
@categories << Category.new(@xml_hash.category)
end
end
rescue NoMethodError
end

return @categories
end
end

class DetailedReport < Base
xml_convention :dasherize

xml_reader :report_format_version, :from => "@report_format_version"
xml_reader :app_name, :from => "@app_name"
xml_reader :app_id, :from => "@app_id"
xml_reader :first_build_submitted_date, :from => "@first_build_submitted_date"
xml_reader :version, :from => "@version"
xml_reader :build_id, :from => "@build_id"
xml_reader :submitter, :from => "@submitter"
xml_reader :vendor, :from => "@vendor"
xml_reader :platform, :from => "@platform"
xml_reader :assurance_level, :from => "@assurance_level"
xml_reader :business_criticality, :from => "@business_criticality"
xml_reader :generation_date, :from => "@generation_date"
xml_reader :veracode_level, :from => "@veracode_level"
xml_reader :total_flaws, :from => "@total_flaws"
xml_reader :flaws_not_mitigated, :from => "@flaws_not_mitigated"
xml_reader :teams, :from => "@teams"
xml_reader :life_cycle_stage, :from => "@life_cycle_stage"
xml_reader :planned_deployment_date, :from => "@planned_deployment_date"
xml_reader :last_update_time, :from => "@last_update_time"
xml_reader :is_latest_build?, :from => "@is_latest_build"
xml_reader :policy_name, :from => "@policy_name"
xml_reader :policy_version, :from => "@policy_version"
xml_reader :policy_compliance_status, :from => "@policy_compliance_status"
xml_reader :policy_rules_status, :from => "@policy_rules_status"
xml_reader :scan_overdue, :from => "@scan_overdue"
xml_reader :any_type_scan_due, :from => "@any_type_scan_due"
xml_reader :business_owner, :from => "@business_owner"
xml_reader :business_unit, :from => "@business_unit"
xml_reader :tags, :from => "@tags"
xml_reader :grace_period_expired?, :from => "@grace_period_expired"

api_field :report_format_version, :tag => :report_format_version
api_field :app_name, :tag => :app_name
api_field :app_id, :tag => :app_id
api_field :first_build_submitted_date, :tag => :first_build_submitted_date
api_field :version, :tag => :version
api_field :build_id, :tag => :build_id
api_field :submitter, :tag => :submitter
api_field :vendor, :tag => :vendor
api_field :platform, :tag => :platform
api_field :assurance_level, :tag => :assurance_level
api_field :business_criticality, :tag => :business_criticality
api_field :generation_date, :tag => :generation_date
api_field :veracode_level, :tag => :veracode_level
api_field :total_flaws, :tag => :total_flaws
api_field :flaws_not_mitigated, :tag => :flaws_not_mitigated
api_field :teams, :tag => :teams
api_field :life_cycle_stage, :tag => :life_cycle_stage
api_field :planned_deployment_date, :tag => :planned_deployment_date
api_field :last_update_time, :tag => :last_update_time
api_field :policy_name, :tag => :policy_name
api_field :policy_version, :tag => :policy_version
api_field :policy_compliance_status, :tag => :policy_compliance_status
api_field :policy_rules_status, :tag => :policy_rules_status
api_field :scan_overdue, :tag => :scan_overdue
api_field :any_type_scan_due, :tag => :any_type_scan_due
api_field :business_owner, :tag => :business_owner
api_field :business_unit, :tag => :business_unit
api_field :tags, :tag => :tags

api_type_field :static_analysis, :tag => :static_analysis, :as => Analysis
api_type_field :dynamic_analysis, :tag => :dynamic_analysis, :as => Analysis
api_type_field :manual_analysis, :tag => :manual_analysis, :as => ManualAnalysis
api_type_field :flaw_status, :tag => :flaw_status, :as => FlawStatus

xml_reader :static_analysis, :as => Analysis
xml_reader :dynamic_analysis, :as => Analysis
xml_reader :manual_analysis, :as => ManualAnalysis
def is_latest_build?
@is_latest_build ||= @xml_hash.is_latest_build.to_bool
end

xml_reader :severity, :as => [Severity]
def grace_period_expired?
@grace_period_expired ||= @xml_hash.grace_period_expired.to_bool
end

xml_reader :flaw_status, :as => FlawStatus
def severity
@severity ||= []
if @severity.empty?
if @xml_hash.severity.class == Array
@severity = @xml_hash.severity.map do |sev|
Severity.new(sev)
end
else
@severity << Severity.new(@xml_hash.severity)
end
end
return @severity
end
end

end
Expand Down
Loading

0 comments on commit 9cfca6c

Please sign in to comment.