mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-09 08:08:32 +00:00
Some checks failed
Notify Downstream / notify-downstream (push) Has been cancelled
Update Test Durations / update-durations (3.10) (push) Has been cancelled
Update Test Durations / update-durations (3.11) (push) Has been cancelled
Update Test Durations / update-durations (3.12) (push) Has been cancelled
Update Test Durations / update-durations (3.13) (push) Has been cancelled
Mark stale issues and pull requests / stale (push) Has been cancelled
Co-authored-by: Greyson LaLonde <greyson.r.lalonde@gmail.com>
26 lines
777 B
Python
26 lines
777 B
Python
import os
|
|
import contextvars
|
|
from typing import Optional
|
|
from contextlib import contextmanager
|
|
|
|
_platform_integration_token: contextvars.ContextVar[Optional[str]] = contextvars.ContextVar(
|
|
"platform_integration_token", default=None
|
|
)
|
|
|
|
def set_platform_integration_token(integration_token: str) -> None:
|
|
_platform_integration_token.set(integration_token)
|
|
|
|
def get_platform_integration_token() -> Optional[str]:
|
|
token = _platform_integration_token.get()
|
|
if token is None:
|
|
token = os.getenv("CREWAI_PLATFORM_INTEGRATION_TOKEN")
|
|
return token
|
|
|
|
@contextmanager
|
|
def platform_context(integration_token: str):
|
|
token = _platform_integration_token.set(integration_token)
|
|
try:
|
|
yield
|
|
finally:
|
|
_platform_integration_token.reset(token)
|