Skip to content

Commit

Permalink
Merge pull request #988 from roboflow/handle-models-obtained-through-…
Browse files Browse the repository at this point in the history
…getWeights-in-authorizer-middleware

Simplify dedicated deployments authorizer middleware to rely on workspace ID match
  • Loading branch information
grzegorz-roboflow authored Jan 30, 2025
2 parents 2be7b0a + 9861278 commit 8f8dabf
Showing 1 changed file with 3 additions and 24 deletions.
27 changes: 3 additions & 24 deletions inference/core/interfaces/http/http_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@
from inference.core.managers.prometheus import InferenceInstrumentator
from inference.core.roboflow_api import (
get_roboflow_dataset_type,
get_roboflow_instant_model_data,
get_roboflow_workspace,
get_workflow_specification,
)
Expand Down Expand Up @@ -590,7 +591,6 @@ async def device_stats():

if DEDICATED_DEPLOYMENT_WORKSPACE_URL:
cached_api_keys = dict()
cached_projects = dict()

@app.middleware("http")
async def check_authorization(request: Request, call_next):
Expand All @@ -600,6 +600,8 @@ async def check_authorization(request: Request, call_next):
or request.url.path
in [
"/",
"/docs",
"/redoc",
"/info",
"/workflows/blocks/describe",
"/workflows/definition/schema",
Expand Down Expand Up @@ -648,29 +650,6 @@ def _unauthorized_response(msg):
except RoboflowAPINotAuthorizedError as e:
return _unauthorized_response("Unauthorized api_key")

# check project_url
model_id = json_params.get("model_id", "")
project_url = (
req_params.get("project", None)
or json_params.get("project", None)
or model_id.split("/")[0]
)
# only check when project_url is not None
if (
project_url is not None
and cached_projects.get(project_url, 0) < time.time()
):
try:
_ = get_roboflow_dataset_type(
api_key, DEDICATED_DEPLOYMENT_WORKSPACE_URL, project_url
)

cached_projects[project_url] = (
time.time() + 3600
) # expired after 1 hour
except RoboflowAPINotNotFoundError as e:
return _unauthorized_response("Unauthorized project")

return await call_next(request)

self.app = app
Expand Down

0 comments on commit 8f8dabf

Please sign in to comment.