lib/mihari/analyzers/censys.rb in mihari-0.9.0 vs lib/mihari/analyzers/censys.rb in mihari-0.9.1

- old
+ new

@@ -3,11 +3,10 @@ require "censu" module Mihari module Analyzers class Censys < Base - attr_reader :api attr_reader :title attr_reader :description attr_reader :query attr_reader :tags @@ -15,13 +14,10 @@ CENSYS_SECRET_KEY = "CENSYS_SECRET" def initialize(query, title: nil, description: nil, tags: []) super() - raise ArgumentError, "#{CENSYS_ID_KEY} and #{CENSYS_SECRET_KEY} are required" unless valid? - - @api = ::Censys::API.new @query = query @title = title || "Censys lookup" @description = description || "query = #{query}" @tags = tags end @@ -35,21 +31,29 @@ ipv4s end # @return [true, false] + def valid? + censys_id? && censys_secret? + end + + private + + # @return [true, false] def censys_id? ENV.key? CENSYS_ID_KEY end # @return [true, false] def censys_secret? ENV.key? CENSYS_SECRET_KEY end - # @return [true, false] - def valid? - censys_id? && censys_secret? + def api + raise ArgumentError, "#{CENSYS_ID_KEY} and #{CENSYS_SECRET_KEY} are required" unless valid? + + @api ||= ::Censys::API.new end end end end