Make the dotnet endpoint and functions configurable in the cli (#2190)

This commit is contained in:
Cheick Keita
2022-07-25 15:12:36 -07:00
committed by GitHub
parent bae35dec97
commit 992751044f
2 changed files with 22 additions and 2 deletions

View File

@ -1714,6 +1714,8 @@ class Onefuzz:
client_secret: Optional[str] = None,
authority: Optional[str] = None,
tenant_domain: Optional[str] = None,
_dotnet_endpoint: Optional[str] = None,
_dotnet_functions: Optional[List[str]] = None,
) -> None:
if endpoint:
@ -1726,6 +1728,10 @@ class Onefuzz:
self._backend.client_secret = client_secret
if tenant_domain is not None:
self._backend.config.tenant_domain = tenant_domain
if _dotnet_endpoint is not None:
self._backend.config.dotnet_endpoint = _dotnet_endpoint
if _dotnet_functions is not None:
self._backend.config.dotnet_functions = _dotnet_functions
if self._backend.is_feature_enabled(PreviewFeature.job_templates.name):
self.job_templates._load_cache()
@ -1769,6 +1775,8 @@ class Onefuzz:
client_id: Optional[str] = None,
enable_feature: Optional[PreviewFeature] = None,
tenant_domain: Optional[str] = None,
_dotnet_endpoint: Optional[str] = None,
_dotnet_functions: Optional[List[str]] = None,
reset: Optional[bool] = None,
) -> BackendConfig:
"""Configure onefuzz CLI"""
@ -1799,6 +1807,10 @@ class Onefuzz:
self._backend.enable_feature(enable_feature.name)
if tenant_domain is not None:
self._backend.config.tenant_domain = tenant_domain
if _dotnet_endpoint is not None:
self._backend.config.dotnet_endpoint = _dotnet_endpoint
if _dotnet_functions is not None:
self._backend.config.dotnet_functions = _dotnet_functions
self._backend.app = None
self._backend.save_config()

View File

@ -92,6 +92,8 @@ class BackendConfig(BaseModel):
endpoint: Optional[str]
features: Set[str] = Field(default_factory=set)
tenant_domain: Optional[str]
dotnet_endpoint: Optional[str]
dotnet_functions: Optional[List[str]]
class Backend:
@ -280,9 +282,15 @@ class Backend:
params: Optional[Any] = None,
_retry_on_auth_failure: bool = True,
) -> Any:
if not self.config.endpoint:
if self.config.dotnet_functions and path in self.config.dotnet_functions:
endpoint = self.config.dotnet_endpoint
else:
endpoint = self.config.endpoint
if not endpoint:
raise Exception("endpoint not configured")
url = self.config.endpoint + "/api/" + path
url = endpoint + "/api/" + path
headers = self.headers()
json_data = serialize(json_data)