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

Commit 1ac3fd4

Browse files
authored
Config Refactor Part 2 - Change Opt Param Names & Set File Expiry (#2835)
* Remove Old Optional Parameters and Hardcoded Values. * Set file to expire. * Adding expiry. * test sleep * Tested expiry. * Set expirty to 24hrs. * Syntax error. * Formatting. * Changing optional. * Adding new params. * Removing arguments. * Removing arguments. * Changing param names. * Update params.
1 parent ddbc715 commit 1ac3fd4

File tree

8 files changed

+31
-36
lines changed

8 files changed

+31
-36
lines changed

src/ApiService/ApiService/Functions/Config.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public async Async.Task<HttpResponseData> Get(HttpRequestData req) {
2424
var endpointParams = new ConfigResponse(
2525
Authority: _context.ServiceConfiguration.Authority,
2626
ClientId: _context.ServiceConfiguration.CliAppId,
27-
TenantDomain: _context.ServiceConfiguration.TenantDomain);
27+
TenantDomain: _context.ServiceConfiguration.TenantDomain,
28+
MultiTenantDomain: _context.ServiceConfiguration.MultiTenantDomain);
2829

2930
var response = req.CreateResponse(HttpStatusCode.OK);
3031
await response.WriteAsJsonAsync(endpointParams);

src/ApiService/ApiService/OneFuzzTypes/Responses.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ public static ScalesetResponse ForScaleset(Scaleset s, bool includeAuth)
162162
public record ConfigResponse(
163163
string? Authority,
164164
string? ClientId,
165-
string? TenantDomain
165+
string? TenantDomain,
166+
string? MultiTenantDomain
166167
) : BaseResponse();
167168

168169
public class BaseResponseConverter : JsonConverter<BaseResponse> {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def main(req: func.HttpRequest) -> func.HttpResponse:
1212
o = Onefuzz()
1313
o.config(
1414
endpoint=os.environ.get("ONEFUZZ_ENDPOINT"),
15-
authority=os.environ.get("ONEFUZZ_AUTHORITY"),
16-
client_id=os.environ.get("ONEFUZZ_CLIENT_ID"),
15+
override_authority=os.environ.get("ONEFUZZ_AUTHORITY"),
16+
override_client_id=os.environ.get("ONEFUZZ_CLIENT_ID"),
1717
)
1818
info = o.info.get()
1919
return func.HttpResponse(info.json())

src/cli/onefuzz/api.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,10 +1896,10 @@ def login(self) -> str:
18961896
def config(
18971897
self,
18981898
endpoint: Optional[str] = None,
1899-
authority: Optional[str] = None,
1900-
client_id: Optional[str] = None,
1899+
override_authority: Optional[str] = None,
1900+
override_client_id: Optional[str] = None,
1901+
override_tenant_domain: Optional[str] = None,
19011902
enable_feature: Optional[PreviewFeature] = None,
1902-
tenant_domain: Optional[str] = None,
19031903
reset: Optional[bool] = None,
19041904
) -> BackendConfig:
19051905
"""Configure onefuzz CLI"""
@@ -1924,14 +1924,14 @@ def config(
19241924
"Missing HTTP Authentication"
19251925
)
19261926
self._backend.config.endpoint = endpoint
1927-
if authority is not None:
1928-
self._backend.config.authority = authority
1929-
if client_id is not None:
1930-
self._backend.config.client_id = client_id
1927+
if override_authority is not None:
1928+
self._backend.config.authority = override_authority
1929+
if override_client_id is not None:
1930+
self._backend.config.client_id = override_client_id
19311931
if enable_feature:
19321932
self._backend.enable_feature(enable_feature.name)
1933-
if tenant_domain is not None:
1934-
self._backend.config.tenant_domain = tenant_domain
1933+
if override_tenant_domain is not None:
1934+
self._backend.config.tenant_domain = override_tenant_domain
19351935
self._backend.app = None
19361936
self._backend.save_config()
19371937

src/cli/onefuzz/backend.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import tempfile
1313
import time
1414
from dataclasses import asdict, is_dataclass
15+
from datetime import datetime, timedelta
1516
from enum import Enum
1617
from typing import (
1718
Any,
@@ -97,6 +98,7 @@ class BackendConfig(BaseModel):
9798
endpoint: Optional[str]
9899
features: Set[str] = Field(default_factory=set)
99100
tenant_domain: str
101+
expires_on: datetime = datetime.utcnow() + timedelta(hours=24)
100102

101103
def get_multi_tenant_domain(self) -> Optional[str]:
102104
if "https://login.microsoftonline.com/common" in self.authority:
@@ -326,7 +328,6 @@ def config_params(
326328

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

329-
logging.debug(response.json())
330331
endpoint_params = responses.Config.parse_obj(response.json())
331332

332333
# Will override values in storage w/ provided values for SP use
@@ -352,6 +353,13 @@ def request(
352353
if not endpoint:
353354
raise Exception("endpoint not configured")
354355

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+
355363
url = endpoint + "/api/" + path
356364

357365
if self.config.client_id == "" or (

src/deployment/config.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
{
2-
"tenant_id": "72f988bf-86f1-41af-91ab-2d7cd011db47",
3-
"tenant_domain": "azurewebsites.net",
2+
"tenant_id": "",
3+
"tenant_domain": "",
44
"multi_tenant_domain": "",
5-
"cli_client_id": "72f1562a-8c0c-41ea-beb9-fa2b71c80134",
5+
"cli_client_id": "",
66
"proxy_nsg_config": {
77
"allowed_ips": [
88
"*"

src/deployment/deploy.py

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,10 @@ def __init__(
147147
create_registration: bool,
148148
migrations: List[str],
149149
export_appinsights: bool,
150-
multi_tenant_domain: str,
151150
upgrade: bool,
152151
subscription_id: Optional[str],
153152
admins: List[UUID],
154153
allowed_aad_tenants: List[UUID],
155-
cli_app_id: str,
156154
auto_create_cli_app: bool,
157155
host_dotnet_on_windows: bool,
158156
enable_profiler: bool,
@@ -169,7 +167,6 @@ def __init__(
169167
self.instance_specific = instance_specific
170168
self.third_party = third_party
171169
self.create_registration = create_registration
172-
self.multi_tenant_domain = multi_tenant_domain
173170
self.custom_domain = custom_domain
174171
self.upgrade = upgrade
175172
self.results: Dict = {
@@ -183,16 +180,17 @@ def __init__(
183180

184181
self.arm_template = bicep_to_arm(bicep_template)
185182

186-
self.cli_app_id = cli_app_id
187183
self.auto_create_cli_app = auto_create_cli_app
188184
self.host_dotnet_on_windows = host_dotnet_on_windows
189185
self.enable_profiler = enable_profiler
190186

191187
self.rules: List[NsgRule] = []
192188

189+
self.cli_app_id = ""
190+
self.authority = ""
193191
self.tenant_id = ""
194192
self.tenant_domain = ""
195-
self.authority = ""
193+
self.multi_tenant_domain = ""
196194

197195
self.cli_config: Dict[str, Union[str, UUID]] = {
198196
"client_id": "",
@@ -1268,12 +1266,6 @@ def main() -> None:
12681266
action="store_true",
12691267
help="enable appinsight log export",
12701268
)
1271-
parser.add_argument(
1272-
"--multi_tenant_domain",
1273-
type=str,
1274-
default="",
1275-
help="enable multi-tenant authentication with this tenant domain",
1276-
)
12771269
parser.add_argument(
12781270
"--subscription_id",
12791271
type=str,
@@ -1295,12 +1287,6 @@ def main() -> None:
12951287
nargs="*",
12961288
help="Set additional AAD tenants beyond the tenant the app is deployed in",
12971289
)
1298-
parser.add_argument(
1299-
"--cli_app_id",
1300-
type=str,
1301-
default="",
1302-
help="CLI App Registration to be used during deployment.",
1303-
)
13041290
parser.add_argument(
13051291
"--auto_create_cli_app",
13061292
action="store_true",
@@ -1348,12 +1334,10 @@ def main() -> None:
13481334
create_registration=args.create_pool_registration,
13491335
migrations=args.apply_migrations,
13501336
export_appinsights=args.export_appinsights,
1351-
multi_tenant_domain=args.multi_tenant_domain,
13521337
upgrade=args.upgrade,
13531338
subscription_id=args.subscription_id,
13541339
admins=args.set_admins,
13551340
allowed_aad_tenants=args.allowed_aad_tenants or [],
1356-
cli_app_id=args.cli_app_id,
13571341
auto_create_cli_app=args.auto_create_cli_app,
13581342
host_dotnet_on_windows=args.host_dotnet_on_windows,
13591343
enable_profiler=args.enable_profiler,

src/pytypes/onefuzztypes/responses.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class Config(BaseResponse):
5656
authority: str
5757
client_id: str
5858
tenant_domain: str
59+
multi_tenant_domain: Optional[str]
5960

6061

6162
class ContainerInfoBase(BaseResponse):

0 commit comments

Comments
 (0)