projectIdFromMetadataServer function

Future<String> projectIdFromMetadataServer({
  1. Client? client,
  2. bool refresh = false,
})

Returns a Future that completes with the Project ID for the current Google Cloud Project by checking project metadata.

The result is cached for the lifetime of the Dart process. Subsequent calls return the cached value without performing discovery again.

If client is provided, it is used to make the request to the metadata server.

If refresh is true, the cache is cleared and the value is re-computed.

If the metadata server cannot be contacted or returns a non-200 status code, a MetadataServerException is thrown.

Implementation

Future<String> projectIdFromMetadataServer({
  http.Client? client,
  bool refresh = false,
}) async =>
    getMetadataValue('project/project-id', client: client, refresh: refresh);