[ 'method' => 'GET', 'header' => GCECredentials::FLAVOR_HEADER . ': Google' ], ]; $this->context = $this->createStreamContext($options); } /** * Read the metadata for a given path. * * @param string $path The metadata path, relative to `/computeMetadata/v1/`. * @return string */ public function read($path) { $url = sprintf( 'http://%s/computeMetadata/v1/%s', GCECredentials::METADATA_IP, $path ); return $this->getMetadata($url); } /** * Abstracted for testing. * * @param array $options * @return resource * @codeCoverageIgnore */ protected function createStreamContext(array $options) { return stream_context_create($options); } /** * Abstracted for testing. * * @param string $url * @return string * @codeCoverageIgnore */ protected function getMetadata($url) { return file_get_contents($url, false, $this->context); } }