Skip to content

Commit b3767c5

Browse files
committed
add collectors to ooniapi
1 parent 5763024 commit b3767c5

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

ooniapi/common/src/common/config.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import List
1+
from typing import List, Dict
22
from pydantic_settings import BaseSettings
33

44

@@ -41,3 +41,21 @@ class Settings(BaseSettings):
4141
failed_reports_bucket: str = (
4242
"" # for uploading reports that couldn't be sent to fastpath
4343
)
44+
45+
# ooniprobe client configuration
46+
collectors: List[Dict[str, str]] = [
47+
{"address": "httpo://guegdifjy7bjpequ.onion", "type": "onion"},
48+
{"address": "https://ams-pg.ooni.org:443", "type": "https"},
49+
{
50+
"address": "https://dkyhjv0wpi2dk.cloudfront.net",
51+
"front": "dkyhjv0wpi2dk.cloudfront.net",
52+
"type": "cloudfront",
53+
},
54+
{"address": "httpo://guegdifjy7bjpequ.onion", "type": "onion"},
55+
{"address": "https://ams-pg.ooni.org:443", "type": "https"},
56+
{
57+
"address": "https://dkyhjv0wpi2dk.cloudfront.net",
58+
"front": "dkyhjv0wpi2dk.cloudfront.net",
59+
"type": "cloudfront",
60+
},
61+
]

ooniapi/services/ooniprobe/src/ooniprobe/routers/v1/probe_services.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,3 +590,21 @@ def random_web_test_helpers(th_list: List[str]) -> List[Dict]:
590590
for th_addr in th_list:
591591
out.append({"address": th_addr, "type": "https"})
592592
return out
593+
594+
595+
class CollectorEntry(BaseModel):
596+
# not actually used but necessary to be compliant with the old API schema
597+
address: str = Field(description="Address of collector")
598+
front: Optional[str] = Field(default=None, description="Fronted domain")
599+
type: Optional[str] = Field(default=None, description="Type of collector")
600+
601+
@router.post("/collectors", tags=["ooniprobe"])
602+
def list_collectors(
603+
settings: Settings = Depends(get_settings),
604+
) -> List[CollectorEntry]:
605+
config_collectors = settings.collectors
606+
collectors_response = []
607+
for entry in config_collectors:
608+
collector = CollectorEntry(**entry)
609+
collectors_response.append(collector)
610+
return collectors_response
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def test_list_collectors(client):
2+
c = client.post("/api/v1/collectors").json()
3+
assert len(c) == 6
4+
for entry in c:
5+
assert "address" in entry

0 commit comments

Comments
 (0)