Class: Site

Inherits:
Domain::Model show all
Defined in:
lib/domain/site/model.rb

Overview

The Site class represents a site in the system, containing various attributes and methods related to site management and identification.

Constant Summary collapse

UTR_PATTERN =
/:UTR\d{5}$/
NETWORK_DISCOVERY_PATTERN =
/Network Discovery Scan/
CMDB_VULNERABILITY_PATTERN =
/Vulnerability Scan/

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Domain::Model

columns, from_csv, from_json, headers, #initialize, primary_key, table_name, #to_csv, #to_hash, view

Constructor Details

This class inherits a constructor from Domain::Model

Instance Attribute Details

#assetsObject

Returns the value of attribute assets.



14
15
16
# File 'lib/domain/site/model.rb', line 14

def assets
  @assets
end

#descriptionObject

Returns the value of attribute description.



14
15
16
# File 'lib/domain/site/model.rb', line 14

def description
  @description
end

#idObject

Returns the value of attribute id.



14
15
16
# File 'lib/domain/site/model.rb', line 14

def id
  @id
end

#nameObject

Returns the value of attribute name.



14
15
16
# File 'lib/domain/site/model.rb', line 14

def name
  @name
end

#risk_scoreObject

Returns the value of attribute risk_score.



14
15
16
# File 'lib/domain/site/model.rb', line 14

def risk_score
  @risk_score
end

#scan_engineObject

Returns the value of attribute scan_engine.



14
15
16
# File 'lib/domain/site/model.rb', line 14

def scan_engine
  @scan_engine
end

#scan_templateObject

Returns the value of attribute scan_template.



14
15
16
# File 'lib/domain/site/model.rb', line 14

def scan_template
  @scan_template
end

Instance Method Details

#cmdb_discovery?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/domain/site/model.rb', line 66

def cmdb_discovery?
  utr?
end

#cmdb_vulnerability?Boolean

return true if the site name contains only 2 colons (:) and it is not a cmdb_discovery?

Returns:

  • (Boolean)


73
74
75
76
77
# File 'lib/domain/site/model.rb', line 73

def cmdb_vulnerability?
  return false if cmdb_discovery?

  name =~ CMDB_VULNERABILITY_PATTERN && name.count(':') == 2
end

#country_codeObject



44
45
46
47
48
49
# File 'lib/domain/site/model.rb', line 44

def country_code
  return nil unless utr?

  matches = name.match(/^:(.*?):/)
  matches ? matches[1] : nil
end

#country_discovery?Boolean

return true if the site name contains Network Discovery Scan (2024)

Returns:

  • (Boolean)


62
63
64
# File 'lib/domain/site/model.rb', line 62

def country_discovery?
  name =~ NETWORK_DISCOVERY_PATTERN
end

#scan_template_idObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/domain/site/model.rb', line 26

def scan_template_id
  return nil unless utr?

  if name.include?(':za:')
    # settings[:za_full_audit]
    '_-sa-ca-_100_-_-pps_min-2000-_-max-15000-_--_-full-audit-without-web-spider'
  else
    # settings[:ar_full_audit]
    '_-angola-ca-_100_-_-pps_min-450-_-max-450-_--_-full-audit-without-web-spider-copy'
  end
end

#time_zone(country_code) ⇒ Object

returns the time_zone from the 2-letter country code



40
41
42
# File 'lib/domain/site/model.rb', line 40

def time_zone(country_code)
  # {'a'}
end

#to_sObject



22
23
24
# File 'lib/domain/site/model.rb', line 22

def to_s
  [id, name, scan_engine, scan_template].join ','
end

#utr?Boolean

returns true if the site ends with :UTR followed by 5 digits

Returns:

  • (Boolean)


57
58
59
# File 'lib/domain/site/model.rb', line 57

def utr?
  name =~ UTR_PATTERN
end

#utr_digitsObject



51
52
53
54
# File 'lib/domain/site/model.rb', line 51

def utr_digits
  digits = name.match(UTR_PATTERN)
  digits ? digits[1].to_i : 0
end