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

Commit a9b5b7f

Browse files
Merge branch 'main' into Release-8.0.0
2 parents f4e3a39 + ace0ccc commit a9b5b7f

File tree

6 files changed

+60
-76
lines changed

6 files changed

+60
-76
lines changed

src/ApiService/IntegrationTests/IntegrationTests.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
<PackageReference Include="FluentAssertions" Version="6.10.0" />
99
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
1010
<PackageReference Include="Moq" Version="4.17.2" />
11-
<PackageReference Include="xunit" Version="2.4.1" />
12-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
11+
<PackageReference Include="xunit" Version="2.4.2" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1313
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1414
<PrivateAssets>all</PrivateAssets>
1515
</PackageReference>

src/ApiService/IntegrationTests/packages.lock.json

+22-22
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,20 @@
3939
},
4040
"xunit": {
4141
"type": "Direct",
42-
"requested": "[2.4.1, )",
43-
"resolved": "2.4.1",
44-
"contentHash": "XNR3Yz9QTtec16O0aKcO6+baVNpXmOnPUxDkCY97J+8krUYxPvXT1szYYEUdKk4sB8GOI2YbAjRIOm8ZnXRfzQ==",
42+
"requested": "[2.4.2, )",
43+
"resolved": "2.4.2",
44+
"contentHash": "6Mj73Ont3zj2CJuoykVJfE0ZmRwn7C+pTuRP8c4bnaaTFjwNG6tGe0prJ1yIbMe9AHrpDys63ctWacSsFJWK/w==",
4545
"dependencies": {
46-
"xunit.analyzers": "0.10.0",
47-
"xunit.assert": "[2.4.1]",
48-
"xunit.core": "[2.4.1]"
46+
"xunit.analyzers": "1.0.0",
47+
"xunit.assert": "2.4.2",
48+
"xunit.core": "[2.4.2]"
4949
}
5050
},
5151
"xunit.runner.visualstudio": {
5252
"type": "Direct",
53-
"requested": "[2.4.3, )",
54-
"resolved": "2.4.3",
55-
"contentHash": "kZZSmOmKA8OBlAJaquPXnJJLM9RwQ27H7BMVqfMLUcTi9xHinWGJiWksa3D4NEtz0wZ/nxd2mogObvBgJKCRhQ=="
53+
"requested": "[2.4.5, )",
54+
"resolved": "2.4.5",
55+
"contentHash": "OwHamvBdUKgqsXfBzWiCW/O98BTx81UKzx2bieIOQI7CZFE5NEQZGi8PBQGIKawDW96xeRffiNf20SjfC0x9hw=="
5656
},
5757
"Azure.Core": {
5858
"type": "Transitive",
@@ -2441,42 +2441,42 @@
24412441
},
24422442
"xunit.analyzers": {
24432443
"type": "Transitive",
2444-
"resolved": "0.10.0",
2445-
"contentHash": "4/IDFCJfIeg6bix9apmUtIMwvOsiwqdEexeO/R2D4GReIGPLIRODTpId/l4LRSrAJk9lEO3Zx1H0Zx6uohJDNg=="
2444+
"resolved": "1.0.0",
2445+
"contentHash": "BeO8hEgs/c8Ls2647fPfieMngncvf0D0xYNDfIO59MolxtCtVjFRd6SRc+7tj8VMqkVOuJcnc9eh4ngI2cAmLQ=="
24462446
},
24472447
"xunit.assert": {
24482448
"type": "Transitive",
2449-
"resolved": "2.4.1",
2450-
"contentHash": "O/Oe0BS5RmSsM+LQOb041TzuPo5MdH2Rov+qXGS37X+KFG1Hxz7kopYklM5+1Y+tRGeXrOx5+Xne1RuqLFQoyQ==",
2449+
"resolved": "2.4.2",
2450+
"contentHash": "pxJISOFjn2XTTi1mcDCkRZrTFb9OtRRCtx2kZFNF51GdReLr1ls2rnyxvAS4JO247K3aNtflvh5Q0346K5BROA==",
24512451
"dependencies": {
24522452
"NETStandard.Library": "1.6.1"
24532453
}
24542454
},
24552455
"xunit.core": {
24562456
"type": "Transitive",
2457-
"resolved": "2.4.1",
2458-
"contentHash": "Zsj5OMU6JasNGERXZy8s72+pcheG6Q15atS5XpZXqAtULuyQiQ6XNnUsp1gyfC6WgqScqMvySiEHmHcOG6Eg0Q==",
2457+
"resolved": "2.4.2",
2458+
"contentHash": "KB4yGCxNqIVyekhJLXtKSEq6BaXVp/JO3mbGVE1hxypZTLEe7h+sTbAhpA+yZW2dPtXTuiW+C1B2oxxHEkrmOw==",
24592459
"dependencies": {
2460-
"xunit.extensibility.core": "[2.4.1]",
2461-
"xunit.extensibility.execution": "[2.4.1]"
2460+
"xunit.extensibility.core": "[2.4.2]",
2461+
"xunit.extensibility.execution": "[2.4.2]"
24622462
}
24632463
},
24642464
"xunit.extensibility.core": {
24652465
"type": "Transitive",
2466-
"resolved": "2.4.1",
2467-
"contentHash": "yKZKm/8QNZnBnGZFD9SewkllHBiK0DThybQD/G4PiAmQjKtEZyHi6ET70QPU9KtSMJGRYS6Syk7EyR2EVDU4Kg==",
2466+
"resolved": "2.4.2",
2467+
"contentHash": "W1BoXTIN1C6kpVSMw25huSet25ky6IAQUNovu3zGOGN/jWnbgSoTyCrlIhmXSg0tH5nEf8q7h3OjNHOjyu5PfA==",
24682468
"dependencies": {
24692469
"NETStandard.Library": "1.6.1",
24702470
"xunit.abstractions": "2.0.3"
24712471
}
24722472
},
24732473
"xunit.extensibility.execution": {
24742474
"type": "Transitive",
2475-
"resolved": "2.4.1",
2476-
"contentHash": "7e/1jqBpcb7frLkB6XDrHCGXAbKN4Rtdb88epYxCSRQuZDRW8UtTfdTEVpdTl8s4T56e07hOBVd4G0OdCxIY2A==",
2475+
"resolved": "2.4.2",
2476+
"contentHash": "CZmgcKkwpyo8FlupZdWpJCryrAOWLh1FBPG6gmVZuPQkGQsim/oL4PcP4nfrC2hHgXUFtluvaJ0Sp9PQKUMNpg==",
24772477
"dependencies": {
24782478
"NETStandard.Library": "1.6.1",
2479-
"xunit.extensibility.core": "[2.4.1]"
2479+
"xunit.extensibility.core": "[2.4.2]"
24802480
}
24812481
},
24822482
"apiservice": {

src/agent/Cargo.lock

+5-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cli/examples/azure-functions-example/info/__init__.py

-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ def main(req: func.HttpRequest) -> func.HttpResponse:
1212
o = Onefuzz()
1313
o.config(
1414
endpoint=os.environ.get("ONEFUZZ_ENDPOINT"),
15-
override_authority=os.environ.get("ONEFUZZ_AUTHORITY"),
16-
client_id=os.environ.get("ONEFUZZ_CLIENT_ID"),
1715
)
1816
info = o.info.get()
1917
return func.HttpResponse(info.json())

src/cli/onefuzz/api.py

+5-19
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@
4040

4141
UUID_EXPANSION = TypeVar("UUID_EXPANSION", UUID, str)
4242

43-
DEFAULT = BackendConfig(
44-
authority="",
45-
client_id="",
46-
tenant_domain="",
47-
)
43+
DEFAULT = BackendConfig(endpoint="")
4844

4945
# This was generated randomly and should be preserved moving forwards
5046
ONEFUZZ_GUID_NAMESPACE = uuid.UUID("27f25e3f-6544-4b69-b309-9b096c5a9cbc")
@@ -1310,7 +1306,7 @@ def get_config(self, pool_name: primitives.PoolName) -> models.AgentConfig:
13101306
raise Exception("Missing AgentConfig in response")
13111307

13121308
config = pool.config
1313-
if not pool.managed:
1309+
if not pool.managed and self.onefuzz._backend.config.authority:
13141310
config.client_credentials = models.ClientCredentials( # nosec
13151311
client_id=uuid.UUID(int=0),
13161312
client_secret="<client_secret>",
@@ -1894,19 +1890,14 @@ def login(self) -> str:
18941890
def config(
18951891
self,
18961892
endpoint: Optional[str] = None,
1897-
override_authority: Optional[str] = None,
1898-
client_id: Optional[str] = None,
1899-
override_tenant_domain: Optional[str] = None,
19001893
enable_feature: Optional[PreviewFeature] = None,
19011894
reset: Optional[bool] = None,
19021895
) -> BackendConfig:
19031896
"""Configure onefuzz CLI"""
19041897
self.logger.debug("set config")
19051898

19061899
if reset:
1907-
self._backend.config = BackendConfig(
1908-
authority="", client_id="", tenant_domain=""
1909-
)
1900+
self._backend.config = BackendConfig(endpoint="")
19101901

19111902
if endpoint is not None:
19121903
# The normal path for calling the API always uses the oauth2 workflow,
@@ -1922,17 +1913,12 @@ def config(
19221913
"Missing HTTP Authentication"
19231914
)
19241915
self._backend.config.endpoint = endpoint
1925-
if client_id is not None:
1926-
self._backend.config.client_id = client_id
1927-
if override_authority is not None:
1928-
self._backend.config.authority = override_authority
1916+
19291917
if enable_feature:
19301918
self._backend.enable_feature(enable_feature.name)
1931-
if override_tenant_domain is not None:
1932-
self._backend.config.tenant_domain = override_tenant_domain
1919+
19331920
self._backend.app = None
19341921
self._backend.save_config()
1935-
19361922
data = self._backend.config.copy(deep=True)
19371923

19381924
if not data.endpoint:

src/cli/onefuzz/backend.py

+26-26
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import tempfile
1313
import time
1414
from dataclasses import asdict, is_dataclass
15-
from datetime import datetime, timedelta
1615
from enum import Enum
1716
from typing import (
1817
Any,
@@ -33,7 +32,7 @@
3332
import requests
3433
from azure.storage.blob import ContainerClient
3534
from onefuzztypes import responses
36-
from pydantic import BaseModel, Field
35+
from pydantic import BaseModel
3736
from requests import Response
3837
from tenacity import RetryCallState, retry
3938
from tenacity.retry import retry_if_exception_type
@@ -93,20 +92,26 @@ def check_application_error(response: requests.Response) -> None:
9392

9493

9594
class BackendConfig(BaseModel):
96-
authority: str
97-
client_id: str
98-
endpoint: Optional[str]
99-
features: Set[str] = Field(default_factory=set)
100-
tenant_domain: str
101-
expires_on: datetime = datetime.utcnow() + timedelta(hours=24)
95+
authority: Optional[str]
96+
client_id: Optional[str]
97+
endpoint: str
98+
features: Optional[Set[str]]
99+
tenant_domain: Optional[str]
102100

103101
def get_multi_tenant_domain(self) -> Optional[str]:
104-
if "https://login.microsoftonline.com/common" in self.authority:
102+
if (
103+
self.authority
104+
and "https://login.microsoftonline.com/common" in self.authority
105+
):
105106
return self.tenant_domain
106107
else:
107108
return None
108109

109110

111+
class CacheConfig(BaseModel):
112+
endpoint: Optional[str]
113+
114+
110115
class Backend:
111116
def __init__(
112117
self,
@@ -129,10 +134,14 @@ def __init__(
129134
atexit.register(self.save_cache)
130135

131136
def enable_feature(self, name: str) -> None:
137+
if not self.config.features:
138+
self.config.features = Set[str]()
132139
self.config.features.add(name)
133140

134141
def is_feature_enabled(self, name: str) -> bool:
135-
return name in self.config.features
142+
if self.config.features:
143+
return name in self.config.features
144+
return False
136145

137146
def load_config(self) -> None:
138147
if os.path.exists(self.config_path):
@@ -143,7 +152,8 @@ def load_config(self) -> None:
143152
def save_config(self) -> None:
144153
os.makedirs(os.path.dirname(self.config_path), exist_ok=True)
145154
with open(self.config_path, "w") as handle:
146-
handle.write(self.config.json(indent=4, exclude_none=True))
155+
endpoint_cache = {"endpoint": f"{self.config.endpoint}"}
156+
handle.write(json.dumps(endpoint_cache, indent=4, sort_keys=True))
147157

148158
def init_cache(self) -> None:
149159
# Ensure the token_path directory exists
@@ -331,15 +341,13 @@ def config_params(
331341
endpoint_params = responses.Config.parse_obj(response.json())
332342

333343
# Will override values in storage w/ provided values for SP use
334-
if self.config.client_id == "":
344+
if not self.config.client_id:
335345
self.config.client_id = endpoint_params.client_id
336-
if self.config.authority == "":
346+
if not self.config.authority:
337347
self.config.authority = endpoint_params.authority
338-
if self.config.tenant_domain == "":
348+
if not self.config.tenant_domain:
339349
self.config.tenant_domain = endpoint_params.tenant_domain
340350

341-
self.save_config()
342-
343351
def request(
344352
self,
345353
method: str,
@@ -353,17 +361,9 @@ def request(
353361
if not endpoint:
354362
raise Exception("endpoint not configured")
355363

356-
# If file expires, remove and force user to reset
357-
if datetime.utcnow() > self.config.expires_on:
358-
os.remove(self.config_path)
359-
self.config = BackendConfig(
360-
endpoint=endpoint, authority="", client_id="", tenant_domain=""
361-
)
362-
363364
url = endpoint + "/api/" + path
364-
365-
if self.config.client_id == "" or (
366-
self.config.authority == "" and self.config.tenant_domain == ""
365+
if not self.config.client_id or (
366+
not self.config.authority and not self.config.tenant_domain
367367
):
368368
self.config_params()
369369
headers = self.headers()

0 commit comments

Comments
 (0)