Skip to content
This repository was archived by the owner on Nov 1, 2023. It is now read-only.
Merged
29 changes: 0 additions & 29 deletions src/cli/onefuzz/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ def _req_model(
as_params: bool = False,
alternate_endpoint: Optional[str] = None,
) -> A:
# Retrieve Auth Parameters
self._req_config_params()

response = self._req_base(
method,
data=data,
Expand Down Expand Up @@ -157,32 +154,6 @@ def _req_model_list(

return [model.parse_obj(x) for x in response]

def _req_config_params(
self,
) -> None:
if self.onefuzz._backend.config.endpoint is None:
raise Exception("Endpoint Not Configured")

endpoint = self.onefuzz._backend.config.endpoint

response = self.onefuzz._backend.session.request(
"GET", endpoint + "/api/config"
)

logging.debug(response.json())
endpoint_params = responses.Config.parse_obj(response.json())

logging.debug(self.onefuzz._backend.config.authority)
# Will override values in storage w/ provided values for SP use
if self.onefuzz._backend.config.client_id == "":
self.onefuzz._backend.config.client_id = endpoint_params.client_id
if self.onefuzz._backend.config.authority == "":
self.onefuzz._backend.config.authority = endpoint_params.authority
if self.onefuzz._backend.config.tenant_domain == "":
self.onefuzz._backend.config.tenant_domain = endpoint_params.tenant_domain

self.onefuzz._backend.save_config()

def _disambiguate(
self,
name: str,
Expand Down
30 changes: 30 additions & 0 deletions src/cli/onefuzz/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import msal
import requests
from azure.storage.blob import ContainerClient
from onefuzztypes import responses
from pydantic import BaseModel, Field
from requests import Response
from tenacity import RetryCallState, retry
Expand Down Expand Up @@ -308,6 +309,28 @@ def do_login(self, scopes: List[str]) -> Any:
else:
raise Exception("Failed to acquire token")

def config_params(
self,
) -> None:
if self.config.endpoint is None:
raise Exception("Endpoint Not Configured")

endpoint = self.config.endpoint

response = self.session.request("GET", endpoint + "/api/config")

logging.debug(response.json())
endpoint_params = responses.Config.parse_obj(response.json())

logging.debug(self.config.authority)
# Will override values in storage w/ provided values for SP use
if self.config.client_id == "":
self.config.client_id = endpoint_params.client_id
if self.config.authority == "":
self.config.authority = endpoint_params.authority
if self.config.tenant_domain == "":
self.config.tenant_domain = endpoint_params.tenant_domain

def request(
self,
method: str,
Expand All @@ -322,6 +345,13 @@ def request(
raise Exception("endpoint not configured")

url = endpoint + "/api/" + path

if (
self.config.client_id == ""
and self.config.authority == ""
and self.config.tenant_domain == ""
):
self.config_params()
headers = self.headers()
json_data = serialize(json_data)

Expand Down