4b6817381b
CI (OpenClaw E2E) / openclaw test (push) Has been cancelled
CI / coverage-report (push) Has been cancelled
CI / test-kubernetes (push) Has been cancelled
CI / should-run-thorough (push) Has been cancelled
CI / test-thorough (cloudwatch-demo) (push) Has been cancelled
CI / test-thorough (flink-ecs) (push) Has been cancelled
CI / test-thorough (upstream-lambda) (push) Has been cancelled
CI / test-thorough (prefect-ecs-fargate) (push) Has been cancelled
Release / build-binaries (zip, opensre.exe, onefile, windows-latest, windows-x64) (push) Has been cancelled
Benchmark image — build + push to ECR (any adapter) / build + push (push) Has been cancelled
CI / quality (ubuntu-latest) (push) Has been cancelled
CI / test (tools-runtime) (push) Has been cancelled
CI / test (e2e-general) (push) Has been cancelled
CI / test (cli-runtime) (push) Has been cancelled
CI / test (e2e-provider-and-openclaw) (push) Has been cancelled
CI / test (integrations-and-misc) (push) Has been cancelled
Release / verify (push) Has been cancelled
Release / build-python-dist (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-15-intel, darwin-x64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, macos-latest, darwin-arm64) (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04, linux-x64) (push) Has been cancelled
Release / publish-release (push) Has been cancelled
Release / publish-main-release (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-checks (no-LLM) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
Interactive Shell Live (PR + post-merge) / turn-live shard ${{ matrix.shard_index }} (push) Has been cancelled
Release / prepare (push) Has been cancelled
Release / build-binaries (tar.gz, opensre, onedir, ubuntu-22.04-arm, linux-arm64) (push) Has been cancelled
Synthetic Deterministic Tests / Synthetic offline (deterministic) (push) Has been cancelled
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
"""Environment validation helpers for agent clients."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from typing import Any
|
|
|
|
|
|
def _missing_env_error(
|
|
missing: list[str], *, context: str, hint: str | None = None
|
|
) -> dict[str, Any]:
|
|
error = f"Missing required environment variables for {context}: {', '.join(missing)}"
|
|
payload: dict[str, Any] = {
|
|
"success": False,
|
|
"error": error,
|
|
"missing_env": missing,
|
|
"context": context,
|
|
}
|
|
if hint:
|
|
payload["hint"] = hint
|
|
return payload
|
|
|
|
|
|
def make_boto3_client(service: str):
|
|
"""Return a boto3 client for the given service using the configured AWS region."""
|
|
try:
|
|
import boto3 as _boto3
|
|
except ImportError:
|
|
return None
|
|
return _boto3.client(service, region_name=os.getenv("AWS_REGION", "us-east-1")) # type: ignore[call-overload]
|
|
|
|
|
|
def require_aws_credentials(*, context: str) -> dict[str, Any] | None:
|
|
try:
|
|
import boto3
|
|
except ImportError:
|
|
return {
|
|
"success": False,
|
|
"error": "boto3 not available",
|
|
"context": context,
|
|
}
|
|
|
|
session = boto3.session.Session()
|
|
credentials = session.get_credentials()
|
|
if credentials is not None:
|
|
return None
|
|
|
|
missing: list[str] = []
|
|
if not os.getenv("AWS_ACCESS_KEY_ID"):
|
|
missing.append("AWS_ACCESS_KEY_ID")
|
|
if not os.getenv("AWS_SECRET_ACCESS_KEY"):
|
|
missing.append("AWS_SECRET_ACCESS_KEY")
|
|
|
|
hint = (
|
|
"Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY (and AWS_SESSION_TOKEN if needed), "
|
|
"or configure an IAM role for this runtime."
|
|
)
|
|
if not missing:
|
|
missing = ["AWS_ACCESS_KEY_ID", "AWS_SECRET_ACCESS_KEY"]
|
|
return _missing_env_error(missing, context=context, hint=hint)
|