id int64 0 1.29M | original_id stringlengths 32 32 | swhid stringlengths 100 170 | sha1 stringlengths 40 40 | repo_name stringlengths 2 45 | repo_group stringclasses 12
values | filepath stringlengths 5 153 | name stringlengths 1 14.9k | type stringclasses 3
values | code stringlengths 7 2.12M |
|---|---|---|---|---|---|---|---|---|---|
1,400 | 85a9b60c9c114bede78739d223b7e58b | swh:1:cnt:fbf62cc2fb6404dffe866bee25f7276093b27f56;origin=https://gitlab.wikimedia.org/repos/data-engineering/node-url-get.git;lines=33-35/ | 16dfeba253b6d22d5d51f90f82a94ceef2135ba5 | node-url-get | analytics | test/index.js | unlinkTempFile | function | function unlinkTempFile() {
fs.unlinkSync(filePath);
} |
1,401 | 24a4129c7dca7645ccfd16b59b47f4ac | swh:1:cnt:26cb201b8c88d1e08be7f5bcf81080bc9bb8fbd8;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=37-42/ | 9183909b2db547c2e19dd7226d0b65cfccee2b4b | growthbook | analytics | ldap-sync/ldap_sync/applier.py | ApplyResult | type | class ApplyResult:
succeeded: int
failed: int
skipped: int
pending_sso: int
noop: int |
1,402 | 74f701f2b4357c848f5c9ff485bc8b30 | swh:1:cnt:26cb201b8c88d1e08be7f5bcf81080bc9bb8fbd8;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=45-103/ | 9183909b2db547c2e19dd7226d0b65cfccee2b4b | growthbook | analytics | ldap-sync/ldap_sync/applier.py | apply_plan(
*,
plan: Plan,
client: GrowthBookClient,
project_id: str,
elevated_role_name: str,
raw_members_by_email: Mapping[str, dict[str, Any]],
dry_run: bool,
metrics: Metrics,
) | function | def apply_plan(
*,
plan: Plan,
client: GrowthBookClient,
project_id: str,
elevated_role_name: str,
raw_members_by_email: Mapping[str, dict[str, Any]],
dry_run: bool,
metrics: Metrics,
) -> ApplyResult:
"""Apply the plan against the GrowthBook API.
Uses raw_members_by_email (the ... |
1,403 | b555daeea5d7960aa06e14f1ebc557d0 | swh:1:cnt:26cb201b8c88d1e08be7f5bcf81080bc9bb8fbd8;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=152-184/ | 9183909b2db547c2e19dd7226d0b65cfccee2b4b | growthbook | analytics | ldap-sync/ldap_sync/applier.py | _build_role_update_payload(
action: Action,
*,
project_id: str,
elevated_role_name: str,
raw_members_by_email: Mapping[str, dict[str, Any]],
) | function | def _build_role_update_payload(
action: Action,
*,
project_id: str,
elevated_role_name: str,
raw_members_by_email: Mapping[str, dict[str, Any]],
) -> dict[str, Any]:
raw = raw_members_by_email.get(action.email, {})
role = SAFE_GLOBAL_ROLE
if action.target_role == Role.NO_ACCESS:
... |
1,404 | 9d875d02c6890ffa317a08f094e526a7 | swh:1:cnt:26cb201b8c88d1e08be7f5bcf81080bc9bb8fbd8;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=106-149/ | 9183909b2db547c2e19dd7226d0b65cfccee2b4b | growthbook | analytics | ldap-sync/ldap_sync/applier.py | _apply_one(
action: Action,
*,
client: GrowthBookClient,
project_id: str,
elevated_role_name: str,
raw_members_by_email: Mapping[str, dict[str, Any]],
dry_run: bool,
) | function | def _apply_one(
action: Action,
*,
client: GrowthBookClient,
project_id: str,
elevated_role_name: str,
raw_members_by_email: Mapping[str, dict[str, Any]],
dry_run: bool,
) -> str:
if action.growthbook_member_id is None:
return "failed"
payload = _build_role_update_payload(
... |
1,405 | 3926d7e19145c89b433cafc4162184bf | swh:1:cnt:26cb201b8c88d1e08be7f5bcf81080bc9bb8fbd8;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=187-203/ | 9183909b2db547c2e19dd7226d0b65cfccee2b4b | growthbook | analytics | ldap-sync/ldap_sync/applier.py | _log_action(action: Action, action_name: str, result: str) | function | def _log_action(action: Action, action_name: str, result: str) -> None:
logger.info(
"action",
extra={
"user_email": action.email,
"user_uid": action.user_uid,
"growthbook_member_id": action.growthbook_member_id,
"current_role": action.current_role.nam... |
1,406 | f891347b056dadffa13461471c84f04a | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=35-42/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | _validate_pushgateway_job(ctx: click.Context, param: click.Parameter, value: str) | function | def _validate_pushgateway_job(ctx: click.Context, param: click.Parameter, value: str) -> str:
"""Reject empty/whitespace `job` values; they'd produce a malformed
Pushgateway URL path and the resulting error gets swallowed by
push()'s catch-all."""
stripped = (value or "").strip()
if not stripped:
... |
1,407 | 8144d75e2fcc269b14e7131fa248b460 | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=265-269/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | _parse_skip_emails(raw: str) | function | # ---- helpers ----
def _parse_skip_emails(raw: str) -> frozenset[str]:
return frozenset(part.strip().lower() for part in raw.split(",") if part.strip()) |
1,408 | 57aeee4c32433fd81dddd2baad295ec8 | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=272-284/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | _raw_members_by_email(raw_members: list[dict[str, Any]]) | function | def _raw_members_by_email(raw_members: list[dict[str, Any]]) -> dict[str, dict[str, Any]]:
out: dict[str, dict[str, Any]] = {}
for m in raw_members:
email = (m.get("email") or "").strip().lower()
if not email:
continue
if email in out:
logger.warning(
... |
1,409 | 679c346821d7fe6c38308e24a3db3ed5 | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=302-309/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | _collect_bitu(opts: dict[str, Any], metrics: Metrics) | function | def _collect_bitu(opts: dict[str, Any], metrics: Metrics) -> Any:
snapshot = fetch_bitu_snapshot(
primary_uri=opts["ldap_uri"],
fallback_uri=opts["ldap_uri_fallback"] or None,
ca_cert_path=opts["ldap_ca_cert_path"],
)
metrics.source_healthy.labels(source="ldap").set(1)
return sna... |
1,410 | e8d9874ab9f7c0cd53f67fc4def24999 | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=318-339/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | _build_target_states(*, bitu: Any, posix: dict[str, frozenset[str]]) | function | def _build_target_states(*, bitu: Any, posix: dict[str, frozenset[str]]) -> dict[str, TargetState]:
posix_map = {name: set(uids) for name, uids in posix.items()}
targets: dict[str, TargetState] = {}
seen_uids: set[str] = set()
for uids in bitu.memberships_by_group.values():
seen_uids.update(uid... |
1,411 | a30acf162e7c5ece0845291ec68e3489 | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=350-364/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | _push_and_summary(
pushgateway_url: str | None,
pushgateway_job: str,
metrics: Metrics,
plan: Plan | None,
started: float,
) | function | def _push_and_summary(
pushgateway_url: str | None,
pushgateway_job: str,
metrics: Metrics,
plan: Plan | None,
started: float,
) -> None:
duration = time.monotonic() - started
metrics.run_duration.observe(duration)
push(metrics, pushgateway_url=pushgateway_url, job=pushgateway_job)
... |
1,412 | 36f59c111ca1f00bafb411005759b3ac | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=45-110/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | _common_options(f) | function | def _common_options(f):
"""Apply the shared option set to a click command."""
options = [
click.option("--api-base-url", envvar="GROWTHBOOK_API_BASE_URL", required=True),
click.option("--api-key", envvar="GROWTHBOOK_LDAP_SYNC_API_KEY", required=True),
click.option("--project-id", envvar=... |
1,413 | 2bef5378ecc33ae6195ce5008a3f4061 | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=115-116/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | cli() | function | def cli() -> None:
"""Sync GrowthBook user roles from Wikimedia IDM (Bitu) LDAP groups.""" |
1,414 | 7e9b8a82d8febd9d97f0d059238c2064 | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=209-262/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | report(**opts: Any) | function | def report(**opts: Any) -> None:
"""Print current state without making any changes.
Useful as a health check or to glance at what the next sync run
will be working from.
"""
configure_logging(level=opts["log_level"], dry_run=True)
metrics = Metrics()
started = time.monotonic()
skip_emai... |
1,415 | ed8e7a316b78029e5e56e39bf5aa401d | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=127-204/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | sync(dry_run: bool, **opts: Any) | function | def sync(dry_run: bool, **opts: Any) -> None:
"""Reconcile GrowthBook role assignments from LDAP/Bitu group state."""
configure_logging(level=opts["log_level"], dry_run=dry_run)
metrics = Metrics()
started = time.monotonic()
skip_emails = _parse_skip_emails(opts["skip_users"])
try:
clie... |
1,416 | d6db209d6de55bbee7a1db678e4b0faa | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=287-299/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | _validate_and_collect_growthbook(
api_base_url: str, api_key: str, project_id: str, metrics: Metrics
) | function | def _validate_and_collect_growthbook(
api_base_url: str, api_key: str, project_id: str, metrics: Metrics
) -> tuple[GrowthBookClient, list[dict[str, Any]]]:
client = GrowthBookClient(base_url=api_base_url, api_key=api_key)
projects = client.list_projects()
project_ids = {p.get("id") for p in projects}
... |
1,417 | e30ce493dd35d19b4a47b12371c72f70 | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=312-315/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | _collect_data_yaml(opts: dict[str, Any], metrics: Metrics) | function | def _collect_data_yaml(opts: dict[str, Any], metrics: Metrics) -> dict[str, frozenset[str]]:
out = fetch_posix_memberships(url=opts["data_yaml_url"])
metrics.source_healthy.labels(source="data_yaml").set(1)
return out |
1,418 | cb37f9c9b15ee3766e309817ed9c4f82 | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=342-347/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | _source_healthy(metrics: Metrics, source: str) | function | def _source_healthy(metrics: Metrics, source: str) -> bool:
for metric in metrics.source_healthy.collect():
for sample in metric.samples:
if sample.labels.get("source") == source:
return sample.value == 1
return False |
1,419 | ca2b5e55678cbd0ba6de17de86a4c70c | swh:1:cnt:b0bf83599d8bfcd8de2bb9e4967b1e5eadb3a0a2;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=367-368/ | db6ba4ff6edf5943bdf71569565a6aa654844c70 | growthbook | analytics | ldap-sync/ldap_sync/cli.py | main() | function | def main() -> None:
cli(max_content_width=120) |
1,420 | 5a976f6f87be021aa1b9532b929fdbc9 | swh:1:cnt:4ae2284664466e74025b17f44c2402dd436c2f8d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=20-21/ | 6f19d21db76809e884543f7bdb253bbd82203731 | growthbook | analytics | ldap-sync/ldap_sync/growthbook_client.py | GrowthBookAPIError | type | class GrowthBookAPIError(Exception):
"""Raised for non-retryable GrowthBook API errors.""" |
1,421 | e1a6a1a2794a3bb7eaaaeacb9f749c9c | swh:1:cnt:4ae2284664466e74025b17f44c2402dd436c2f8d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=24-25/ | 6f19d21db76809e884543f7bdb253bbd82203731 | growthbook | analytics | ldap-sync/ldap_sync/growthbook_client.py | GrowthBookAuthError | type | class GrowthBookAuthError(GrowthBookAPIError):
"""Raised when the API rejects our credentials (401/403).""" |
1,422 | aa56c153d028960a65e69bd66b7ee685 | swh:1:cnt:4ae2284664466e74025b17f44c2402dd436c2f8d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=28-121/ | 6f19d21db76809e884543f7bdb253bbd82203731 | growthbook | analytics | ldap-sync/ldap_sync/growthbook_client.py | GrowthBookClient | type | class GrowthBookClient:
def __init__(
self,
base_url: str,
api_key: str,
timeout: tuple[float, float] = (5.0, 20.0),
session: requests.Session | None = None,
max_retries: int = 3,
):
self.base_url = base_url.rstrip("/")
self.timeout = timeout
... |
1,423 | a77f8f9c95a47503f5b93af7ce5ce4d7 | swh:1:cnt:4ae2284664466e74025b17f44c2402dd436c2f8d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=29-49/ | 6f19d21db76809e884543f7bdb253bbd82203731 | growthbook | analytics | ldap-sync/ldap_sync/growthbook_client.py | GrowthBookClient::__init__(
self,
base_url: str,
api_key: str,
timeout: tuple[float, float] = (5.0, 20.0),
session: requests.Session | None = None,
max_retries: int = 3,
) | function | def __init__(
self,
base_url: str,
api_key: str,
timeout: tuple[float, float] = (5.0, 20.0),
session: requests.Session | None = None,
max_retries: int = 3,
):
self.base_url = base_url.rstrip("/")
self.timeout = timeout
self.session = session or... |
1,424 | ae53d8e3fb922a2819aed48472535220 | swh:1:cnt:4ae2284664466e74025b17f44c2402dd436c2f8d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=55-57/ | 6f19d21db76809e884543f7bdb253bbd82203731 | growthbook | analytics | ldap-sync/ldap_sync/growthbook_client.py | GrowthBookClient::list_members(self) | function | def list_members(self) -> list[dict[str, Any]]:
"""List all GrowthBook members."""
return self._paginated("/members", "members") |
1,425 | eb887bfe7efb7c89de8f14d67446dbb0 | swh:1:cnt:4ae2284664466e74025b17f44c2402dd436c2f8d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=63-79/ | 6f19d21db76809e884543f7bdb253bbd82203731 | growthbook | analytics | ldap-sync/ldap_sync/growthbook_client.py | GrowthBookClient::_paginated(self, path: str, key: str, page_size: int = 100) | function | def _paginated(self, path: str, key: str, page_size: int = 100) -> list[dict[str, Any]]:
"""Fetch all pages; retry once if the first pass's item count disagrees with
the first-page `total`. Abort if still inconsistent."""
first_pass, first_total = self._paginate_once(path, key, page_size)
... |
1,426 | 85fadc38ede7c8c2974e0955dca2187c | swh:1:cnt:4ae2284664466e74025b17f44c2402dd436c2f8d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=51-53/ | 6f19d21db76809e884543f7bdb253bbd82203731 | growthbook | analytics | ldap-sync/ldap_sync/growthbook_client.py | GrowthBookClient::list_projects(self) | function | def list_projects(self) -> list[dict[str, Any]]:
"""List all GrowthBook projects."""
return self._paginated("/projects", "projects") |
1,427 | 6334557ff9e77649984d81fd7ec37970 | swh:1:cnt:4ae2284664466e74025b17f44c2402dd436c2f8d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=59-61/ | 6f19d21db76809e884543f7bdb253bbd82203731 | growthbook | analytics | ldap-sync/ldap_sync/growthbook_client.py | GrowthBookClient::update_member_role(self, member_id: str, payload: dict[str, Any]) | function | def update_member_role(self, member_id: str, payload: dict[str, Any]) -> dict[str, Any]:
"""Update a member's global and per-project role assignments."""
return self._request("POST", f"/members/{member_id}/role", json={"member": payload}) |
1,428 | 96e625c0625b58a5c5886c474fbd8744 | swh:1:cnt:4ae2284664466e74025b17f44c2402dd436c2f8d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=81-101/ | 6f19d21db76809e884543f7bdb253bbd82203731 | growthbook | analytics | ldap-sync/ldap_sync/growthbook_client.py | GrowthBookClient::_paginate_once(
self, path: str, key: str, page_size: int
) | function | def _paginate_once(
self, path: str, key: str, page_size: int
) -> tuple[list[dict[str, Any]], int | None]:
items: list[dict[str, Any]] = []
first_total: int | None = None
offset = 0
while True:
data = self._request("GET", path, params={"limit": page_size, "offset... |
1,429 | dd4889b0f88b58d10e97fb090309e57b | swh:1:cnt:4ae2284664466e74025b17f44c2402dd436c2f8d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=103-121/ | 6f19d21db76809e884543f7bdb253bbd82203731 | growthbook | analytics | ldap-sync/ldap_sync/growthbook_client.py | GrowthBookClient::_request(
self,
method: str,
path: str,
*,
params: dict[str, Any] | None = None,
json: dict[str, Any] | None = None,
) | function | def _request(
self,
method: str,
path: str,
*,
params: dict[str, Any] | None = None,
json: dict[str, Any] | None = None,
) -> dict[str, Any]:
url = f"{self.base_url}{path}"
try:
resp = self.session.request(method, url, params=params, json=j... |
1,430 | d646a4d0d8aa21683e06ed2be43e828a | swh:1:cnt:0abd13cdc6074866215c1114c94b7017ad064638;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=17-43/ | cc45c5274750d9ee1c28c5c25cdde5e850e061e3 | growthbook | analytics | ldap-sync/ldap_sync/log.py | JsonFormatter | type | class JsonFormatter(logging.Formatter):
def __init__(self, *, sync_run_id: str, dry_run: bool) -> None:
super().__init__()
self.sync_run_id = sync_run_id
self.dry_run = dry_run
def format(self, record: logging.LogRecord) -> str:
payload: dict[str, Any] = {
"ts": self... |
1,431 | d50466fb11e7176dcc3b0edb3b729ef4 | swh:1:cnt:0abd13cdc6074866215c1114c94b7017ad064638;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=18-21/ | cc45c5274750d9ee1c28c5c25cdde5e850e061e3 | growthbook | analytics | ldap-sync/ldap_sync/log.py | JsonFormatter::__init__(self, *, sync_run_id: str, dry_run: bool) | function | def __init__(self, *, sync_run_id: str, dry_run: bool) -> None:
super().__init__()
self.sync_run_id = sync_run_id
self.dry_run = dry_run |
1,432 | e049974086379a0cae0e25574f878ac5 | swh:1:cnt:0abd13cdc6074866215c1114c94b7017ad064638;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=23-43/ | cc45c5274750d9ee1c28c5c25cdde5e850e061e3 | growthbook | analytics | ldap-sync/ldap_sync/log.py | JsonFormatter::format(self, record: logging.LogRecord) | function | def format(self, record: logging.LogRecord) -> str:
payload: dict[str, Any] = {
"ts": self.formatTime(record, "%Y-%m-%dT%H:%M:%S%z"),
"level": record.levelname,
"logger": record.name,
"actor": "ldap-sync",
"sync_run_id": self.sync_run_id,
"... |
1,433 | 248777d9d413e3343517223cdf21ec5b | swh:1:cnt:0abd13cdc6074866215c1114c94b7017ad064638;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=74-83/ | cc45c5274750d9ee1c28c5c25cdde5e850e061e3 | growthbook | analytics | ldap-sync/ldap_sync/log.py | configure_logging(*, level: str, dry_run: bool) | function | def configure_logging(*, level: str, dry_run: bool) -> str:
"""Install a JSON formatter on the root logger; return the sync_run_id."""
sync_run_id = str(uuid.uuid4())
handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(JsonFormatter(sync_run_id=sync_run_id, dry_run=dry_run))
root = logg... |
1,434 | d4ee8e24666677e268f760b9d9c23200 | swh:1:cnt:4a87441b5c45e21dbc5c85715b77ebee44b8de9d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=25-76/ | f539f5b8368d900dc1375b8ce34014f662e1dced | growthbook | analytics | ldap-sync/ldap_sync/metrics.py | Metrics | type | class Metrics:
def __init__(self) -> None:
self.registry = CollectorRegistry()
self.seats = Gauge(
"growthbook_sync_seats_total",
"Current GrowthBook seat count, by role.",
["role"],
registry=self.registry,
)
self.actions_applied = Coun... |
1,435 | a605d332f0a66067bdc74eb48c926287 | swh:1:cnt:4a87441b5c45e21dbc5c85715b77ebee44b8de9d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=26-70/ | f539f5b8368d900dc1375b8ce34014f662e1dced | growthbook | analytics | ldap-sync/ldap_sync/metrics.py | Metrics::__init__(self) | function | def __init__(self) -> None:
self.registry = CollectorRegistry()
self.seats = Gauge(
"growthbook_sync_seats_total",
"Current GrowthBook seat count, by role.",
["role"],
registry=self.registry,
)
self.actions_applied = Counter(
"g... |
1,436 | 8383ac0e354b59a04d1811d77ef9f1bd | swh:1:cnt:4a87441b5c45e21dbc5c85715b77ebee44b8de9d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=75-76/ | f539f5b8368d900dc1375b8ce34014f662e1dced | growthbook | analytics | ldap-sync/ldap_sync/metrics.py | Metrics::mark_failure(self) | function | def mark_failure(self) -> None:
self.last_failure.set(time.time()) |
1,437 | 5eb414df236f9359b390e18bffa91cf9 | swh:1:cnt:4a87441b5c45e21dbc5c85715b77ebee44b8de9d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=79-91/ | f539f5b8368d900dc1375b8ce34014f662e1dced | growthbook | analytics | ldap-sync/ldap_sync/metrics.py | emit_seats_metrics(current_members: Mapping[str, CurrentMember], metrics: Metrics) | function | def emit_seats_metrics(current_members: Mapping[str, CurrentMember], metrics: Metrics) -> None:
"""Populate the seats gauge from current member roles.
Always zeroes every managed role first so a tier with zero seats
shows as 0 (not absent) in Prometheus.
"""
for role in (Role.ADMIN, Role.CUSTOM_ELE... |
1,438 | 524be7c75a4c49d6deee800025cff4f7 | swh:1:cnt:4a87441b5c45e21dbc5c85715b77ebee44b8de9d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=94-105/ | f539f5b8368d900dc1375b8ce34014f662e1dced | growthbook | analytics | ldap-sync/ldap_sync/metrics.py | push(metrics: Metrics, *, pushgateway_url: str | None, job: str) | function | def push(metrics: Metrics, *, pushgateway_url: str | None, job: str) -> None:
"""Push metrics to the configured Pushgateway, if any.
Failures are logged at WARNING and swallowed so a Pushgateway outage
can't take down the sync.
"""
if not pushgateway_url:
return
try:
push_to_gat... |
1,439 | 602b1c685607f88451743361dfbe5f04 | swh:1:cnt:4a87441b5c45e21dbc5c85715b77ebee44b8de9d;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=72-73/ | f539f5b8368d900dc1375b8ce34014f662e1dced | growthbook | analytics | ldap-sync/ldap_sync/metrics.py | Metrics::mark_success(self) | function | def mark_success(self) -> None:
self.last_success.set(time.time()) |
1,440 | d187898bf15a28bc1c9458a62de23990 | swh:1:cnt:78d4c6e96393b3429a9711ecd08e47a1d78426d9;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=22-30/ | 4eb65bb72ebad08ccd52982ad6ccc5a1410955f6 | growthbook | analytics | ldap-sync/ldap_sync/plan.py | ActionKind | type | class ActionKind(Enum):
"""The kind of operation an Action represents."""
REMOVE = 0 # current is some role, target is NO_ACCESS
UPDATE = 1 # role change within project (was downgrade or upgrade)
ADD = 2 # current is NO_ACCESS, target is some role
NOOP = 3 # current == target
SKIPPED = 4 #... |
1,441 | 5c255d6f30dd58e8584fb9a07b436470 | swh:1:cnt:78d4c6e96393b3429a9711ecd08e47a1d78426d9;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=34-45/ | 4eb65bb72ebad08ccd52982ad6ccc5a1410955f6 | growthbook | analytics | ldap-sync/ldap_sync/plan.py | CurrentMember | type | class CurrentMember:
"""A current GrowthBook member's relevant state.
`project_role` is the user's effective role for the managed project:
the role from `projectRoles[managed_project]` if present, else
Role.NO_ACCESS.
"""
email: str
member_id: str
project_role: Role
user_uid: str |... |
1,442 | a1f500d58e96dc47f48fa1d85585de76 | swh:1:cnt:78d4c6e96393b3429a9711ecd08e47a1d78426d9;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=49-60/ | 4eb65bb72ebad08ccd52982ad6ccc5a1410955f6 | growthbook | analytics | ldap-sync/ldap_sync/plan.py | Action | type | class Action:
"""A single per-user operation, with full provenance for audit logging."""
email: str
kind: ActionKind
current_role: Role
target_role: Role
rule_number: int
source_bitu_groups: frozenset[str] = field(default_factory=frozenset)
source_posix_groups: frozenset[str] = field(de... |
1,443 | 6b1b244d553d95dbf7948456874255cf | swh:1:cnt:78d4c6e96393b3429a9711ecd08e47a1d78426d9;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=64-90/ | 4eb65bb72ebad08ccd52982ad6ccc5a1410955f6 | growthbook | analytics | ldap-sync/ldap_sync/plan.py | Plan | type | class Plan:
"""A reconciliation plan: ordered list of actions, plus categorization."""
actions: tuple[Action, ...]
def by_kind(self, kind: ActionKind) -> tuple[Action, ...]:
return tuple(a for a in self.actions if a.kind == kind)
def counts(self) -> dict[ActionKind, int]:
out: dict[Ac... |
1,444 | 6f314d6de71b9995af0c1d2048e51f67 | swh:1:cnt:78d4c6e96393b3429a9711ecd08e47a1d78426d9;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=69-70/ | 4eb65bb72ebad08ccd52982ad6ccc5a1410955f6 | growthbook | analytics | ldap-sync/ldap_sync/plan.py | Plan::by_kind(self, kind: ActionKind) | function | def by_kind(self, kind: ActionKind) -> tuple[Action, ...]:
return tuple(a for a in self.actions if a.kind == kind) |
1,445 | 8408e4508d90d8b982de9a8b4ba85627 | swh:1:cnt:78d4c6e96393b3429a9711ecd08e47a1d78426d9;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=93-162/ | 4eb65bb72ebad08ccd52982ad6ccc5a1410955f6 | growthbook | analytics | ldap-sync/ldap_sync/plan.py | diff(
*,
current_members: Mapping[str, CurrentMember],
target_states: Mapping[str, TargetState],
skip_emails: Set[str],
) | function | def diff(
*,
current_members: Mapping[str, CurrentMember],
target_states: Mapping[str, TargetState],
skip_emails: Set[str],
) -> Plan:
"""Compute the reconciliation plan."""
_validate_lowercase(current_members, "current_members")
_validate_lowercase(target_states, "target_states")
_valid... |
1,446 | b91b2569019f9153a3feb0c4a094fc9d | swh:1:cnt:78d4c6e96393b3429a9711ecd08e47a1d78426d9;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=187-194/ | 4eb65bb72ebad08ccd52982ad6ccc5a1410955f6 | growthbook | analytics | ldap-sync/ldap_sync/plan.py | _classify(current: Role, target: Role) | function | def _classify(current: Role, target: Role) -> ActionKind:
if current == target:
return ActionKind.NOOP
if target == Role.NO_ACCESS:
return ActionKind.REMOVE
if current == Role.NO_ACCESS:
return ActionKind.ADD
return ActionKind.UPDATE |
1,447 | 2bd2ad1130b77d6e84539617258837b4 | swh:1:cnt:78d4c6e96393b3429a9711ecd08e47a1d78426d9;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=72-76/ | 4eb65bb72ebad08ccd52982ad6ccc5a1410955f6 | growthbook | analytics | ldap-sync/ldap_sync/plan.py | Plan::counts(self) | function | def counts(self) -> dict[ActionKind, int]:
out: dict[ActionKind, int] = dict.fromkeys(ActionKind, 0)
for a in self.actions:
out[a.kind] += 1
return out |
1,448 | b37b11f7f1316f70fa0a03e747f20d6d | swh:1:cnt:78d4c6e96393b3429a9711ecd08e47a1d78426d9;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=78-90/ | 4eb65bb72ebad08ccd52982ad6ccc5a1410955f6 | growthbook | analytics | ldap-sync/ldap_sync/plan.py | Plan::sorted_actions(self) | function | def sorted_actions(self) -> tuple[Action, ...]:
"""Return actions in apply order (fail-closed).
Outer order: by ActionKind value (REMOVE -> UPDATE -> ADD -> NOOP
-> SKIPPED -> PENDING_SSO). Inner order within each kind: by
current_role descending (most over-privileged first), then email... |
1,449 | ccede2f5b952ec6324afa5866ee981b0 | swh:1:cnt:78d4c6e96393b3429a9711ecd08e47a1d78426d9;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=165-184/ | 4eb65bb72ebad08ccd52982ad6ccc5a1410955f6 | growthbook | analytics | ldap-sync/ldap_sync/plan.py | _build_action(
*,
email: str,
kind: ActionKind,
current_role: Role,
target_role: Role,
target: TargetState | None,
member: CurrentMember | None,
) | function | def _build_action(
*,
email: str,
kind: ActionKind,
current_role: Role,
target_role: Role,
target: TargetState | None,
member: CurrentMember | None,
) -> Action:
return Action(
email=email,
kind=kind,
current_role=current_role,
target_role=target_role,
... |
1,450 | 836f1e7b4dfcfb7542a54b0bcc559fe3 | swh:1:cnt:78d4c6e96393b3429a9711ecd08e47a1d78426d9;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=197-203/ | 4eb65bb72ebad08ccd52982ad6ccc5a1410955f6 | growthbook | analytics | ldap-sync/ldap_sync/plan.py | _validate_lowercase(m: Mapping[str, object], name: str) | function | def _validate_lowercase(m: Mapping[str, object], name: str) -> None:
for k in m:
if k != k.lower():
raise ValueError(
f"{name} contains non-lowercase email key {k!r}; "
"callers must normalize before calling diff()"
) |
1,451 | bdb446edf14c8de909e2dcf4dac47d1a | swh:1:cnt:78d4c6e96393b3429a9711ecd08e47a1d78426d9;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=206-212/ | 4eb65bb72ebad08ccd52982ad6ccc5a1410955f6 | growthbook | analytics | ldap-sync/ldap_sync/plan.py | _validate_lowercase_iter(s: Set[str], name: str) | function | def _validate_lowercase_iter(s: Set[str], name: str) -> None:
for k in s:
if k != k.lower():
raise ValueError(
f"{name} contains non-lowercase email {k!r}; "
"callers must normalize before passing to diff()"
) |
1,452 | dc931eae5c8a8d492d1d978aca6db80f | swh:1:cnt:468239060b4b177778f321640bb5d8c5ca4113b7;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=25-31/ | 9c216f0aaa4001b80c94ead40cb5156c1b0edad5 | growthbook | analytics | ldap-sync/ldap_sync/resolver.py | Role | type | class Role(IntEnum):
"""GrowthBook role tier. Order matters: max() of matching rules wins."""
NO_ACCESS = 0
READ_ONLY = 1
CUSTOM_ELEVATED = 2
ADMIN = 3 |
1,453 | c6a16b8e45c0f5d046ce4aed2a433921 | swh:1:cnt:468239060b4b177778f321640bb5d8c5ca4113b7;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=62-75/ | 9c216f0aaa4001b80c94ead40cb5156c1b0edad5 | growthbook | analytics | ldap-sync/ldap_sync/resolver.py | TargetState | type | class TargetState:
"""The desired role for a user, with full audit provenance.
`rule_number` records which T419622 rule produced the role, so
audit logs and incident review can answer "why did this user get
this role?" without re-deriving from the inputs. When multiple
Bitu rules match (e.g. user i... |
1,454 | c66f4950f8b1098b129bacf265883fcc | swh:1:cnt:468239060b4b177778f321640bb5d8c5ca4113b7;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=78-139/ | 9c216f0aaa4001b80c94ead40cb5156c1b0edad5 | growthbook | analytics | ldap-sync/ldap_sync/resolver.py | compute_target_state(
*,
user_uid: str,
bitu_memberships: Set[str],
posix_memberships: Mapping[str, Set[str]],
) | function | def compute_target_state(
*,
user_uid: str,
bitu_memberships: Set[str],
posix_memberships: Mapping[str, Set[str]],
) -> TargetState:
"""Return the target GrowthBook state for a user.
Args:
user_uid: The user's LDAP uid (e.g. "jdoe").
bitu_memberships: Set of Bitu group cn values... |
1,455 | 45e016146fdee06fdc8c566f8c23ff7f | swh:1:cnt:2b31afdefc8d2f0bbfba9b650045c5473e7ad44f;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=20-21/ | d3feb3ed4d849bb7c667d0c1f652b49a8672b653 | growthbook | analytics | ldap-sync/ldap_sync/collectors/data_yaml_collector.py | DataYamlError | type | class DataYamlError(Exception):
"""Raised when data.yaml cannot be fetched or required groups are missing.""" |
1,456 | ec1bd2844cbf52b185493148eba1ddeb | swh:1:cnt:2b31afdefc8d2f0bbfba9b650045c5473e7ad44f;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=24-31/ | d3feb3ed4d849bb7c667d0c1f652b49a8672b653 | growthbook | analytics | ldap-sync/ldap_sync/collectors/data_yaml_collector.py | _flatten_string_list(nested_list: NestedStrList) | function | def _flatten_string_list(nested_list: NestedStrList) -> list[str]:
flat_list: list[str] = []
for item in nested_list:
if isinstance(item, list):
flat_list.extend(_flatten_string_list(item))
else:
flat_list.append(item)
return flat_list |
1,457 | b640a56aec3b4c95a502c4a3fc6d4897 | swh:1:cnt:2b31afdefc8d2f0bbfba9b650045c5473e7ad44f;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=34-94/ | d3feb3ed4d849bb7c667d0c1f652b49a8672b653 | growthbook | analytics | ldap-sync/ldap_sync/collectors/data_yaml_collector.py | fetch_posix_memberships(
*,
url: str,
connect_timeout: float = 5.0,
read_timeout: float = 20.0,
session: requests.Session | None = None,
) | function | def fetch_posix_memberships(
*,
url: str,
connect_timeout: float = 5.0,
read_timeout: float = 20.0,
session: requests.Session | None = None,
) -> dict[str, frozenset[str]]:
"""Return {group_name: frozenset(uids)} for the four required groups."""
client = session or requests
try:
... |
1,458 | 56d9cdbfa6542806e59143ae83bc2207 | swh:1:cnt:65ba4e7c7f6cef2416bd506485c4b9dd988f5dcb;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=26-41/ | e15e23fe6f290faf85a0f0ed98d2fc8caf9ba892 | growthbook | analytics | ldap-sync/ldap_sync/collectors/growthbook_collector.py | role_string_to_enum(role_str: str | None, *, elevated_role_name: str) | function | # Map a GrowthBook role string to our Role enum. Built-in GB roles
# come back lowercase from the API; the custom elevated role name is
# matched as-is, since it could be any case
def role_string_to_enum(role_str: str | None, *, elevated_role_name: str) -> Role:
if not role_str:
return Role.NO_ACCESS
if... |
1,459 | 61f3e54900fa8060d695d3be5833beab | swh:1:cnt:65ba4e7c7f6cef2416bd506485c4b9dd988f5dcb;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=82-89/ | e15e23fe6f290faf85a0f0ed98d2fc8caf9ba892 | growthbook | analytics | ldap-sync/ldap_sync/collectors/growthbook_collector.py | _project_role_for(member: dict[str, Any], *, project_id: str, elevated_role_name: str) | function | def _project_role_for(member: dict[str, Any], *, project_id: str, elevated_role_name: str) -> Role:
project_roles = member.get("projectRoles") or []
for entry in project_roles:
if not isinstance(entry, dict):
continue
if entry.get("project") == project_id:
return role_str... |
1,460 | ec5507d5776b2f7896cfa60f40c5a59f | swh:1:cnt:65ba4e7c7f6cef2416bd506485c4b9dd988f5dcb;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=103-134/ | e15e23fe6f290faf85a0f0ed98d2fc8caf9ba892 | growthbook | analytics | ldap-sync/ldap_sync/collectors/growthbook_collector.py | project_roles_with_managed_set(
*,
existing_member: Mapping[str, Any],
project_id: str,
new_role_string: str | None,
) | function | def project_roles_with_managed_set(
*,
existing_member: Mapping[str, Any],
project_id: str,
new_role_string: str | None,
) -> list[dict[str, Any]]:
"""Build a new projectRoles array that updates ONLY the managed entry.
`new_role_string=None` removes the managed-project entry entirely
(revoc... |
1,461 | 5fbae90b807b0cc9117461cd9303183e | swh:1:cnt:65ba4e7c7f6cef2416bd506485c4b9dd988f5dcb;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=92-100/ | e15e23fe6f290faf85a0f0ed98d2fc8caf9ba892 | growthbook | analytics | ldap-sync/ldap_sync/collectors/growthbook_collector.py | role_enum_to_string(role: Role, *, elevated_role_name: str) | function | def role_enum_to_string(role: Role, *, elevated_role_name: str) -> str:
"""Inverse of role_string_to_enum for the three managed tiers."""
if role == Role.ADMIN:
return "admin"
if role == Role.CUSTOM_ELEVATED:
return elevated_role_name
if role == Role.READ_ONLY:
return "readonly"
... |
1,462 | 5790f7cd8a5bf586475ef6dc9c0874cf | swh:1:cnt:65ba4e7c7f6cef2416bd506485c4b9dd988f5dcb;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=44-79/ | e15e23fe6f290faf85a0f0ed98d2fc8caf9ba892 | growthbook | analytics | ldap-sync/ldap_sync/collectors/growthbook_collector.py | members_from_raw(
raw_members: list[dict[str, Any]],
*,
project_id: str,
elevated_role_name: str,
in_scope_emails: Set[str],
) | function | def members_from_raw(
raw_members: list[dict[str, Any]],
*,
project_id: str,
elevated_role_name: str,
in_scope_emails: Set[str],
) -> dict[str, CurrentMember]:
"""Return {lowercase_email: CurrentMember} for in-scope members.
Operates on an already-fetched raw member list. The sync CLI
f... |
1,463 | 2e0959076b027931e7b61b8389db789b | swh:1:cnt:48a93d90a68acd97aa382649556bdc811372935c;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=50-51/ | c41f927845d64b04ae2d6993fefe9addc4704a92 | growthbook | analytics | ldap-sync/ldap_sync/collectors/ldap_collector.py | LDAPCollectorError | type | class LDAPCollectorError(Exception):
"""Raised when LDAP queries fail or return inconsistent data.""" |
1,464 | b39df094714561ed6e8e4638f0bd4e09 | swh:1:cnt:48a93d90a68acd97aa382649556bdc811372935c;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=55-59/ | c41f927845d64b04ae2d6993fefe9addc4704a92 | growthbook | analytics | ldap-sync/ldap_sync/collectors/ldap_collector.py | BituSnapshot | type | class BituSnapshot:
"""Per-group uid memberships, plus uid → email resolution."""
memberships_by_group: dict[str, frozenset[str]] # group_cn → {uid}
uid_to_email: dict[str, str] # uid → lowercase email |
1,465 | f7512e05f988a4b4e657087efa2518a7 | swh:1:cnt:48a93d90a68acd97aa382649556bdc811372935c;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=111-139/ | c41f927845d64b04ae2d6993fefe9addc4704a92 | growthbook | analytics | ldap-sync/ldap_sync/collectors/ldap_collector.py | _build_connection(
*,
primary_uri: str,
fallback_uri: str | None,
ca_cert_path: str,
connect_timeout: float,
receive_timeout: float,
) | function | def _build_connection(
*,
primary_uri: str,
fallback_uri: str | None,
ca_cert_path: str,
connect_timeout: float,
receive_timeout: float,
) -> Connection:
tls = Tls(ca_certs_file=ca_cert_path, validate=ssl.CERT_REQUIRED)
# ldap3 requires an int for connect_timeout; ceil so sub-second
... |
1,466 | 10ec3e4d2720c9eed82668dec1235bff | swh:1:cnt:48a93d90a68acd97aa382649556bdc811372935c;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=163-185/ | c41f927845d64b04ae2d6993fefe9addc4704a92 | growthbook | analytics | ldap-sync/ldap_sync/collectors/ldap_collector.py | _resolve_emails(conn: Connection, uids: Iterable[str], chunk_size: int) | function | def _resolve_emails(conn: Connection, uids: Iterable[str], chunk_size: int) -> dict[str, str]:
result: dict[str, str] = {}
uids_list = sorted(uids) # deterministic chunk boundaries for tests
for i in range(0, len(uids_list), chunk_size):
chunk = uids_list[i : i + chunk_size]
if not chunk:
... |
1,467 | d3c49c7ff923abf6944438fdc47ae9c0 | swh:1:cnt:48a93d90a68acd97aa382649556bdc811372935c;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=206-214/ | c41f927845d64b04ae2d6993fefe9addc4704a92 | growthbook | analytics | ldap-sync/ldap_sync/collectors/ldap_collector.py | _detect_duplicate_emails(uid_to_email: dict[str, str]) | function | def _detect_duplicate_emails(uid_to_email: dict[str, str]) -> None:
seen: dict[str, str] = {}
for uid, email in uid_to_email.items():
if email in seen:
raise LDAPCollectorError(
f"two LDAP uids resolve to the same email {email!r}: "
f"{seen[email]!r} and {uid!... |
1,468 | 1b704d2a5b3d12e5ed0d118a044698d9 | swh:1:cnt:48a93d90a68acd97aa382649556bdc811372935c;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=62-108/ | c41f927845d64b04ae2d6993fefe9addc4704a92 | growthbook | analytics | ldap-sync/ldap_sync/collectors/ldap_collector.py | fetch_bitu_snapshot(
*,
primary_uri: str,
fallback_uri: str | None,
ca_cert_path: str,
connect_timeout: float = 10.0,
receive_timeout: float = 30.0,
chunk_size: int = 100,
connection: Connection | None = None,
) | function | def fetch_bitu_snapshot(
*,
primary_uri: str,
fallback_uri: str | None,
ca_cert_path: str,
connect_timeout: float = 10.0,
receive_timeout: float = 30.0,
chunk_size: int = 100,
connection: Connection | None = None,
) -> BituSnapshot:
"""Return a BituSnapshot for the three GrowthBook-*... |
1,469 | db4081f76184221ff067caac767fcfdc | swh:1:cnt:48a93d90a68acd97aa382649556bdc811372935c;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=142-160/ | c41f927845d64b04ae2d6993fefe9addc4704a92 | growthbook | analytics | ldap-sync/ldap_sync/collectors/ldap_collector.py | _fetch_group_uids(conn: Connection, group_cn: str) | function | def _fetch_group_uids(conn: Connection, group_cn: str) -> set[str]:
found = conn.search(
search_base=GROUPS_BASE_DN,
search_filter=f"(&(objectclass=groupOfNames)(cn={_escape_filter(group_cn)}))",
attributes=["member"],
)
if not found or not conn.entries:
# Group not present i... |
1,470 | 7cbbbd3bcfa6e9508ec2cea9d793ba2d | swh:1:cnt:48a93d90a68acd97aa382649556bdc811372935c;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=188-203/ | c41f927845d64b04ae2d6993fefe9addc4704a92 | growthbook | analytics | ldap-sync/ldap_sync/collectors/ldap_collector.py | _uid_from_dn(dn: str) | function | def _uid_from_dn(dn: str) -> str | None:
try:
components = parse_dn(dn, escape=False)
except Exception as e:
logger.warning(
"failed to parse DN",
extra={"dn": dn, "error": str(e), "error_type": type(e).__name__},
)
return None
for attr, value, _ in co... |
1,471 | aaed0d84c6ce920bcea3da40b2925617 | swh:1:cnt:48a93d90a68acd97aa382649556bdc811372935c;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=220-224/ | c41f927845d64b04ae2d6993fefe9addc4704a92 | growthbook | analytics | ldap-sync/ldap_sync/collectors/ldap_collector.py | _escape_filter(value: str) | function | def _escape_filter(value: str) -> str:
out = []
for ch in value:
out.append(_FILTER_ESCAPES.get(ch, ch))
return "".join(out) |
1,472 | c30e271fadfbb62568aca6073d75ba6e | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=14-24/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | _StubClient | type | class _StubClient:
"""Minimal stub for the applier."""
def __init__(self, *, fail_on_member_id: str | None = None) -> None:
self.calls: list[tuple[str, dict[str, Any]]] = []
self._fail_on = fail_on_member_id
def update_member_role(self, member_id: str, payload: dict[str, Any]) -> None:
... |
1,473 | e4f28415b66e91f731e5270264b6e48f | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=38-69/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | test_remove_payload_omits_managed_project() | function | # ---- payload shape ----
def test_remove_payload_omits_managed_project() -> None:
raw = {
"a@x": {
"projectRoles": [
{"project": "other", "role": "engineer"},
{"project": "prj1", "role": "admin"},
]
}
}
plan = Plan(
actions=(... |
1,474 | e7790b66a61702f322c2cd00b9beaa90 | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=91-114/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | test_update_payload_uses_custom_role_name() | function | def test_update_payload_uses_custom_role_name() -> None:
raw = {"a@x": {"projectRoles": [{"project": "prj1", "role": "readonly"}]}}
plan = Plan(
actions=(
_action(
ActionKind.UPDATE,
"a@x",
current=Role.READ_ONLY,
target=Role.CU... |
1,475 | 6d82143124c8404412498148b4486ccf | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=144-168/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | test_update_non_admin_role() | function | def test_update_non_admin_role() -> None:
raw = {"a@x": {"projectRoles": [{"project": "prj1", "role": "readonly"}]}}
plan = Plan(
actions=(
_action(
ActionKind.UPDATE,
"a@x",
current=Role.NO_ACCESS,
target=Role.READ_ONLY,
... |
1,476 | 40538894ed08999e19f28a2dfa79d1b4 | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=212-231/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | test_dry_run_makes_no_api_calls() | function | # ---- dry-run ----
def test_dry_run_makes_no_api_calls() -> None:
raw = {"a@x": {"projectRoles": []}}
plan = Plan(
actions=(_action(ActionKind.ADD, "a@x", current=Role.NO_ACCESS, target=Role.READ_ONLY),)
)
client = _StubClient()
result = apply_plan(
plan=plan,
client=clien... |
1,477 | 27b18c49a466291f398eb0b2db83e005 | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=259-283/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | test_noop_skipped_pending_sso_make_no_calls() | function | # ---- skip / noop / pending_sso classification ----
def test_noop_skipped_pending_sso_make_no_calls() -> None:
plan = Plan(
actions=(
_action(ActionKind.NOOP, "a@x", current=Role.READ_ONLY, target=Role.READ_ONLY),
_action(ActionKind.SKIPPED, "b@x", current=Role.ADMIN, target=Role.... |
1,478 | 16ea1ad2f98b035b27a27e1f7868c65f | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=324-325/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | test_auth_error_during_apply_propagates::auth_fail(*args: Any, **kwargs: Any) | function | def auth_fail(*args: Any, **kwargs: Any) -> None:
raise GrowthBookAuthError("revoked") |
1,479 | 1cede04a5a2c80f35d27329180c04eb2 | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=17-19/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | _StubClient::__init__(self, *, fail_on_member_id: str | None = None) | function | def __init__(self, *, fail_on_member_id: str | None = None) -> None:
self.calls: list[tuple[str, dict[str, Any]]] = []
self._fail_on = fail_on_member_id |
1,480 | a41fe57df6b32abff1d112d9af14184a | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=27-35/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | _action(kind: ActionKind, email: str, *, current: Role, target: Role) | function | def _action(kind: ActionKind, email: str, *, current: Role, target: Role) -> Action:
return Action(
email=email,
kind=kind,
current_role=current,
target_role=target,
rule_number=2,
growthbook_member_id=f"id-{email}",
) |
1,481 | 07b636b07946fd19d61b50e134f170c8 | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=72-88/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | test_add_payload_adds_managed_project() | function | def test_add_payload_adds_managed_project() -> None:
raw = {"a@x": {"projectRoles": []}}
plan = Plan(
actions=(_action(ActionKind.ADD, "a@x", current=Role.NO_ACCESS, target=Role.READ_ONLY),)
)
client = _StubClient()
apply_plan(
plan=plan,
client=client, # type: ignore[arg-ty... |
1,482 | 183e0d623bc762fd86134aa782e0f47b | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=21-24/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | _StubClient::update_member_role(self, member_id: str, payload: dict[str, Any]) | function | def update_member_role(self, member_id: str, payload: dict[str, Any]) -> None:
self.calls.append((member_id, payload))
if member_id == self._fail_on:
raise GrowthBookAPIError("simulated 500") |
1,483 | a7aef499adc690315f3f45234fdc0a4c | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=117-141/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | test_update_admin_role() | function | def test_update_admin_role() -> None:
raw = {"a@x": {"projectRoles": [{"project": "prj1", "role": "admin"}]}}
plan = Plan(
actions=(
_action(
ActionKind.UPDATE,
"a@x",
current=Role.READ_ONLY,
target=Role.ADMIN,
),
... |
1,484 | 1dd3759c9156410a95b6819635c66a58 | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=171-209/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | test_payload_preserves_other_projectroles() | function | def test_payload_preserves_other_projectroles() -> None:
"""An update to the managed project must leave other-project entries alone.
We use the Collect-phase snapshot for payload construction, which means
a UI edit between collect and apply could be clobbered. That's the
accepted race; this test pins t... |
1,485 | 889f602c55306da49cc189bf497fe1c0 | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=234-256/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | test_dry_run_metric_label_is_distinct() | function | def test_dry_run_metric_label_is_distinct() -> None:
metrics = Metrics()
raw = {"a@x": {"projectRoles": []}}
plan = Plan(
actions=(_action(ActionKind.ADD, "a@x", current=Role.NO_ACCESS, target=Role.READ_ONLY),)
)
apply_plan(
plan=plan,
client=_StubClient(), # type: ignore[ar... |
1,486 | 4907d4444bfd6b16e6c3e109d547e0ea | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=312-337/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | test_auth_error_during_apply_propagates() | function | def test_auth_error_during_apply_propagates() -> None:
"""Mid-run credential revocation should halt rather than N x fail
as per-user errors."""
raw = {f"u{i}@x": {"projectRoles": []} for i in range(3)}
plan = Plan(
actions=tuple(
_action(ActionKind.ADD, f"u{i}@x", current=Role.NO_ACC... |
1,487 | f106112673d1c8240355ee36f56b8a50 | swh:1:cnt:f6faaec0ef7d336fc24892d9b98aef36f3a23129;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=286-309/ | 6eeb71aebe651295859606c73aa725b67fa9080e | growthbook | analytics | ldap-sync/tests/test_applier.py | test_per_user_error_does_not_abort_run() | function | # ---- error handling ----
def test_per_user_error_does_not_abort_run() -> None:
raw = {"a@x": {"projectRoles": []}, "b@x": {"projectRoles": []}}
plan = Plan(
actions=(
_action(ActionKind.ADD, "a@x", current=Role.NO_ACCESS, target=Role.READ_ONLY),
_action(ActionKind.ADD, "b@x",... |
1,488 | 20a0e7d693705e9a415e903031f66b79 | swh:1:cnt:35a18c85eca73f31b32a73ce444bf2ee5a9f8eee;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=20-26/ | 8aeabfc9cb76a5184d33decbf5b60fb532768ed1 | growthbook | analytics | ldap-sync/tests/test_cli.py | test_cli_missing_required_option_fails() | function | def test_cli_missing_required_option_fails() -> None:
runner = CliRunner()
result = runner.invoke(cli, ["sync"], env={}, catch_exceptions=False)
# Click's required-option failure exits with code 2 and an error
# message about the missing option
assert result.exit_code != 0
assert "missing" in re... |
1,489 | b3d164bc0033572dba05c64050a2bac6 | swh:1:cnt:35a18c85eca73f31b32a73ce444bf2ee5a9f8eee;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=48-49/ | 8aeabfc9cb76a5184d33decbf5b60fb532768ed1 | growthbook | analytics | ldap-sync/tests/test_cli.py | _Raiser::__init__(self, exc: Exception) | function | def __init__(self, exc: Exception) -> None:
self._exc = exc |
1,490 | 456b31f9cb167c2477e4c9eb0aceaf7d | swh:1:cnt:35a18c85eca73f31b32a73ce444bf2ee5a9f8eee;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=37-41/ | 8aeabfc9cb76a5184d33decbf5b60fb532768ed1 | growthbook | analytics | ldap-sync/tests/test_cli.py | test_sync_help_shows_dry_run() | function | def test_sync_help_shows_dry_run() -> None:
runner = CliRunner()
result = runner.invoke(cli, ["sync", "--help"])
assert result.exit_code == 0
assert "--dry-run" in result.output |
1,491 | 64e0dcec27fa236f10c05aed70309d51 | swh:1:cnt:35a18c85eca73f31b32a73ce444bf2ee5a9f8eee;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=110-141/ | 8aeabfc9cb76a5184d33decbf5b60fb532768ed1 | growthbook | analytics | ldap-sync/tests/test_cli.py | test_sync_emits_seats_metric(monkeypatch: pytest.MonkeyPatch) | function | def test_sync_emits_seats_metric(monkeypatch: pytest.MonkeyPatch) -> None:
"""sync must populate growthbook_sync_seats_total. Production CronJob
runs sync; if seats only emits from report, dashboards stay empty."""
from ldap_sync.applier import ApplyResult
from ldap_sync.metrics import Metrics
capt... |
1,492 | 4a24071545f29da9ef33a5c49a6163dc | swh:1:cnt:35a18c85eca73f31b32a73ce444bf2ee5a9f8eee;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=161-182/ | 8aeabfc9cb76a5184d33decbf5b60fb532768ed1 | growthbook | analytics | ldap-sync/tests/test_cli.py | test_pushgateway_job_overridable_via_env(monkeypatch: pytest.MonkeyPatch) | function | def test_pushgateway_job_overridable_via_env(monkeypatch: pytest.MonkeyPatch) -> None:
"""Two ldap-sync deployments (e.g. one per GrowthBook release) must be
able to push under distinct `job` labels so their metrics don't
collide on the same Prometheus series."""
captured: list[str] = []
def fake_p... |
1,493 | 524cc6234423e897256070da408bf7d9 | swh:1:cnt:35a18c85eca73f31b32a73ce444bf2ee5a9f8eee;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=51-52/ | 8aeabfc9cb76a5184d33decbf5b60fb532768ed1 | growthbook | analytics | ldap-sync/tests/test_cli.py | _Raiser::__call__(self, *args: Any, **kwargs: Any) | function | def __call__(self, *args: Any, **kwargs: Any) -> Any:
raise self._exc |
1,494 | 9f6c592c985110717d2e9580133aeac0 | swh:1:cnt:35a18c85eca73f31b32a73ce444bf2ee5a9f8eee;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=29-34/ | 8aeabfc9cb76a5184d33decbf5b60fb532768ed1 | growthbook | analytics | ldap-sync/tests/test_cli.py | test_help_works() | function | def test_help_works() -> None:
runner = CliRunner()
result = runner.invoke(cli, ["--help"])
assert result.exit_code == 0
assert "sync" in result.output
assert "report" in result.output |
1,495 | 4a049b57dee1e75b2c459ddd0465366e | swh:1:cnt:35a18c85eca73f31b32a73ce444bf2ee5a9f8eee;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=66-68/ | 8aeabfc9cb76a5184d33decbf5b60fb532768ed1 | growthbook | analytics | ldap-sync/tests/test_cli.py | _MarkingCollector::__init__(self, source: str, return_value: Any = None) | function | def __init__(self, source: str, return_value: Any = None) -> None:
self._source = source
self._return_value = return_value if return_value is not None else [] |
1,496 | 3c4e0ee2161d644ddb1e5eb00d6ebb64 | swh:1:cnt:35a18c85eca73f31b32a73ce444bf2ee5a9f8eee;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=70-77/ | 8aeabfc9cb76a5184d33decbf5b60fb532768ed1 | growthbook | analytics | ldap-sync/tests/test_cli.py | _MarkingCollector::__call__(self, *args: Any, **kwargs: Any) | function | def __call__(self, *args: Any, **kwargs: Any) -> Any:
# Find the metrics arg (passed positionally as second arg in the
# real helpers, or as kwarg)
metrics = args[-1] if args else kwargs["metrics"]
metrics.source_healthy.labels(source=self._source).set(1)
if self._source == "grow... |
1,497 | 07d8816050cc8e1a28085e90498a4763 | swh:1:cnt:35a18c85eca73f31b32a73ce444bf2ee5a9f8eee;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=90-97/ | 8aeabfc9cb76a5184d33decbf5b60fb532768ed1 | growthbook | analytics | ldap-sync/tests/test_cli.py | test_sync_exits_1_on_any_collection_error(
monkeypatch: pytest.MonkeyPatch, exception: Exception
) | function | def test_sync_exits_1_on_any_collection_error(
monkeypatch: pytest.MonkeyPatch, exception: Exception
) -> None:
"""All failure paths collapse to exit 1; detail goes to logs not exit codes."""
monkeypatch.setattr("ldap_sync.cli._validate_and_collect_growthbook", _Raiser(exception))
runner = CliRunner()
... |
1,498 | e17ef067f8ec2cf170e28e512c4a594e | swh:1:cnt:35a18c85eca73f31b32a73ce444bf2ee5a9f8eee;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=100-107/ | 8aeabfc9cb76a5184d33decbf5b60fb532768ed1 | growthbook | analytics | ldap-sync/tests/test_cli.py | test_report_exits_1_on_collection_error(monkeypatch: pytest.MonkeyPatch) | function | def test_report_exits_1_on_collection_error(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setattr(
"ldap_sync.cli._validate_and_collect_growthbook",
_Raiser(LDAPCollectorError("x")),
)
runner = CliRunner()
result = runner.invoke(cli, ["report"], env=VALID_ENV, catch_exceptions=Fa... |
1,499 | 9c8f531c9e4fe11ead8c561a60e4552c | swh:1:cnt:35a18c85eca73f31b32a73ce444bf2ee5a9f8eee;origin=https://gitlab.wikimedia.org/repos/data-engineering/growthbook.git;lines=119-121/ | 8aeabfc9cb76a5184d33decbf5b60fb532768ed1 | growthbook | analytics | ldap-sync/tests/test_cli.py | test_sync_emits_seats_metric::capturing_init(self: Metrics) | function | def capturing_init(self: Metrics) -> None:
real_init(self)
captured.append(self) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.