Skip to content
This repository has been archived by the owner on Nov 1, 2023. It is now read-only.

Commit

Permalink
Resolving bug in config refactor. (#2811)
Browse files Browse the repository at this point in the history
* Resolving bug in config refactor.

* fixing isort.

* Reformatting api.

* debugging.

* fixing backend.

* Adding condition to param retrieval.

* Adding back save.

* Fixing condition check.

* Formatting.
  • Loading branch information
nharper285 authored Feb 8, 2023
1 parent fed7e69 commit f93c755
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
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
29 changes: 29 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,29 @@ 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())

# 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,
Expand All @@ -322,6 +346,11 @@ def request(
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)

Expand Down

0 comments on commit f93c755

Please sign in to comment.