Class: Threatstack::Utils::Aws

Inherits:
Object
  • Object
show all
Includes:
Singleton, Constants
Defined in:
lib/utils/aws_utils.rb

Constant Summary

Constants included from Constants

Constants::AGENT_ID, Constants::AGENT_INSTANCE_ID, Constants::AGENT_NAME, Constants::AGENT_VERSION, Constants::APPSEC_BASE_URL, Constants::APPSEC_EVENTS_URL, Constants::ATTACK, Constants::AWS_METADATA_URL, Constants::BLOCK_PATH_TRAVERSAL, Constants::BLOCK_SQLI, Constants::BLOCK_XSS, Constants::CGI_VARIABLES, Constants::DEPENDENCIES, Constants::DETECTED_NOT_BLOCKED, Constants::DETECT_ATTACKS_ONLY, Constants::DETECT_PATH_TRAVERSAL, Constants::DISABLED, Constants::DROP_FIELDS, Constants::ENVIRONMENT, Constants::EVENTS_PER_REQ, Constants::FILTER_BY_PATH, Constants::INSTRUMENTATION, Constants::IPV4, Constants::IPV6, Constants::JOB_INTERVAL, Constants::LOG_COLORS, Constants::LOG_LEVEL, Constants::MANUAL_INIT, Constants::MAX_QUEUED_EVENTS, Constants::PATH_TRAVERSAL, Constants::REDACTED, Constants::REQUEST_BLOCKED, Constants::ROOT_DIR, Constants::RUBY, Constants::SQLI, Constants::TRUTHY, Constants::XSS

Instance Method Summary collapse

Methods included from Constants

app_root_dir, env, is_truthy

Constructor Details

#initializeAws



14
15
16
# File 'lib/utils/aws_utils.rb', line 14

def initialize
  @logger = Threatstack::Utils::TSLogger.create 'AwsUtils'
end

Instance Method Details

#get_aws_metadataObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/utils/aws_utils.rb', line 18

def 
   = {}
  timeout = 5 # secs

  begin
    # prepare request
    @logger.debug 'Preparing request to fetch AWS metadata'
    aws_uri = URI()
    http = Net::HTTP.new(aws_uri.host, aws_uri.port)
    http.open_timeout = timeout
    http.read_timeout = timeout
    # http.keep_alive_timeout = 2
    req = Net::HTTP::Get.new(aws_uri.path)
    # fire request
    @logger.debug 'Firing request to fetch AWS metadata'
    resp = http.request(req)
    @logger.debug "AWS metadata request HTTP code #{resp.code} and response: #{resp.body}"
    # convert response to hash
     = resp.body ? JSON.parse(resp.body) : 
  rescue StandardError => e
    @logger.error "StandardError: #{e.inspect}"
  end

  # return
  
end