Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions inference/core/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,10 @@
ROBOFLOW_API_REQUEST_TIMEOUT = int(ROBOFLOW_API_REQUEST_TIMEOUT)


# Control SSL certificate verification for requests to the Roboflow API
# Default is True (verify SSL). Set ROBOFLOW_API_VERIFY_SSL=false to disable in local dev.
ROBOFLOW_API_VERIFY_SSL = str2bool(os.getenv("ROBOFLOW_API_VERIFY_SSL", "True"))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needed for the new localapi because Python doesn't respect the system keychain certificate store apparently.


IGNORE_MODEL_DEPENDENCIES_WARNINGS = str2bool(
os.getenv("IGNORE_MODEL_DEPENDENCIES_WARNINGS", "False")
)
Expand Down
8 changes: 7 additions & 1 deletion inference/core/managers/pingback.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
METRICS_ENABLED,
METRICS_INTERVAL,
METRICS_URL,
ROBOFLOW_API_VERIFY_SSL,
TAGS,
)
from inference.core.logger import logger
Expand Down Expand Up @@ -122,7 +123,12 @@ def post_data(self, model_manager):
GLOBAL_INFERENCE_SERVER_ID, model_id, min=start, max=now
)
all_data["inference_results"] = all_data["inference_results"] + results
res = requests.post(wrap_url(METRICS_URL), json=all_data, timeout=10)
res = requests.post(
wrap_url(METRICS_URL),
json=all_data,
timeout=10,
verify=ROBOFLOW_API_VERIFY_SSL,
)
try:
api_key_safe_raise_for_status(response=res)
logger.debug(
Expand Down
64 changes: 43 additions & 21 deletions inference/core/roboflow_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
RETRY_CONNECTION_ERRORS_TO_ROBOFLOW_API,
ROBOFLOW_API_EXTRA_HEADERS,
ROBOFLOW_API_REQUEST_TIMEOUT,
ROBOFLOW_API_VERIFY_SSL,
ROBOFLOW_SERVICE_SECRET,
TRANSIENT_ROBOFLOW_API_ERRORS,
TRANSIENT_ROBOFLOW_API_ERRORS_RETRIES,
Expand Down Expand Up @@ -279,6 +280,7 @@ def add_custom_metadata(
},
headers=build_roboflow_api_headers(),
timeout=ROBOFLOW_API_REQUEST_TIMEOUT,
verify=ROBOFLOW_API_VERIFY_SSL,
)
api_key_safe_raise_for_status(response=response)

Expand Down Expand Up @@ -521,6 +523,7 @@ def register_image_at_roboflow(
data=m,
headers=headers,
timeout=ROBOFLOW_API_REQUEST_TIMEOUT,
verify=ROBOFLOW_API_VERIFY_SSL,
)
api_key_safe_raise_for_status(response=response)
parsed_response = response.json()
Expand Down Expand Up @@ -564,6 +567,7 @@ def annotate_image_at_roboflow(
data=annotation_content,
headers=headers,
timeout=ROBOFLOW_API_REQUEST_TIMEOUT,
verify=ROBOFLOW_API_VERIFY_SSL,
)
api_key_safe_raise_for_status(response=response)
parsed_response = response.json()
Expand Down Expand Up @@ -839,6 +843,7 @@ def _get_from_url(
wrap_url(url),
headers=build_roboflow_api_headers(),
timeout=ROBOFLOW_API_REQUEST_TIMEOUT,
verify=ROBOFLOW_API_VERIFY_SSL,
)

except (ConnectionError, Timeout, requests.exceptions.ConnectionError) as error:
Expand Down Expand Up @@ -913,6 +918,7 @@ def send_inference_results_to_model_monitoring(
json=inference_data,
headers=build_roboflow_api_headers(),
timeout=ROBOFLOW_API_REQUEST_TIMEOUT,
verify=ROBOFLOW_API_VERIFY_SSL,
)
api_key_safe_raise_for_status(response=response)

Expand All @@ -932,32 +938,48 @@ def build_roboflow_api_headers(
return explicit_headers


@wrap_roboflow_api_errors()
def post_to_roboflow_api(
endpoint: str,
api_key: Optional[str],
payload: Optional[dict] = None,
params: Optional[List[Tuple[str, str]]] = None,
http_errors_handlers: Optional[
Dict[int, Callable[[Union[requests.exceptions.HTTPError]], None]]
] = None,
) -> dict:
"""Generic function to make a POST request to the Roboflow API."""
url_params = []
if api_key:
url_params.append(("api_key", api_key))
if params:
url_params.extend(params)

full_url = _add_params_to_url(
url=f"{API_BASE_URL}/{endpoint.strip('/')}", params=url_params
)
wrapped_url = wrap_url(full_url)
"""Generic function to make a POST request to the Roboflow API.

Args:
endpoint: API endpoint path
api_key: Roboflow API key
payload: JSON payload
params: Additional URL parameters
http_errors_handlers: Optional custom HTTP error handlers by status code
"""

@wrap_roboflow_api_errors(http_errors_handlers=http_errors_handlers)
def _make_request():
url_params = []
if api_key:
url_params.append(("api_key", api_key))
if params:
url_params.extend(params)

full_url = _add_params_to_url(
url=f"{API_BASE_URL}/{endpoint.strip('/')}", params=url_params
)
wrapped_url = wrap_url(full_url)

headers = build_roboflow_api_headers()
headers = build_roboflow_api_headers()

response = requests.post(
url=wrapped_url,
json=payload,
headers=headers,
timeout=ROBOFLOW_API_REQUEST_TIMEOUT,
)
api_key_safe_raise_for_status(response=response)
return response.json()
response = requests.post(
url=wrapped_url,
json=payload,
headers=headers,
timeout=ROBOFLOW_API_REQUEST_TIMEOUT,
verify=ROBOFLOW_API_VERIFY_SSL,
)
api_key_safe_raise_for_status(response=response)
return response.json()

return _make_request()
4 changes: 4 additions & 0 deletions inference/core/workflows/core_steps/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@
from inference.core.workflows.core_steps.sinks.email_notification.v1 import (
EmailNotificationBlockV1,
)
from inference.core.workflows.core_steps.sinks.email_notification.v2 import (
EmailNotificationBlockV2,
)
from inference.core.workflows.core_steps.sinks.local_file.v1 import LocalFileSinkBlockV1
from inference.core.workflows.core_steps.sinks.onvif_movement.v1 import ONVIFSinkBlockV1
from inference.core.workflows.core_steps.sinks.roboflow.custom_metadata.v1 import (
Expand Down Expand Up @@ -666,6 +669,7 @@ def load_blocks() -> List[Type[WorkflowBlock]]:
DataAggregatorBlockV1,
CSVFormatterBlockV1,
EmailNotificationBlockV1,
EmailNotificationBlockV2,
LocalFileSinkBlockV1,
TraceVisualizationBlockV1,
ReferencePathVisualizationBlockV1,
Expand Down
Loading
Loading