google_cloud library

Utilities for running Dart code correctly on the Google Cloud Platform.

This library exports both general and http_serving.

Classes

RequestLogger
Allows logging at a specified severity.

Properties

badRequestMiddleware → Middleware
Adds logic which catches BadRequestException, logs details to stderr and returns a corresponding Response.
no setter
currentLogger RequestLogger
Returns the current RequestLogger.
no setter
gceMetadataHost String
Returns the host for the GCE metadata server.
no setter

Functions

cloudLoggingMiddleware(String projectId) → Middleware
Return Middleware that logs errors using Google Cloud structured logs and returns the correct response.
computeProjectId({Client? client, bool refresh = false}) Future<String>
A convenience wrapper that tries multiple strategies to find the project ID, prioritizing local development strategies over cloud discovery.
createLoggingMiddleware({String? projectId}) → Middleware
Convenience Middleware that handles logging depending on projectId.
fetchMetadataValue(String path, {Client? client, Duration timeout = const Duration(seconds: 3)}) Future<String>
Retrieves a value from the GCE metadata server without caching the result.
gceMetadataUrl(String path) Uri
Returns a Uri for the given path on the GCE metadata server.
getMetadataValue(String path, {Client? client, Duration timeout = const Duration(seconds: 3), bool refresh = false}) Future<String>
Retrieves a value from the GCE metadata server.
listenPortFromEnvironment() int
Returns the port to listen on from environment variable or uses the default 8080.
projectIdFromCredentialsFile() String?
Returns the Project ID for the current Google Cloud Project by reading the project_id field from the credentials JSON file specified by the GOOGLE_APPLICATION_CREDENTIALS environment variable.
projectIdFromEnvironmentVariables() String?
Returns the Project ID for the current Google Cloud Project by checking the environment variables in projectIdEnvironmentVariableOptions.
projectIdFromGcloudConfig() Future<String?>
Returns a Future that completes with the Project ID for the current Google Cloud Project by querying the gcloud CLI configuration.
projectIdFromMetadataServer({Client? client, bool refresh = false}) Future<String>
Returns a Future that completes with the Project ID for the current Google Cloud Project by checking project metadata.
serveHandler(Handler handler) Future<void>
Serves handler on InternetAddress.anyIPv4 using the port returned by listenPortFromEnvironment.
serviceAccountEmailFromMetadataServer({Client? client, bool refresh = false}) Future<String>
A convenience wrapper that tries to retrieve the default service account email from the Metadata Server.
structuredLogEntry(Object message, LogSeverity severity, {String? traceId, StackTrace? stackTrace}) String
Creates a JSON-encoded log entry that conforms with structured logs.
waitForTerminate() Future<void>
Returns a Future that completes when the process receives a ProcessSignal requesting a shutdown.

Exceptions / Errors

BadConfigurationException
Thrown if a service is configured incorrectly.
BadRequestException
When thrown in a Handler, configured with badRequestMiddleware or similar, causes a response with statusCode to be returned.
MetadataServerException
Exception thrown when accessing the GCE metadata server fails.