Code Monkey home page Code Monkey logo

Comments (1)

nvwls avatar nvwls commented on September 18, 2024

The issue is that the top-level object never changes because of the trailing ?recursive=true

The calls will be:
/computeMetadata/v1/?recursive=true/
/computeMetadata/v1/?recursive=true/instance/
/computeMetadata/v1/?recursive=true/instance/instance/
and so on

diff --git lib/ohai/mixin/gce_metadata.rb lib/ohai/mixin/gce_metadata.rb
index 64b35f92..29725c3b 100644
--- lib/ohai/mixin/gce_metadata.rb
+++ lib/ohai/mixin/gce_metadata.rb
@@ -23,7 +23,7 @@ module Ohai
 
       # Trailing dot to host is added to avoid DNS search path
       GCE_METADATA_ADDR ||= "metadata.google.internal."
-      GCE_METADATA_URL ||= "/computeMetadata/v1/?recursive=true"
+      GCE_METADATA_URL ||= "/computeMetadata/v1"
 
       # fetch the meta content with a timeout and the required header
       def http_get(uri)
@@ -36,7 +36,9 @@ module Ohai
       end
 
       def fetch_metadata(id = "")
-        response = http_get("#{GCE_METADATA_URL}/#{id}")
+        url = "#{GCE_METADATA_URL}/#{id}"
+        url << "?recursive=true" if url.end_with?("/")
+        response = http_get(url)
         return nil unless response.code == "200"
 
         if json?(response.body)

from ohai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.