mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-19 21:13:46 +00:00
instance wide configuration (#1010)
TODO: * [x] add setting initial set of admins during deployment
This commit is contained in:
34
src/api-service/__app__/onefuzzlib/config.py
Normal file
34
src/api-service/__app__/onefuzzlib/config.py
Normal file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
from typing import Optional, Tuple
|
||||
|
||||
from onefuzztypes.events import EventInstanceConfigUpdated
|
||||
from onefuzztypes.models import InstanceConfig as BASE_CONFIG
|
||||
from pydantic import Field
|
||||
|
||||
from .azure.creds import get_instance_name
|
||||
from .events import send_event
|
||||
from .orm import ORMMixin
|
||||
|
||||
|
||||
class InstanceConfig(BASE_CONFIG, ORMMixin):
|
||||
instance_name: str = Field(default_factory=get_instance_name)
|
||||
|
||||
@classmethod
|
||||
def key_fields(cls) -> Tuple[str, Optional[str]]:
|
||||
return ("instance_name", None)
|
||||
|
||||
@classmethod
|
||||
def fetch(cls) -> "InstanceConfig":
|
||||
entry = cls.get(get_instance_name())
|
||||
if entry is None:
|
||||
entry = cls()
|
||||
entry.save()
|
||||
return entry
|
||||
|
||||
def save(self, new: bool = False, require_etag: bool = False) -> None:
|
||||
super().save(new=new, require_etag=require_etag)
|
||||
send_event(EventInstanceConfigUpdated(config=self))
|
Reference in New Issue
Block a user