Class: Mihari::Structs::Onyphe::Result

Inherits:
Dry::Struct
  • Object
show all
Includes:
Concerns::AutonomousSystemNormalizable
Defined in:
lib/mihari/structs/onyphe.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::AutonomousSystemNormalizable

#normalize_asn

Instance Attribute Details

#asnString (readonly)

Returns:

  • (String)


11
# File 'lib/mihari/structs/onyphe.rb', line 11

attribute :asn, Types::String

#country_codeString, nll (readonly)

Returns:

  • (String, nll)


15
# File 'lib/mihari/structs/onyphe.rb', line 15

attribute :country_code, Types::String.optional

#ipString (readonly)

Returns:

  • (String)


20
# File 'lib/mihari/structs/onyphe.rb', line 20

attribute :ip, Types::String

#metadataHash (readonly)

Returns:

  • (Hash)


24
# File 'lib/mihari/structs/onyphe.rb', line 24

attribute :metadata, Types::Hash

Class Method Details

.from_dynamic!(d) ⇒ Object

Parameters:

  • d (Hash)


61
62
63
64
65
66
67
68
69
70
# File 'lib/mihari/structs/onyphe.rb', line 61

def from_dynamic!(d)
  d = Types::Hash[d]
  new(
    asn: d.fetch("asn"),
    ip: d.fetch("ip"),
    # Onyphe's country = 2-letter country code
    country_code: d["country"],
    metadata: d
  )
end

Instance Method Details

#artifactMihari::Models::Artifact



29
30
31
32
33
34
35
36
# File 'lib/mihari/structs/onyphe.rb', line 29

def artifact
  Mihari::Models::Artifact.new(
    data: ip,
    metadata:,
    autonomous_system: as,
    geolocation:
  )
end

#asMihari::AutonomousSystem

Returns:

  • (Mihari::AutonomousSystem)


53
54
55
# File 'lib/mihari/structs/onyphe.rb', line 53

def as
  Mihari::Models::AutonomousSystem.new(number: normalize_asn(asn))
end

#geolocationMihari::Geolocation?

Returns:

  • (Mihari::Geolocation, nil)


41
42
43
44
45
46
47
48
# File 'lib/mihari/structs/onyphe.rb', line 41

def geolocation
  return nil if country_code.nil?

  Mihari::Models::Geolocation.new(
    country: NormalizeCountry(country_code, to: :short),
    country_code:
  )
end