Skip to content

Commit 99ac24a

Browse files
Allow Bearer on Admin OIE REST and fix staging filing lookup.
Staging monitors need API-key access to /admin/oie and related ops routes; also resolve CRE links by uuid or external_id and align ingest test asserts with skip_c1/max_repos=0. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent a2e8cec commit 99ac24a

4 files changed

Lines changed: 36 additions & 7 deletions

File tree

‎application/tests/admin_panel_test.py‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,7 @@ def test_oie_start_defaults_to_live_sync(self) -> None:
720720
max_repos=service.DEFAULT_OIE_MAX_REPOS,
721721
skip_b=False,
722722
skip_c=False,
723+
skip_c1=False,
723724
)
724725
pipe = c.get("/admin/pipeline").get_json()
725726
stages = {e["stage"] for e in pipe["events"]}
@@ -743,14 +744,24 @@ def test_oie_start_defaults_to_live_sync(self) -> None:
743744
max_repos=2,
744745
skip_b=False,
745746
skip_c=False,
747+
skip_c1=False,
746748
)
747749

748750
r = c.post(
749751
"/admin/ingest/start",
750752
json={"target_id": "repo1", "max_repos": 0},
751753
)
752-
self.assertEqual(r.status_code, 400)
753-
self.assertIn("max_repos", (r.get_json() or {}).get("description", ""))
754+
self.assertEqual(r.status_code, 200, r.data)
755+
mock_oie.assert_called_with(
756+
r.get_json()["run_id"],
757+
repos_yaml=str(service.REPOS_YAML),
758+
dry_run=False,
759+
sync_repos=True,
760+
max_repos=0,
761+
skip_b=False,
762+
skip_c=False,
763+
skip_c1=False,
764+
)
754765

755766
with self.app.test_client() as c:
756767
c.post(
@@ -1600,6 +1611,7 @@ def test_built_in_agent_is_a_resource_not_a_crud_row(self) -> None:
16001611
max_repos=service.DEFAULT_OIE_MAX_REPOS,
16011612
skip_b=False,
16021613
skip_c=False,
1614+
skip_c1=False,
16031615
)
16041616

16051617
@patch.dict(os.environ, {"NO_LOGIN": "1", "CRE_ALLOW_IMPORT": "1"})

‎application/tests/api_tokens_test.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,8 @@ def test_bad_signature_rejected(self) -> None:
206206
)
207207
self.assertEqual(resp.status_code, 401)
208208

209-
def test_admin_get_rejects_bearer(self) -> None:
210-
"""Admin surfaces require Google session — API keys are denied."""
209+
def test_admin_oie_allows_bearer(self) -> None:
210+
"""OIE Admin REST allows API keys for machine ops."""
211211
minted = mint.mint_api_token(
212212
user=self.admin,
213213
name="admin-read",
@@ -219,4 +219,4 @@ def test_admin_get_rejects_bearer(self) -> None:
219219
"/admin/oie/rq/status",
220220
headers={"Authorization": f"Bearer {minted.token}"},
221221
)
222-
self.assertIn(resp.status_code, (401, 302), resp.data)
222+
self.assertEqual(resp.status_code, 200, resp.data)

‎application/utils/api_tokens/verify.py‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,21 @@ def extract_raw_token() -> Optional[str]:
3636
def api_key_allowed_for_request() -> bool:
3737
"""True when this request may authenticate via API key.
3838
39-
Admin HTML/API surfaces require a Google session (not a bearer token).
39+
OIE/agent Admin REST allows Bearer for machine ops; other /admin HTML
40+
surfaces still require a Google session.
4041
"""
4142
path = request.path or ""
43+
ops_prefixes = (
44+
"/admin/oie/",
45+
"/admin/ingest",
46+
"/admin/agent/",
47+
"/admin/config",
48+
"/admin/pipeline",
49+
"/admin/dashboard",
50+
"/admin/upstream-sync",
51+
)
52+
if path == "/admin/config" or any(path.startswith(p) for p in ops_prefixes):
53+
return True
4254
if path.startswith("/admin/") or path.startswith("/rest/v1/admin/"):
4355
return False
4456
if path.startswith("/rest/v1/api-keys"):

‎application/utils/oie_scheduler/graph_filer.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,13 @@ def file_linked_decisions(
166166

167167
db_cres = []
168168
for link in sure:
169+
# Librarian proposals store CRE primary key (uuid); also accept
170+
# human-facing external_id (e.g. "123-456") for hand-authored rows.
169171
db_cre = (
170-
session.query(db.CRE).filter(db.CRE.external_id == link.cre_id).first()
172+
session.query(db.CRE).filter(db.CRE.id == link.cre_id).first()
173+
or session.query(db.CRE)
174+
.filter(db.CRE.external_id == link.cre_id)
175+
.first()
171176
)
172177
if db_cre is None:
173178
result.unknown_cre += 1

0 commit comments

Comments
 (0)