Class: SemgrepWebApp::FoundDependency

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/semgrep_web_app/models/found_dependency.rb

Overview

Information about the vulnerable package that was found in the codebase

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(ecosystem: Ecosystem2::NO_PACKAGE_MANAGER, lockfile_line_url: SKIP, package: SKIP, transitivity: SKIP, version: SKIP, additional_properties: nil) ⇒ FoundDependency

Returns a new instance of FoundDependency.



59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/semgrep_web_app/models/found_dependency.rb', line 59

def initialize(ecosystem: Ecosystem2::NO_PACKAGE_MANAGER,
               lockfile_line_url: SKIP, package: SKIP, transitivity: SKIP,
               version: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @ecosystem = ecosystem unless ecosystem == SKIP
  @lockfile_line_url = lockfile_line_url unless lockfile_line_url == SKIP
  @package = package unless package == SKIP
  @transitivity = transitivity unless transitivity == SKIP
  @version = version unless version == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#ecosystemEcosystem2

Ecosystem of the package

Returns:



14
15
16
# File 'lib/semgrep_web_app/models/found_dependency.rb', line 14

def ecosystem
  @ecosystem
end

#lockfile_line_urlString

URL to the specific line in the lockfile where the dependency is listed

Returns:

  • (String)


18
19
20
# File 'lib/semgrep_web_app/models/found_dependency.rb', line 18

def lockfile_line_url
  @lockfile_line_url
end

#packageString

Name of the package that contains the vulnerability

Returns:

  • (String)


22
23
24
# File 'lib/semgrep_web_app/models/found_dependency.rb', line 22

def package
  @package
end

#transitivityTransitivity2

Indicates whether the dependency is direct or transitive

Returns:



26
27
28
# File 'lib/semgrep_web_app/models/found_dependency.rb', line 26

def transitivity
  @transitivity
end

#versionString

Version of the package that was found to be vulnerable

Returns:

  • (String)


30
31
32
# File 'lib/semgrep_web_app/models/found_dependency.rb', line 30

def version
  @version
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/semgrep_web_app/models/found_dependency.rb', line 74

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  ecosystem = hash['ecosystem'] ||= Ecosystem2::NO_PACKAGE_MANAGER
  lockfile_line_url =
    hash.key?('lockfile_line_url') ? hash['lockfile_line_url'] : SKIP
  package = hash.key?('package') ? hash['package'] : SKIP
  transitivity = hash.key?('transitivity') ? hash['transitivity'] : SKIP
  version = hash.key?('version') ? hash['version'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  FoundDependency.new(ecosystem: ecosystem,
                      lockfile_line_url: lockfile_line_url,
                      package: package,
                      transitivity: transitivity,
                      version: version,
                      additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



33
34
35
36
37
38
39
40
41
# File 'lib/semgrep_web_app/models/found_dependency.rb', line 33

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['ecosystem'] = 'ecosystem'
  @_hash['lockfile_line_url'] = 'lockfile_line_url'
  @_hash['package'] = 'package'
  @_hash['transitivity'] = 'transitivity'
  @_hash['version'] = 'version'
  @_hash
end

.nullablesObject

An array for nullable fields



55
56
57
# File 'lib/semgrep_web_app/models/found_dependency.rb', line 55

def self.nullables
  []
end

.optionalsObject

An array for optional fields



44
45
46
47
48
49
50
51
52
# File 'lib/semgrep_web_app/models/found_dependency.rb', line 44

def self.optionals
  %w[
    ecosystem
    lockfile_line_url
    package
    transitivity
    version
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (FoundDependency | Hash)

    value against the validation is performed.



103
104
105
106
107
108
109
# File 'lib/semgrep_web_app/models/found_dependency.rb', line 103

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



120
121
122
123
124
125
126
# File 'lib/semgrep_web_app/models/found_dependency.rb', line 120

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} ecosystem: #{@ecosystem.inspect}, lockfile_line_url:"\
  " #{@lockfile_line_url.inspect}, package: #{@package.inspect}, transitivity:"\
  " #{@transitivity.inspect}, version: #{@version.inspect}, additional_properties:"\
  " #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



112
113
114
115
116
117
# File 'lib/semgrep_web_app/models/found_dependency.rb', line 112

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} ecosystem: #{@ecosystem}, lockfile_line_url: #{@lockfile_line_url},"\
  " package: #{@package}, transitivity: #{@transitivity}, version: #{@version},"\
  " additional_properties: #{@additional_properties}>"
end