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

Commit f93c755

Browse files
authored
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.
1 parent fed7e69 commit f93c755

File tree

2 files changed

+29
-29
lines changed

2 files changed

+29
-29
lines changed

src/cli/onefuzz/api.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,6 @@ def _req_model(
123123
as_params: bool = False,
124124
alternate_endpoint: Optional[str] = None,
125125
) -> A:
126-
# Retrieve Auth Parameters
127-
self._req_config_params()
128-
129126
response = self._req_base(
130127
method,
131128
data=data,
@@ -157,32 +154,6 @@ def _req_model_list(
157154

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

160-
def _req_config_params(
161-
self,
162-
) -> None:
163-
if self.onefuzz._backend.config.endpoint is None:
164-
raise Exception("Endpoint Not Configured")
165-
166-
endpoint = self.onefuzz._backend.config.endpoint
167-
168-
response = self.onefuzz._backend.session.request(
169-
"GET", endpoint + "/api/config"
170-
)
171-
172-
logging.debug(response.json())
173-
endpoint_params = responses.Config.parse_obj(response.json())
174-
175-
logging.debug(self.onefuzz._backend.config.authority)
176-
# Will override values in storage w/ provided values for SP use
177-
if self.onefuzz._backend.config.client_id == "":
178-
self.onefuzz._backend.config.client_id = endpoint_params.client_id
179-
if self.onefuzz._backend.config.authority == "":
180-
self.onefuzz._backend.config.authority = endpoint_params.authority
181-
if self.onefuzz._backend.config.tenant_domain == "":
182-
self.onefuzz._backend.config.tenant_domain = endpoint_params.tenant_domain
183-
184-
self.onefuzz._backend.save_config()
185-
186157
def _disambiguate(
187158
self,
188159
name: str,

src/cli/onefuzz/backend.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import msal
3232
import requests
3333
from azure.storage.blob import ContainerClient
34+
from onefuzztypes import responses
3435
from pydantic import BaseModel, Field
3536
from requests import Response
3637
from tenacity import RetryCallState, retry
@@ -308,6 +309,29 @@ def do_login(self, scopes: List[str]) -> Any:
308309
else:
309310
raise Exception("Failed to acquire token")
310311

312+
def config_params(
313+
self,
314+
) -> None:
315+
if self.config.endpoint is None:
316+
raise Exception("Endpoint Not Configured")
317+
318+
endpoint = self.config.endpoint
319+
320+
response = self.session.request("GET", endpoint + "/api/config")
321+
322+
logging.debug(response.json())
323+
endpoint_params = responses.Config.parse_obj(response.json())
324+
325+
# Will override values in storage w/ provided values for SP use
326+
if self.config.client_id == "":
327+
self.config.client_id = endpoint_params.client_id
328+
if self.config.authority == "":
329+
self.config.authority = endpoint_params.authority
330+
if self.config.tenant_domain == "":
331+
self.config.tenant_domain = endpoint_params.tenant_domain
332+
333+
self.save_config()
334+
311335
def request(
312336
self,
313337
method: str,
@@ -322,6 +346,11 @@ def request(
322346
raise Exception("endpoint not configured")
323347

324348
url = endpoint + "/api/" + path
349+
350+
if self.config.client_id == "" or (
351+
self.config.authority == "" and self.config.tenant_domain == ""
352+
):
353+
self.config_params()
325354
headers = self.headers()
326355
json_data = serialize(json_data)
327356

0 commit comments

Comments
 (0)