mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-17 04:18:07 +00:00
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.
This commit is contained in:
committed by
GitHub
parent
ddbc715b3f
commit
1ac3fd4bed
@ -12,8 +12,8 @@ def main(req: func.HttpRequest) -> func.HttpResponse:
|
||||
o = Onefuzz()
|
||||
o.config(
|
||||
endpoint=os.environ.get("ONEFUZZ_ENDPOINT"),
|
||||
authority=os.environ.get("ONEFUZZ_AUTHORITY"),
|
||||
client_id=os.environ.get("ONEFUZZ_CLIENT_ID"),
|
||||
override_authority=os.environ.get("ONEFUZZ_AUTHORITY"),
|
||||
override_client_id=os.environ.get("ONEFUZZ_CLIENT_ID"),
|
||||
)
|
||||
info = o.info.get()
|
||||
return func.HttpResponse(info.json())
|
||||
|
@ -1896,10 +1896,10 @@ class Onefuzz:
|
||||
def config(
|
||||
self,
|
||||
endpoint: Optional[str] = None,
|
||||
authority: Optional[str] = None,
|
||||
client_id: Optional[str] = None,
|
||||
override_authority: Optional[str] = None,
|
||||
override_client_id: Optional[str] = None,
|
||||
override_tenant_domain: Optional[str] = None,
|
||||
enable_feature: Optional[PreviewFeature] = None,
|
||||
tenant_domain: Optional[str] = None,
|
||||
reset: Optional[bool] = None,
|
||||
) -> BackendConfig:
|
||||
"""Configure onefuzz CLI"""
|
||||
@ -1924,14 +1924,14 @@ class Onefuzz:
|
||||
"Missing HTTP Authentication"
|
||||
)
|
||||
self._backend.config.endpoint = endpoint
|
||||
if authority is not None:
|
||||
self._backend.config.authority = authority
|
||||
if client_id is not None:
|
||||
self._backend.config.client_id = client_id
|
||||
if override_authority is not None:
|
||||
self._backend.config.authority = override_authority
|
||||
if override_client_id is not None:
|
||||
self._backend.config.client_id = override_client_id
|
||||
if enable_feature:
|
||||
self._backend.enable_feature(enable_feature.name)
|
||||
if tenant_domain is not None:
|
||||
self._backend.config.tenant_domain = tenant_domain
|
||||
if override_tenant_domain is not None:
|
||||
self._backend.config.tenant_domain = override_tenant_domain
|
||||
self._backend.app = None
|
||||
self._backend.save_config()
|
||||
|
||||
|
@ -12,6 +12,7 @@ import sys
|
||||
import tempfile
|
||||
import time
|
||||
from dataclasses import asdict, is_dataclass
|
||||
from datetime import datetime, timedelta
|
||||
from enum import Enum
|
||||
from typing import (
|
||||
Any,
|
||||
@ -97,6 +98,7 @@ class BackendConfig(BaseModel):
|
||||
endpoint: Optional[str]
|
||||
features: Set[str] = Field(default_factory=set)
|
||||
tenant_domain: str
|
||||
expires_on: datetime = datetime.utcnow() + timedelta(hours=24)
|
||||
|
||||
def get_multi_tenant_domain(self) -> Optional[str]:
|
||||
if "https://login.microsoftonline.com/common" in self.authority:
|
||||
@ -326,7 +328,6 @@ class Backend:
|
||||
|
||||
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
|
||||
@ -352,6 +353,13 @@ class Backend:
|
||||
if not endpoint:
|
||||
raise Exception("endpoint not configured")
|
||||
|
||||
# If file expires, remove and force user to reset
|
||||
if datetime.utcnow() > self.config.expires_on:
|
||||
os.remove(self.config_path)
|
||||
self.config = BackendConfig(
|
||||
endpoint=endpoint, authority="", client_id="", tenant_domain=""
|
||||
)
|
||||
|
||||
url = endpoint + "/api/" + path
|
||||
|
||||
if self.config.client_id == "" or (
|
||||
|
Reference in New Issue
Block a user