class Facter::Resolvers::Ec2
Constants
- EC2_METADATA_ROOT_URL
- EC2_SESSION_TIMEOUT
- EC2_USERDATA_ROOT_URL
Private Class Methods
Source
# File lib/facter/resolvers/ec2.rb, line 47 def build_path_component(line) array_match = /^(\d+)=.*$/.match(line) array_match ? "#{array_match[1]}/" : line.strip end
Source
# File lib/facter/resolvers/ec2.rb, line 58 def determine_session_timeout session_env = ENV['EC2_SESSION_TIMEOUT'] session_env ? session_env.to_i : EC2_SESSION_TIMEOUT end
Source
# File lib/facter/resolvers/ec2.rb, line 52 def get_data_from(url) headers = {} headers['X-aws-ec2-metadata-token'] = v2_token if v2_token Facter::Util::Resolvers::Http.get_request(url, headers, { session: determine_session_timeout }, false) end
Source
# File lib/facter/resolvers/ec2.rb, line 15 def post_resolve(fact_name, _options) log.debug('Querying Ec2 metadata') @fact_list.fetch(fact_name) { read_facts(fact_name) } end
Source
# File lib/facter/resolvers/ec2.rb, line 27 def query_for_metadata(url, container) metadata = get_data_from(url) metadata.each_line do |line| next if line.empty? http_path_component = build_path_component(line) next if http_path_component == 'security-credentials/' if http_path_component.end_with?('/') child = {} child[http_path_component] = query_for_metadata("#{url}#{http_path_component}", child) child.reject! { |key, _info| key == http_path_component } name = http_path_component.chomp('/') container[name] = child else container[http_path_component] = get_data_from("#{url}#{http_path_component}").strip end end end
Source
# File lib/facter/resolvers/ec2.rb, line 20 def read_facts(fact_name) @fact_list[:metadata] = {} query_for_metadata(EC2_METADATA_ROOT_URL, @fact_list[:metadata]) @fact_list[:userdata] = get_data_from(EC2_USERDATA_ROOT_URL).strip.force_encoding('UTF-8') @fact_list[fact_name] end
Source
# File lib/facter/resolvers/ec2.rb, line 63 def v2_token @v2_token ||= begin token = Facter::Util::Resolvers::AwsToken.get token == '' ? nil : token end end