lib/ohai/mixin/ec2_metadata.rb in ohai-18.1.0 vs lib/ohai/mixin/ec2_metadata.rb in ohai-18.1.3
- old
+ new
@@ -18,10 +18,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.
require "net/http" unless defined?(Net::HTTP)
+require_relative "../mixin/json_helper"
+include Ohai::Mixin::JsonHelper
+
module Ohai
module Mixin
##
# This code parses the EC2 Instance Metadata API to provide details
# of the running instance.
@@ -227,12 +230,17 @@
def fetch_dynamic_data
@fetch_dynamic_data ||= begin
response = http_client.get("/#{best_api_version}/dynamic/instance-identity/document/", { 'X-aws-ec2-metadata-token': v2_token })
- if json?(response.body) && response.code == "200"
- FFI_Yajl::Parser.parse(response.body)
+ if response.code == "200"
+ json_data = parse_json(response.body, {})
+ if json_data.nil?
+ logger.warn("Mixin Ec2Metadata: Metadata response is NOT valid JSON")
+ end
+ json_data
else
+ logger.warn("Mixin Ec2Metadata: Received response code #{response.code} requesting metadata")
{}
end
end
end