api-everything 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- api_everything/__init__.py +3 -0
- api_everything/__main__.py +8 -0
- api_everything/check.py +168 -0
- api_everything/chrome_cmd.py +131 -0
- api_everything/cli.py +803 -0
- api_everything/config.py +321 -0
- api_everything/delivery.py +518 -0
- api_everything/delivery_git.py +94 -0
- api_everything/driver/__init__.py +37 -0
- api_everything/driver/attach.py +95 -0
- api_everything/driver/base.py +80 -0
- api_everything/driver/chrome.py +127 -0
- api_everything/driver/profile.py +84 -0
- api_everything/engine.py +381 -0
- api_everything/errors.py +23 -0
- api_everything/hooks.py +52 -0
- api_everything/login.py +95 -0
- api_everything/mcp_bridge.py +249 -0
- api_everything/metrics.py +87 -0
- api_everything/mock_site/__init__.py +5 -0
- api_everything/mock_site/__main__.py +18 -0
- api_everything/mock_site/app.py +262 -0
- api_everything/pipeline.py +934 -0
- api_everything/pool.py +553 -0
- api_everything/ratelimit.py +67 -0
- api_everything/recipe/__init__.py +6 -0
- api_everything/recipe/actions.py +56 -0
- api_everything/recipe/jsonpath.py +22 -0
- api_everything/recipe/loader.py +142 -0
- api_everything/recipe/params.py +120 -0
- api_everything/recipe/schema.py +235 -0
- api_everything/recipes/alignmentforum/feed.yaml +15 -0
- api_everything/recipes/alpine_docs/search.yaml +32 -0
- api_everything/recipes/angular_docs/search.yaml +32 -0
- api_everything/recipes/anthropic_status/summary.yaml +17 -0
- api_everything/recipes/apis_guru/providers.yaml +15 -0
- api_everything/recipes/arbeitnow/jobs.yaml +20 -0
- api_everything/recipes/arin_rdap/ip.yaml +24 -0
- api_everything/recipes/artifacthub/browse.yaml +22 -0
- api_everything/recipes/artifacthub/search.yaml +24 -0
- api_everything/recipes/astro_docs/search.yaml +32 -0
- api_everything/recipes/atlassian_status/summary.yaml +17 -0
- api_everything/recipes/babel_docs/search.yaml +32 -0
- api_everything/recipes/binance/price.yaml +24 -0
- api_everything/recipes/bugzilla/bugs.yaml +24 -0
- api_everything/recipes/bundlephobia/size.yaml +24 -0
- api_everything/recipes/caddy_docs/search.yaml +32 -0
- api_everything/recipes/caniuse/search.yaml +24 -0
- api_everything/recipes/capacitor_docs/search.yaml +32 -0
- api_everything/recipes/cdnjs/library.yaml +22 -0
- api_everything/recipes/cdnjs/search.yaml +27 -0
- api_everything/recipes/certspotter/issuances.yaml +27 -0
- api_everything/recipes/cheerio_docs/search.yaml +32 -0
- api_everything/recipes/circleci_status/summary.yaml +17 -0
- api_everything/recipes/cisa_kev/catalog.yaml +17 -0
- api_everything/recipes/civitai/models.yaml +26 -0
- api_everything/recipes/cloudflare_status/summary.yaml +17 -0
- api_everything/recipes/cncf_landscape/projects.yaml +20 -0
- api_everything/recipes/cncf_landscape/ui.yaml +18 -0
- api_everything/recipes/coinbase/rates.yaml +24 -0
- api_everything/recipes/coingecko/trending.yaml +17 -0
- api_everything/recipes/conda_forge/package.yaml +25 -0
- api_everything/recipes/crates/categories.yaml +15 -0
- api_everything/recipes/crates/downloads.yaml +22 -0
- api_everything/recipes/crates/keywords.yaml +15 -0
- api_everything/recipes/crates/reverse_deps.yaml +22 -0
- api_everything/recipes/crates/search.yaml +24 -0
- api_everything/recipes/crates/summary.yaml +15 -0
- api_everything/recipes/crates/user.yaml +22 -0
- api_everything/recipes/crates/versions.yaml +22 -0
- api_everything/recipes/crossref/works.yaml +24 -0
- api_everything/recipes/cve_org/record.yaml +24 -0
- api_everything/recipes/debian_sources/search.yaml +24 -0
- api_everything/recipes/deps_dev/npm_spa.yaml +22 -0
- api_everything/recipes/deps_dev/package.yaml +23 -0
- api_everything/recipes/devdocs/index.yaml +18 -0
- api_everything/recipes/devto/articles.yaml +26 -0
- api_everything/recipes/devto/latest.yaml +18 -0
- api_everything/recipes/devto/tags.yaml +18 -0
- api_everything/recipes/devto/top.yaml +18 -0
- api_everything/recipes/digitalocean_status/summary.yaml +17 -0
- api_everything/recipes/digitalocean_status/ui.yaml +15 -0
- api_everything/recipes/discord_status/summary.yaml +17 -0
- api_everything/recipes/dns_google/resolve.yaml +24 -0
- api_everything/recipes/drizzle_docs/search.yaml +32 -0
- api_everything/recipes/echojs/latest.yaml +17 -0
- api_everything/recipes/ecosystems/package.yaml +25 -0
- api_everything/recipes/endoflife/product.yaml +24 -0
- api_everything/recipes/epss/score.yaml +24 -0
- api_everything/recipes/exchangerate/latest.yaml +24 -0
- api_everything/recipes/firefox_addons/search.yaml +26 -0
- api_everything/recipes/fly_status/summary.yaml +17 -0
- api_everything/recipes/formik_docs/search.yaml +32 -0
- api_everything/recipes/frankfurter/rates.yaml +24 -0
- api_everything/recipes/gcp_status/incidents.yaml +20 -0
- api_everything/recipes/github/explore.yaml +35 -0
- api_everything/recipes/github/gists.yaml +18 -0
- api_everything/recipes/github/issues.yaml +30 -0
- api_everything/recipes/github/license.yaml +23 -0
- api_everything/recipes/github/org.yaml +22 -0
- api_everything/recipes/github/releases.yaml +30 -0
- api_everything/recipes/github/repo.yaml +28 -0
- api_everything/recipes/github/user.yaml +22 -0
- api_everything/recipes/github_advisories/list.yaml +20 -0
- api_everything/recipes/github_status/summary.yaml +17 -0
- api_everything/recipes/github_status/ui.yaml +15 -0
- api_everything/recipes/gitlab/issues.yaml +24 -0
- api_everything/recipes/gitlab/repo.yaml +21 -0
- api_everything/recipes/gitlab/search.yaml +26 -0
- api_everything/recipes/go_proxy/latest.yaml +24 -0
- api_everything/recipes/grafana_status/summary.yaml +17 -0
- api_everything/recipes/hackage/versions.yaml +24 -0
- api_everything/recipes/hackernews/ask.yaml +18 -0
- api_everything/recipes/hackernews/front_page.yaml +18 -0
- api_everything/recipes/hackernews/item.yaml +21 -0
- api_everything/recipes/hackernews/jobs.yaml +18 -0
- api_everything/recipes/hackernews/latest.yaml +25 -0
- api_everything/recipes/hackernews/search.yaml +34 -0
- api_everything/recipes/hackernews/show.yaml +18 -0
- api_everything/recipes/hashicorp_releases/list.yaml +27 -0
- api_everything/recipes/hashicorp_status/summary.yaml +17 -0
- api_everything/recipes/helm_docs/search.yaml +32 -0
- api_everything/recipes/heroku_status/current.yaml +17 -0
- api_everything/recipes/hexpm/search.yaml +27 -0
- api_everything/recipes/hf_papers/daily.yaml +20 -0
- api_everything/recipes/himalayas/jobs.yaml +17 -0
- api_everything/recipes/homebrew/cask.yaml +22 -0
- api_everything/recipes/homebrew/formula.yaml +26 -0
- api_everything/recipes/hono_docs/search.yaml +32 -0
- api_everything/recipes/httpbin/json.yaml +17 -0
- api_everything/recipes/httpbin/uuid.yaml +15 -0
- api_everything/recipes/huggingface/datasets.yaml +25 -0
- api_everything/recipes/huggingface/model_info.yaml +27 -0
- api_everything/recipes/huggingface/models.yaml +28 -0
- api_everything/recipes/huggingface/spaces.yaml +25 -0
- api_everything/recipes/inspirehep/papers.yaml +24 -0
- api_everything/recipes/ionic_docs/search.yaml +32 -0
- api_everything/recipes/ipify/ipv4.yaml +17 -0
- api_everything/recipes/ipwho/lookup.yaml +24 -0
- api_everything/recipes/jest_docs/search.yaml +32 -0
- api_everything/recipes/jsdelivr/gh.yaml +27 -0
- api_everything/recipes/jsdelivr/npm.yaml +24 -0
- api_everything/recipes/jsr/search.yaml +27 -0
- api_everything/recipes/launchdarkly_status/summary.yaml +17 -0
- api_everything/recipes/lemmy/hot.yaml +17 -0
- api_everything/recipes/lesswrong/feed.yaml +17 -0
- api_everything/recipes/llamaindex_docs/search.yaml +32 -0
- api_everything/recipes/lobsters/hottest.yaml +20 -0
- api_everything/recipes/luma/category.yaml +22 -0
- api_everything/recipes/luma/events.yaml +17 -0
- api_everything/recipes/mastodon/explore.yaml +26 -0
- api_everything/recipes/mastodon/tag.yaml +23 -0
- api_everything/recipes/mastodon/trends_tags.yaml +18 -0
- api_everything/recipes/mdn/search.yaml +24 -0
- api_everything/recipes/metacpan/search.yaml +24 -0
- api_everything/recipes/microlink/preview.yaml +24 -0
- api_everything/recipes/mikro_orm_docs/search.yaml +32 -0
- api_everything/recipes/mock/items.yaml +35 -0
- api_everything/recipes/mongodb_status/summary.yaml +17 -0
- api_everything/recipes/nager_date/holidays.yaml +32 -0
- api_everything/recipes/neon_docs/search.yaml +32 -0
- api_everything/recipes/nestjs_docs/search.yaml +32 -0
- api_everything/recipes/netlify_status/summary.yaml +17 -0
- api_everything/recipes/nextjs_docs/search.yaml +32 -0
- api_everything/recipes/nodejs_dist/releases.yaml +17 -0
- api_everything/recipes/npm/dist_tags.yaml +22 -0
- api_everything/recipes/npm/package.yaml +25 -0
- api_everything/recipes/npm/search.yaml +25 -0
- api_everything/recipes/npm_downloads/weekly.yaml +24 -0
- api_everything/recipes/npm_status/summary.yaml +17 -0
- api_everything/recipes/npmtrends/compare.yaml +22 -0
- api_everything/recipes/nuget/search.yaml +27 -0
- api_everything/recipes/nuxt_docs/search.yaml +32 -0
- api_everything/recipes/nvd/cve.yaml +22 -0
- api_everything/recipes/nvd/cves.yaml +24 -0
- api_everything/recipes/open_elevation/lookup.yaml +29 -0
- api_everything/recipes/openai_status/summary.yaml +17 -0
- api_everything/recipes/opencollective/search.yaml +22 -0
- api_everything/recipes/openfda/events.yaml +17 -0
- api_everything/recipes/openlibrary/search.yaml +24 -0
- api_everything/recipes/openmeteo/forecast.yaml +17 -0
- api_everything/recipes/openrouter/models.yaml +20 -0
- api_everything/recipes/openstreetmap/geocode.yaml +27 -0
- api_everything/recipes/openstreetmap/reverse.yaml +27 -0
- api_everything/recipes/osv/vuln.yaml +24 -0
- api_everything/recipes/packagist/search.yaml +27 -0
- api_everything/recipes/peps/list.yaml +17 -0
- api_everything/recipes/pinia_docs/search.yaml +32 -0
- api_everything/recipes/pkg_go_dev/browse.yaml +15 -0
- api_everything/recipes/pkg_go_dev/package.yaml +25 -0
- api_everything/recipes/playwright_docs/search.yaml +32 -0
- api_everything/recipes/pnpm_docs/search.yaml +32 -0
- api_everything/recipes/pokeapi/pokemon.yaml +24 -0
- api_everything/recipes/posthog_docs/search.yaml +32 -0
- api_everything/recipes/postman_echo/get.yaml +24 -0
- api_everything/recipes/postman_status/summary.yaml +17 -0
- api_everything/recipes/preact_docs/search.yaml +32 -0
- api_everything/recipes/pubdev/search.yaml +24 -0
- api_everything/recipes/pubmed/search.yaml +24 -0
- api_everything/recipes/puppeteer_docs/search.yaml +32 -0
- api_everything/recipes/pypi/package.yaml +24 -0
- api_everything/recipes/pypi/version.yaml +27 -0
- api_everything/recipes/quay/search.yaml +27 -0
- api_everything/recipes/quora/answers.yaml +46 -0
- api_everything/recipes/qwik_docs/search.yaml +32 -0
- api_everything/recipes/ray_docs/search.yaml +32 -0
- api_everything/recipes/rdap/domain.yaml +24 -0
- api_everything/recipes/react_docs/search.yaml +32 -0
- api_everything/recipes/react_hook_form_docs/search.yaml +32 -0
- api_everything/recipes/reactrouter_docs/search.yaml +32 -0
- api_everything/recipes/reddit/search.yaml +48 -0
- api_everything/recipes/reddit_status/summary.yaml +17 -0
- api_everything/recipes/remoteok/jobs.yaml +17 -0
- api_everything/recipes/render_status/summary.yaml +17 -0
- api_everything/recipes/repology/project.yaml +24 -0
- api_everything/recipes/ripe_stat/prefix.yaml +24 -0
- api_everything/recipes/rollup_docs/search.yaml +32 -0
- api_everything/recipes/rsbuild_docs/search.yaml +32 -0
- api_everything/recipes/rubygems/gem.yaml +22 -0
- api_everything/recipes/rubygems/search.yaml +27 -0
- api_everything/recipes/sendgrid_status/summary.yaml +17 -0
- api_everything/recipes/sequelize_docs/search.yaml +32 -0
- api_everything/recipes/shodan_internetdb/host.yaml +24 -0
- api_everything/recipes/shopify_status/summary.yaml +17 -0
- api_everything/recipes/sigstore_rekor/log.yaml +17 -0
- api_everything/recipes/slack_status/current.yaml +17 -0
- api_everything/recipes/spdx/licenses.yaml +17 -0
- api_everything/recipes/stackexchange/sites.yaml +20 -0
- api_everything/recipes/stackoverflow/answers.yaml +15 -0
- api_everything/recipes/stackoverflow/questions.yaml +18 -0
- api_everything/recipes/stackoverflow/search.yaml +27 -0
- api_everything/recipes/stackoverflow/tags.yaml +18 -0
- api_everything/recipes/strapi_docs/search.yaml +32 -0
- api_everything/recipes/strawberry_docs/search.yaml +32 -0
- api_everything/recipes/stripe_status/current.yaml +17 -0
- api_everything/recipes/substack/explore.yaml +22 -0
- api_everything/recipes/substack/search.yaml +31 -0
- api_everything/recipes/sunrise_sunset/times.yaml +29 -0
- api_everything/recipes/supabase_status/summary.yaml +17 -0
- api_everything/recipes/swr_docs/search.yaml +32 -0
- api_everything/recipes/tanstack_docs/search.yaml +32 -0
- api_everything/recipes/tc39/proposals.yaml +20 -0
- api_everything/recipes/techempower/results.yaml +15 -0
- api_everything/recipes/temporal_docs/search.yaml +32 -0
- api_everything/recipes/terraform_registry/browse.yaml +25 -0
- api_everything/recipes/terraform_registry/search.yaml +24 -0
- api_everything/recipes/testing_library_docs/search.yaml +32 -0
- api_everything/recipes/tvmaze/shows.yaml +24 -0
- api_everything/recipes/twilio_status/summary.yaml +17 -0
- api_everything/recipes/upstash_docs/search.yaml +32 -0
- api_everything/recipes/valibot_docs/search.yaml +32 -0
- api_everything/recipes/vercel_status/summary.yaml +17 -0
- api_everything/recipes/vercel_status/ui.yaml +15 -0
- api_everything/recipes/vue_docs/search.yaml +32 -0
- api_everything/recipes/w3c/specs.yaml +17 -0
- api_everything/recipes/wayback/available.yaml +24 -0
- api_everything/recipes/webdriverio_docs/search.yaml +32 -0
- api_everything/recipes/webpack_docs/search.yaml +32 -0
- api_everything/recipes/wikidata/entity.yaml +22 -0
- api_everything/recipes/wikidata/search.yaml +24 -0
- api_everything/recipes/wikimedia_commons/search.yaml +25 -0
- api_everything/recipes/wikipedia/search.yaml +25 -0
- api_everything/recipes/wikipedia/summary.yaml +33 -0
- api_everything/recipes/wordpress_plugins/search.yaml +24 -0
- api_everything/recipes/wordpress_themes/search.yaml +24 -0
- api_everything/recipes/worldbank/indicator.yaml +17 -0
- api_everything/recipes/zenodo/records.yaml +24 -0
- api_everything/recipes/zippopotam/in.yaml +22 -0
- api_everything/recipes/zippopotam/lookup.yaml +29 -0
- api_everything/recipes/zoom_status/summary.yaml +17 -0
- api_everything/record.py +327 -0
- api_everything/record_session.py +364 -0
- api_everything/repair.py +717 -0
- api_everything/repair_ai.py +194 -0
- api_everything/runlog.py +61 -0
- api_everything/server.py +323 -0
- api_everything-0.5.0.dist-info/METADATA +363 -0
- api_everything-0.5.0.dist-info/RECORD +281 -0
- api_everything-0.5.0.dist-info/WHEEL +4 -0
- api_everything-0.5.0.dist-info/entry_points.txt +2 -0
- api_everything-0.5.0.dist-info/licenses/LICENSE +202 -0
api_everything/check.py
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""Live checks: run a recipe with its sample parameters and test the result.
|
|
2
|
+
|
|
3
|
+
A check passes only if the run succeeds AND every assertion in the recipe's `check:` block
|
|
4
|
+
holds, so a site that still answers 200 but changed its data shape is caught. Checks run one
|
|
5
|
+
after another, never in parallel, to stay polite to the sites.
|
|
6
|
+
|
|
7
|
+
If a daemon is already running, checks go through it (so they share its Chrome and its profile
|
|
8
|
+
locks, queue and rate limiter). Otherwise a private pool is started just for the checks.
|
|
9
|
+
Live checks are never run by hosted CI: they run on your own machine, by hand or on a schedule.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import os
|
|
15
|
+
import subprocess
|
|
16
|
+
import time
|
|
17
|
+
from collections.abc import Awaitable, Callable, Iterable
|
|
18
|
+
from dataclasses import dataclass
|
|
19
|
+
from urllib.parse import urlsplit
|
|
20
|
+
|
|
21
|
+
import httpx
|
|
22
|
+
|
|
23
|
+
from api_everything.config import Config
|
|
24
|
+
from api_everything.engine import RunResult
|
|
25
|
+
from api_everything.errors import RunError
|
|
26
|
+
from api_everything.hooks import load_hooks
|
|
27
|
+
from api_everything.pool import Pool
|
|
28
|
+
from api_everything.recipe import Recipe
|
|
29
|
+
from api_everything.recipe.loader import LoadedRecipes
|
|
30
|
+
|
|
31
|
+
Runner = Callable[[Recipe], Awaitable[RunResult]]
|
|
32
|
+
_LOCAL_HOSTS = {"127.0.0.1", "localhost", "::1"}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class CheckSelectionError(Exception):
|
|
36
|
+
"""The user asked for recipes that do not exist, or for nothing at all."""
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
@dataclass
|
|
40
|
+
class CheckResult:
|
|
41
|
+
recipe: str
|
|
42
|
+
ok: bool
|
|
43
|
+
detail: str
|
|
44
|
+
duration_ms: int
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def is_local(recipe: Recipe) -> bool:
|
|
48
|
+
"""True for recipes that point at this machine, such as the mock-site demo."""
|
|
49
|
+
return (urlsplit(recipe.url).hostname or "") in _LOCAL_HOSTS
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def select_recipes(
|
|
53
|
+
loaded: LoadedRecipes,
|
|
54
|
+
names: Iterable[str],
|
|
55
|
+
*,
|
|
56
|
+
everything: bool,
|
|
57
|
+
include_local: bool,
|
|
58
|
+
include_experimental: bool = False,
|
|
59
|
+
) -> list[Recipe]:
|
|
60
|
+
names = list(names)
|
|
61
|
+
if names and everything:
|
|
62
|
+
raise CheckSelectionError("give recipe names or --all, not both")
|
|
63
|
+
if not names and not everything:
|
|
64
|
+
raise CheckSelectionError("name the recipes to check, or use --all")
|
|
65
|
+
if names:
|
|
66
|
+
unknown = [name for name in names if name not in loaded.recipes]
|
|
67
|
+
if unknown:
|
|
68
|
+
raise CheckSelectionError(f"unknown recipe(s): {', '.join(unknown)}")
|
|
69
|
+
return [loaded.recipes[name] for name in names]
|
|
70
|
+
chosen = [loaded.recipes[name] for name in sorted(loaded.recipes)]
|
|
71
|
+
if not include_local:
|
|
72
|
+
chosen = [r for r in chosen if not is_local(r)]
|
|
73
|
+
if not include_experimental:
|
|
74
|
+
chosen = [r for r in chosen if r.status != "experimental"]
|
|
75
|
+
return chosen
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
async def check_recipes(recipes: Iterable[Recipe], run: Runner) -> list[CheckResult]:
|
|
79
|
+
results: list[CheckResult] = []
|
|
80
|
+
for recipe in recipes:
|
|
81
|
+
started = time.perf_counter()
|
|
82
|
+
try:
|
|
83
|
+
result = await run(recipe)
|
|
84
|
+
except RunError as err:
|
|
85
|
+
ok, detail = False, f"{err.code}: {err.message}"
|
|
86
|
+
else:
|
|
87
|
+
failures = [
|
|
88
|
+
problem
|
|
89
|
+
for expectation in recipe.check.expect
|
|
90
|
+
for problem in expectation.failures(result.data)
|
|
91
|
+
]
|
|
92
|
+
ok, detail = not failures, "; ".join(failures) or "ok"
|
|
93
|
+
results.append(
|
|
94
|
+
CheckResult(recipe.name, ok, detail, int((time.perf_counter() - started) * 1000))
|
|
95
|
+
)
|
|
96
|
+
return results
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def daemon_base_url(config: Config) -> str:
|
|
100
|
+
"""Where a running daemon would be listening, as a client should address it."""
|
|
101
|
+
host = config.server.host
|
|
102
|
+
if host in ("0.0.0.0", "::", ""):
|
|
103
|
+
host = "127.0.0.1"
|
|
104
|
+
if ":" in host: # a bare IPv6 literal needs brackets in a URL
|
|
105
|
+
host = f"[{host}]"
|
|
106
|
+
return f"http://{host}:{config.server.port}"
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
async def daemon_is_running(client: httpx.AsyncClient, base_url: str) -> bool:
|
|
110
|
+
try:
|
|
111
|
+
response = await client.get(f"{base_url}/healthz", timeout=1.0)
|
|
112
|
+
except httpx.HTTPError:
|
|
113
|
+
return False
|
|
114
|
+
return response.status_code == 200 and response.json().get("status") == "ok"
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def daemon_runner(client: httpx.AsyncClient, base_url: str, token: str | None) -> Runner:
|
|
118
|
+
"""A runner that asks a running daemon, so checks share its browser and limits."""
|
|
119
|
+
headers = {"Authorization": f"Bearer {token}"} if token else {}
|
|
120
|
+
|
|
121
|
+
async def run(recipe: Recipe) -> RunResult:
|
|
122
|
+
try:
|
|
123
|
+
response = await client.get(
|
|
124
|
+
f"{base_url}/v1/run/{recipe.name}",
|
|
125
|
+
params=recipe.check.params,
|
|
126
|
+
headers=headers,
|
|
127
|
+
timeout=120.0,
|
|
128
|
+
)
|
|
129
|
+
except httpx.HTTPError as exc:
|
|
130
|
+
raise RunError(
|
|
131
|
+
"daemon_unreachable", f"could not reach the daemon: {type(exc).__name__}"
|
|
132
|
+
) from exc
|
|
133
|
+
body = response.json()
|
|
134
|
+
if response.status_code != 200:
|
|
135
|
+
error = body.get("error", {})
|
|
136
|
+
raise RunError(
|
|
137
|
+
error.get("code", "daemon_error"),
|
|
138
|
+
error.get("message", f"the daemon answered {response.status_code}"),
|
|
139
|
+
http_status=response.status_code,
|
|
140
|
+
meta=body.get("meta"),
|
|
141
|
+
)
|
|
142
|
+
return RunResult(data=body["data"], meta=body.get("meta", {}))
|
|
143
|
+
|
|
144
|
+
return run
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
async def run_locally(config: Config, loaded: LoadedRecipes, recipes: list[Recipe]):
|
|
148
|
+
"""Check with a private pool (no daemon running): start Chrome, run, shut it down."""
|
|
149
|
+
pool = Pool(config)
|
|
150
|
+
hooks = load_hooks(config.hooks_dir, loaded.recipes.values())
|
|
151
|
+
await pool.start()
|
|
152
|
+
try:
|
|
153
|
+
|
|
154
|
+
async def run(recipe: Recipe) -> RunResult:
|
|
155
|
+
return await pool.run(recipe, recipe.check.params, hook=hooks.get(recipe.name))
|
|
156
|
+
|
|
157
|
+
return await check_recipes(recipes, run)
|
|
158
|
+
finally:
|
|
159
|
+
await pool.stop()
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def notify(command: str, failed: list[str]) -> int:
|
|
163
|
+
"""Run the operator's own notification command, telling it which recipes failed."""
|
|
164
|
+
env = dict(os.environ, API_EVERYTHING_FAILED_RECIPES=",".join(failed))
|
|
165
|
+
try:
|
|
166
|
+
return subprocess.run(command, shell=True, env=env, timeout=30, check=False).returncode
|
|
167
|
+
except subprocess.TimeoutExpired:
|
|
168
|
+
return 124
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""`api-everything chrome <name>`: start the Chrome that an attached profile connects to.
|
|
2
|
+
|
|
3
|
+
It opens a normal visible Chrome on the profile's own folder, listening for the DevTools
|
|
4
|
+
protocol on this machine only, at the port in the profile's `attach` address. You sign in by
|
|
5
|
+
hand and leave it open; the daemon attaches to it. The daemon never sees your credentials.
|
|
6
|
+
|
|
7
|
+
Chrome 136 and later ignores remote debugging on the default profile, so this Chrome always
|
|
8
|
+
uses a dedicated folder. That is also why it cannot be your everyday Chrome.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import asyncio
|
|
14
|
+
import socket
|
|
15
|
+
import subprocess
|
|
16
|
+
from pathlib import Path
|
|
17
|
+
|
|
18
|
+
import httpx
|
|
19
|
+
|
|
20
|
+
from api_everything.config import Config, ConfigError
|
|
21
|
+
from api_everything.login import profile_lock_pid
|
|
22
|
+
|
|
23
|
+
CHROME_PATHS = [
|
|
24
|
+
"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome",
|
|
25
|
+
"/usr/bin/google-chrome",
|
|
26
|
+
"/usr/bin/google-chrome-stable",
|
|
27
|
+
]
|
|
28
|
+
START_TIMEOUT_SECONDS = 20.0
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ChromeCommandError(Exception):
|
|
32
|
+
"""Chrome cannot be started for this profile. The message says what to do."""
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def find_chrome() -> str | None:
|
|
36
|
+
for path in CHROME_PATHS:
|
|
37
|
+
if Path(path).exists():
|
|
38
|
+
return path
|
|
39
|
+
return None
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def chrome_args(chrome: str, directory: Path, port: int, *, headless: bool = False) -> list[str]:
|
|
43
|
+
args = [
|
|
44
|
+
chrome,
|
|
45
|
+
f"--remote-debugging-port={port}",
|
|
46
|
+
"--remote-debugging-address=127.0.0.1", # this machine only, never the network
|
|
47
|
+
f"--user-data-dir={directory}",
|
|
48
|
+
"--no-first-run",
|
|
49
|
+
"--no-default-browser-check",
|
|
50
|
+
]
|
|
51
|
+
if headless:
|
|
52
|
+
args.append("--headless=new")
|
|
53
|
+
return args
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
async def cdp_answering(url: str) -> bool:
|
|
57
|
+
"""True when a Chrome is answering the DevTools protocol at this address."""
|
|
58
|
+
try:
|
|
59
|
+
async with httpx.AsyncClient() as client:
|
|
60
|
+
resp = await client.get(f"{url}/json/version", timeout=1.5)
|
|
61
|
+
return resp.status_code == 200 and "webSocketDebuggerUrl" in resp.json()
|
|
62
|
+
except (httpx.HTTPError, ValueError):
|
|
63
|
+
return False
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _port_taken(port: int) -> bool:
|
|
67
|
+
with socket.socket() as sock:
|
|
68
|
+
return sock.connect_ex(("127.0.0.1", port)) == 0
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
async def start_chrome(
|
|
72
|
+
config: Config,
|
|
73
|
+
name: str,
|
|
74
|
+
*,
|
|
75
|
+
headless: bool = False,
|
|
76
|
+
chrome_path: str | None = None,
|
|
77
|
+
say=print,
|
|
78
|
+
) -> Path:
|
|
79
|
+
"""Start Chrome for an attached profile and return once it answers. Leaves it running."""
|
|
80
|
+
try:
|
|
81
|
+
attach = config.profile_attach(name)
|
|
82
|
+
directory = config.profile_dir(name)
|
|
83
|
+
except ConfigError as exc:
|
|
84
|
+
raise ChromeCommandError(str(exc)) from exc
|
|
85
|
+
if attach is None:
|
|
86
|
+
raise ChromeCommandError(
|
|
87
|
+
f"profile {name!r} is not set up to attach. Add it to your config file:\n"
|
|
88
|
+
f" profiles:\n {name}:\n attach: http://127.0.0.1:9222"
|
|
89
|
+
)
|
|
90
|
+
if await cdp_answering(attach.url):
|
|
91
|
+
say(f"Chrome for profile {name!r} is already running at {attach.url}.")
|
|
92
|
+
return directory
|
|
93
|
+
|
|
94
|
+
holder = profile_lock_pid(directory)
|
|
95
|
+
if holder is not None:
|
|
96
|
+
raise ChromeCommandError(
|
|
97
|
+
f"profile {name!r} ({directory}) is open in a Chrome (pid {holder}) that was not "
|
|
98
|
+
"started with remote debugging. Close that window, then run this again."
|
|
99
|
+
)
|
|
100
|
+
if _port_taken(attach.port):
|
|
101
|
+
raise ChromeCommandError(
|
|
102
|
+
f"port {attach.port} is already in use by another program. Choose another port "
|
|
103
|
+
f"in the attach address of profile {name!r}."
|
|
104
|
+
)
|
|
105
|
+
chrome = chrome_path or find_chrome()
|
|
106
|
+
if chrome is None:
|
|
107
|
+
raise ChromeCommandError(
|
|
108
|
+
"Google Chrome was not found. Install it, then run this again."
|
|
109
|
+
)
|
|
110
|
+
|
|
111
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
112
|
+
process = subprocess.Popen( # noqa: S603 - a fixed argument list, no shell
|
|
113
|
+
chrome_args(chrome, directory, attach.port, headless=headless),
|
|
114
|
+
stdout=subprocess.DEVNULL,
|
|
115
|
+
stderr=subprocess.DEVNULL,
|
|
116
|
+
start_new_session=True, # outlives this command, so you can close the terminal
|
|
117
|
+
)
|
|
118
|
+
loop = asyncio.get_running_loop()
|
|
119
|
+
deadline = loop.time() + START_TIMEOUT_SECONDS
|
|
120
|
+
while loop.time() < deadline:
|
|
121
|
+
if process.poll() is not None:
|
|
122
|
+
raise ChromeCommandError(
|
|
123
|
+
f"Chrome exited straight away (code {process.returncode}). Is another Chrome "
|
|
124
|
+
"using this profile?"
|
|
125
|
+
)
|
|
126
|
+
if await cdp_answering(attach.url):
|
|
127
|
+
say(f"Chrome is running for profile {name!r} at {attach.url} ({directory}).")
|
|
128
|
+
return directory
|
|
129
|
+
await asyncio.sleep(0.3)
|
|
130
|
+
process.terminate()
|
|
131
|
+
raise ChromeCommandError(f"Chrome did not start answering at {attach.url} in time.")
|