Sha256: 62c7dcb349463727eb241499edf49a3c156eb0a16c5e48dbd95e1a8a90b1bc95

Contents?: true

Size: 1.84 KB

Versions: 28

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true

module Mihari
  module Structs
    module BinaryEdge
      class Target < Dry::Struct
        # @!attribute [r] ip
        #   @return [String]
        attribute :ip, Types::String

        class << self
          #
          # @param [Hash] d
          #
          def from_dynamic!(d)
            d = Types::Hash[d]
            new(
              ip: d.fetch("ip")
            )
          end
        end
      end

      class Event < Dry::Struct
        # @!attribute [r] target
        #   @return [Target]
        attribute :target, Target

        class << self
          #
          # @param [Hash] d
          #
          def from_dynamic!(d)
            d = Types::Hash[d]
            new(
              target: Target.from_dynamic!(d.fetch("target"))
            )
          end
        end
      end

      class Response < Dry::Struct
        # @!attribute [r] page
        #   @return [Integer]
        attribute :page, Types::Int

        # @!attribute [r] pagesize
        #   @return [Integer]
        attribute :pagesize, Types::Int

        # @!attribute [r] total
        #   @return [Integer]
        attribute :total, Types::Int

        # @!attribute [r] events
        #   @return [Array<Event>]
        attribute :events, Types.Array(Event)

        #
        # @return [Array<Artifact>]
        #
        def artifacts
          events.map { |event| Models::Artifact.new(data: event.target.ip) }
        end

        class << self
          #
          # @param [Hash] d
          #
          def from_dynamic!(d)
            d = Types::Hash[d]
            new(
              page: d.fetch("page"),
              pagesize: d.fetch("pagesize"),
              total: d.fetch("total"),
              events: d.fetch("events").map { |x| Event.from_dynamic!(x) }
            )
          end
        end
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
mihari-8.0.0 lib/mihari/structs/binaryedge.rb
mihari-7.6.4 lib/mihari/structs/binaryedge.rb
mihari-7.6.3 lib/mihari/structs/binaryedge.rb
mihari-7.6.2 lib/mihari/structs/binaryedge.rb
mihari-7.6.1 lib/mihari/structs/binaryedge.rb
mihari-7.6.0 lib/mihari/structs/binaryedge.rb
mihari-7.5.0 lib/mihari/structs/binaryedge.rb
mihari-7.4.0 lib/mihari/structs/binaryedge.rb
mihari-7.3.2 lib/mihari/structs/binaryedge.rb
mihari-7.3.1 lib/mihari/structs/binaryedge.rb
mihari-7.3.0 lib/mihari/structs/binaryedge.rb
mihari-7.2.0 lib/mihari/structs/binaryedge.rb
mihari-7.1.3 lib/mihari/structs/binaryedge.rb
mihari-7.1.2 lib/mihari/structs/binaryedge.rb
mihari-7.1.1 lib/mihari/structs/binaryedge.rb
mihari-7.1.0 lib/mihari/structs/binaryedge.rb
mihari-7.0.5 lib/mihari/structs/binaryedge.rb
mihari-7.0.4 lib/mihari/structs/binaryedge.rb
mihari-7.0.3 lib/mihari/structs/binaryedge.rb
mihari-7.0.2 lib/mihari/structs/binaryedge.rb