Resolving bug in config refactor. (#2811)

* Resolving bug in config refactor.

* fixing isort.

* Reformatting api.

* debugging.

* fixing backend.

* Adding condition to param retrieval.

* Adding back save.

* Fixing condition check.

* Formatting.
This commit is contained in:
Noah McGregor Harper
2023-02-08 02:13:29 +00:00
committed by GitHub
parent fed7e6939d
commit f93c75556d
2 changed files with 29 additions and 29 deletions

View File

@ -123,9 +123,6 @@ class Endpoint:
as_params: bool = False,
alternate_endpoint: Optional[str] = None,
) -> A:
# Retrieve Auth Parameters
self._req_config_params()
response = self._req_base(
method,
data=data,
@ -157,32 +154,6 @@ class Endpoint:
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,

View File

@ -31,6 +31,7 @@ from uuid import UUID
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
@ -308,6 +309,29 @@ class Backend:
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())
# 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
self.save_config()
def request(
self,
method: str,
@ -322,6 +346,11 @@ class Backend:
raise Exception("endpoint not configured")
url = endpoint + "/api/" + path
if self.config.client_id == "" or (
self.config.authority == "" and self.config.tenant_domain == ""
):
self.config_params()
headers = self.headers()
json_data = serialize(json_data)