Skip to content

Commit fdcce8b

Browse files
committed
Added FastAPI router for Rust package repository endpoints; added endpoint to download config.json file from
1 parent 886361e commit fdcce8b

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/murfey/server/api/bootstrap.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
from __future__ import annotations
1616

1717
import functools
18+
import io
19+
import json
1820
import logging
1921
import random
2022
import re
@@ -23,7 +25,7 @@
2325
import packaging.version
2426
import requests
2527
from fastapi import APIRouter, HTTPException, Request, Response
26-
from fastapi.responses import FileResponse, HTMLResponse
28+
from fastapi.responses import FileResponse, HTMLResponse, StreamingResponse
2729

2830
import murfey
2931
from murfey.server import get_machine_config, respond_with_template
@@ -43,6 +45,7 @@
4345
bootstrap = APIRouter(prefix="/bootstrap", tags=["bootstrap"])
4446
cygwin = APIRouter(prefix="/cygwin", tags=["bootstrap"])
4547
msys2 = APIRouter(prefix="/msys2", tags=["bootstrap"])
48+
rust = APIRouter(prefix="/rust", tags=["bootstrap"])
4649
pypi = APIRouter(prefix="/pypi", tags=["bootstrap"])
4750
plugins = APIRouter(prefix="/plugins", tags=["bootstrap"])
4851

@@ -565,6 +568,44 @@ def get_msys2_package_file(
565568
raise HTTPException(status_code=package_file.status_code)
566569

567570

571+
"""
572+
=======================================================================================
573+
RUST-RELATED FUNCTIONS AND ENDPOINTS
574+
=======================================================================================
575+
"""
576+
577+
rust_dl = "https://static.crates.io/crates"
578+
rust_api = "https://crates.io"
579+
580+
581+
@rust.get("/cargo/config.json", response_class=StreamingResponse)
582+
def get_maturin_config(request: Request):
583+
"""
584+
Download a config.json file used by Maturin that is used when integrating Rust
585+
backends for Python packages. This file will determine where Maturin sources
586+
Rust backend packages from.
587+
588+
This config is to be saved in ~/.cargo/registry/config.json
589+
"""
590+
591+
# Construct config file with the necessary endpoints
592+
config = {
593+
"dl": f"{request.url.scheme}://{request.url.netloc}/crates",
594+
"api": f"{request.url.scheme}://{request.url.netloc}/api/crates",
595+
# "proxy": f"{request.url.scheme}://{request.url.netloc}",
596+
}
597+
598+
# Save it as a JSON and return it as part of the response
599+
json_data = json.dumps(config, indent=4)
600+
json_bytes = io.BytesIO(json_data.encode("utf-8"))
601+
602+
return StreamingResponse(
603+
json_bytes,
604+
media_type="application/json",
605+
headers={"Content-Disposition": "attachment; filename=config.json"},
606+
)
607+
608+
568609
"""
569610
=======================================================================================
570611
PYPI-RELATED FUNCTIONS AND ENDPOINTS

src/murfey/server/main.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class Settings(BaseSettings):
6565
app.include_router(murfey.server.api.bootstrap.bootstrap)
6666
app.include_router(murfey.server.api.bootstrap.cygwin)
6767
app.include_router(murfey.server.api.bootstrap.msys2)
68+
app.include_router(murfey.server.api.bootstrap.rust)
6869
app.include_router(murfey.server.api.bootstrap.pypi)
6970
app.include_router(murfey.server.api.bootstrap.plugins)
7071
app.include_router(murfey.server.api.clem.router)

0 commit comments

Comments
 (0)