GCP Context Detection
Detect the currently active Google Cloud project and authenticated account.
Purpose
Provides the necessary context for subsequent gcloud commands by identifying the active project ID and user account.
Inputs
None.
Behavior
- •Run
gcloud config get-value projectto retrieve the active project ID. - •Run
gcloud config get-value accountto retrieve the active account email. - •Verify if a project is set; if not, suggest the user to set one using
gcloud config set project [PROJECT_ID]. - •Verify if an account is authenticated; if not, suggest
gcloud auth login. - •Check for ADC (Application Default Credentials) if running in a non-interactive environment.
Output
Returns a JSON object containing projectId and account.
json
{
"projectId": "my-project-id",
"account": "user@example.com"
}