Skip to content

Commit ff98987

Browse files
Merge pull request #843 from roboflow/public-workflow
Don't Require API Keys for Public Workflows
2 parents 8cb07a7 + 25c2871 commit ff98987

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

inference/core/entities/requests/workflows.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88

99

1010
class WorkflowInferenceRequest(BaseModel):
11-
api_key: str = Field(
11+
api_key: Optional[str] = Field(
12+
default=None,
1213
description="Roboflow API Key that will be passed to the model during initialization for artifact retrieval",
1314
)
1415
inputs: Dict[str, Any] = Field(

inference/core/roboflow_api.py

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,15 @@ def get_roboflow_labeling_jobs(
393393

394394

395395
def get_workflow_cache_file(
396-
workspace_id: WorkspaceID, workflow_id: str, api_key: str
396+
workspace_id: WorkspaceID, workflow_id: str, api_key: Optional[str]
397397
) -> str:
398398
sanitized_workspace_id = sanitize_path_segment(workspace_id)
399399
sanitized_workflow_id = sanitize_path_segment(workflow_id)
400-
api_key_hash = hashlib.md5(api_key.encode("utf-8")).hexdigest()
400+
api_key_hash = (
401+
hashlib.md5(api_key.encode("utf-8")).hexdigest()
402+
if api_key is not None
403+
else "None"
404+
)
401405
prefix = os.path.abspath(os.path.join(MODEL_CACHE_DIR, "workflow"))
402406
result = os.path.abspath(
403407
os.path.join(
@@ -414,7 +418,7 @@ def get_workflow_cache_file(
414418

415419

416420
def cache_workflow_response(
417-
workspace_id: WorkspaceID, workflow_id: str, api_key: str, response: dict
421+
workspace_id: WorkspaceID, workflow_id: str, api_key: Optional[str], response: dict
418422
):
419423
workflow_cache_file = get_workflow_cache_file(
420424
workspace_id=workspace_id,
@@ -431,7 +435,7 @@ def cache_workflow_response(
431435
def delete_cached_workflow_response_if_exists(
432436
workspace_id: WorkspaceID,
433437
workflow_id: str,
434-
api_key: str,
438+
api_key: Optional[str],
435439
) -> None:
436440
workflow_cache_file = get_workflow_cache_file(
437441
workspace_id=workspace_id,
@@ -445,7 +449,7 @@ def delete_cached_workflow_response_if_exists(
445449
def load_cached_workflow_response(
446450
workspace_id: WorkspaceID,
447451
workflow_id: str,
448-
api_key: str,
452+
api_key: Optional[str],
449453
) -> Optional[dict]:
450454
workflow_cache_file = get_workflow_cache_file(
451455
workspace_id=workspace_id,
@@ -467,7 +471,7 @@ def load_cached_workflow_response(
467471

468472
@wrap_roboflow_api_errors()
469473
def get_workflow_specification(
470-
api_key: str,
474+
api_key: Optional[str],
471475
workspace_id: WorkspaceID,
472476
workflow_id: str,
473477
use_cache: bool = True,
@@ -483,9 +487,12 @@ def get_workflow_specification(
483487
)
484488
if cached_entry:
485489
return cached_entry
490+
params = []
491+
if api_key is not None:
492+
params.append(("api_key", api_key))
486493
api_url = _add_params_to_url(
487494
url=f"{API_BASE_URL}/{workspace_id}/workflows/{workflow_id}",
488-
params=[("api_key", api_key)],
495+
params=params,
489496
)
490497
try:
491498
response = _get_from_url(url=api_url)
@@ -533,7 +540,7 @@ def get_workflow_specification(
533540

534541

535542
def _retrieve_workflow_specification_from_ephemeral_cache(
536-
api_key: str,
543+
api_key: Optional[str],
537544
workspace_id: WorkspaceID,
538545
workflow_id: str,
539546
ephemeral_cache: BaseCache,
@@ -547,7 +554,7 @@ def _retrieve_workflow_specification_from_ephemeral_cache(
547554

548555

549556
def _cache_workflow_specification_in_ephemeral_cache(
550-
api_key: str,
557+
api_key: Optional[str],
551558
workspace_id: WorkspaceID,
552559
workflow_id: str,
553560
specification: dict,
@@ -566,11 +573,15 @@ def _cache_workflow_specification_in_ephemeral_cache(
566573

567574

568575
def _prepare_workflow_response_cache_key(
569-
api_key: str,
576+
api_key: Optional[str],
570577
workspace_id: WorkspaceID,
571578
workflow_id: str,
572579
) -> str:
573-
api_key_hash = hashlib.md5(api_key.encode("utf-8")).hexdigest()
580+
api_key_hash = (
581+
hashlib.md5(api_key.encode("utf-8")).hexdigest()
582+
if api_key is not None
583+
else "None"
584+
)
574585
return f"workflow_definition:{workspace_id}:{workflow_id}:{api_key_hash}"
575586

576587

0 commit comments

Comments
 (0)