Class: SemgrepWebApp::SearchScansRequest

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

Overview

SearchScansRequest Model.

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(deployment_id:, branch: SKIP, cursor: SKIP, is_full_scan: SKIP, limit: SKIP, products: SKIP, repository_id: SKIP, since: SKIP, statuses: SKIP, total_time: SKIP, additional_properties: nil) ⇒ SearchScansRequest

Returns a new instance of SearchScansRequest.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 118

def initialize(deployment_id:, branch: SKIP, cursor: SKIP,
               is_full_scan: SKIP, limit: SKIP, products: SKIP,
               repository_id: SKIP, since: SKIP, statuses: SKIP,
               total_time: SKIP, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @branch = branch unless branch == SKIP
  @cursor = cursor unless cursor == SKIP
  @deployment_id = deployment_id
  @is_full_scan = is_full_scan unless is_full_scan == SKIP
  @limit = limit unless limit == SKIP
  @products = products unless products == SKIP
  @repository_id = repository_id unless repository_id == SKIP
  @since = since unless since == SKIP
  @statuses = statuses unless statuses == SKIP
  @total_time = total_time unless total_time == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#branchString

Only get scans from the specified branch

Returns:

  • (String)


15
16
17
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 15

def branch
  @branch
end

#cursorString

Cursor to paginate through the results

Returns:

  • (String)


19
20
21
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 19

def cursor
  @cursor
end

#deployment_idString

Deployment ID (numeric). Example: 123. Can be found at /deployments, or in your Settings in the web UI.

Returns:

  • (String)


24
25
26
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 24

def deployment_id
  @deployment_id
end

#is_full_scanInteger

Only get scans that are full scans (if false, only get diff scans)

Returns:

  • (Integer)


28
29
30
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 28

def is_full_scan
  @is_full_scan
end

#limitInteger

Page size to paginate through the results (default is 100, max is 500)

Returns:

  • (Integer)


32
33
34
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 32

def limit
  @limit
end

#productsProducts

Only get scans that have these enabled products

value description
PRODUCT_SAST
PRODUCT_SCA
PRODUCT_SECRETS
PRODUCT_AI_SAST

Returns:



42
43
44
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 42

def products
  @products
end

#repository_idInteger

Only get scans for this repo

Returns:

  • (Integer)


46
47
48
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 46

def repository_id
  @repository_id
end

#sinceDateTime

Only get scans created after this time. Provide time in ISO 8601 format.

Returns:

  • (DateTime)


50
51
52
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 50

def since
  @since
end

#statusesStatuses

Only get scans that have one of these statuses

value description
SCAN_STATUS_RUNNING The scan is currently running
SCAN_STATUS_COMPLETED The scan has completed successfully (0 or 1 exit
code)
SCAN_STATUS_PENDING The scan is queued and waiting to start
SCAN_STATUS_CANCELLED The scan was cancelled before completion
SCAN_STATUS_ERROR The scan has exited with a failure (exit code not 0
or 1)
SCAN_STATUS_NEVER_FINISHED The scan did not report an error or success
after over an hour

Returns:



65
66
67
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 65

def statuses
  @statuses
end

#total_timeFloatRange

Only get scans that have one of these statuses

value description
SCAN_STATUS_RUNNING The scan is currently running
SCAN_STATUS_COMPLETED The scan has completed successfully (0 or 1 exit
code)
SCAN_STATUS_PENDING The scan is queued and waiting to start
SCAN_STATUS_CANCELLED The scan was cancelled before completion
SCAN_STATUS_ERROR The scan has exited with a failure (exit code not 0
or 1)
SCAN_STATUS_NEVER_FINISHED The scan did not report an error or success
after over an hour

Returns:



80
81
82
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 80

def total_time
  @total_time
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 139

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  deployment_id = hash.key?('deploymentId') ? hash['deploymentId'] : nil
  branch = hash.key?('branch') ? hash['branch'] : SKIP
  cursor = hash.key?('cursor') ? hash['cursor'] : SKIP
  is_full_scan = hash.key?('is_full_scan') ? hash['is_full_scan'] : SKIP
  limit = hash.key?('limit') ? hash['limit'] : SKIP
  products = hash.key?('products') ? hash['products'] : SKIP
  repository_id = hash.key?('repository_id') ? hash['repository_id'] : SKIP
  since = if hash.key?('since')
            (DateTimeHelper.from_rfc3339(hash['since']) if hash['since'])
          else
            SKIP
          end
  statuses = hash.key?('statuses') ? hash['statuses'] : SKIP
  total_time = FloatRange.from_hash(hash['total_time']) if hash['total_time']

  # 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.
  SearchScansRequest.new(deployment_id: deployment_id,
                         branch: branch,
                         cursor: cursor,
                         is_full_scan: is_full_scan,
                         limit: limit,
                         products: products,
                         repository_id: repository_id,
                         since: since,
                         statuses: statuses,
                         total_time: total_time,
                         additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 83

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['branch'] = 'branch'
  @_hash['cursor'] = 'cursor'
  @_hash['deployment_id'] = 'deploymentId'
  @_hash['is_full_scan'] = 'is_full_scan'
  @_hash['limit'] = 'limit'
  @_hash['products'] = 'products'
  @_hash['repository_id'] = 'repository_id'
  @_hash['since'] = 'since'
  @_hash['statuses'] = 'statuses'
  @_hash['total_time'] = 'total_time'
  @_hash
end

.nullablesObject

An array for nullable fields



114
115
116
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 114

def self.nullables
  []
end

.optionalsObject

An array for optional fields



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 99

def self.optionals
  %w[
    branch
    cursor
    is_full_scan
    limit
    products
    repository_id
    since
    statuses
    total_time
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



193
194
195
196
197
198
199
200
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 193

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} branch: #{@branch.inspect}, cursor: #{@cursor.inspect}, deployment_id:"\
  " #{@deployment_id.inspect}, is_full_scan: #{@is_full_scan.inspect}, limit:"\
  " #{@limit.inspect}, products: #{@products.inspect}, repository_id:"\
  " #{@repository_id.inspect}, since: #{@since.inspect}, statuses: #{@statuses.inspect},"\
  " total_time: #{@total_time.inspect}, additional_properties: #{@additional_properties}>"
end

#to_custom_sinceObject



179
180
181
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 179

def to_custom_since
  DateTimeHelper.to_rfc3339(since)
end

#to_sObject

Provides a human-readable string representation of the object.



184
185
186
187
188
189
190
# File 'lib/semgrep_web_app/models/search_scans_request.rb', line 184

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} branch: #{@branch}, cursor: #{@cursor}, deployment_id: #{@deployment_id},"\
  " is_full_scan: #{@is_full_scan}, limit: #{@limit}, products: #{@products}, repository_id:"\
  " #{@repository_id}, since: #{@since}, statuses: #{@statuses}, total_time: #{@total_time},"\
  " additional_properties: #{@additional_properties}>"
end