mirror of
https://github.com/microsoft/onefuzz.git
synced 2025-06-18 20:58:06 +00:00
basic list proxy functionality (#905)
This commit is contained in:
@ -9,7 +9,7 @@ import azure.functions as func
|
||||
from onefuzztypes.enums import ErrorCode, VmState
|
||||
from onefuzztypes.models import Error
|
||||
from onefuzztypes.requests import ProxyCreate, ProxyDelete, ProxyGet, ProxyReset
|
||||
from onefuzztypes.responses import BoolResult, ProxyGetResult
|
||||
from onefuzztypes.responses import BoolResult, ProxyGetResult, ProxyInfo, ProxyList
|
||||
|
||||
from ..onefuzzlib.endpoint_authorization import call_if_user
|
||||
from ..onefuzzlib.events import get_events
|
||||
@ -36,6 +36,11 @@ def get(req: func.HttpRequest) -> func.HttpResponse:
|
||||
if isinstance(request, Error):
|
||||
return not_ok(request, context="ProxyGet")
|
||||
|
||||
if (
|
||||
request.scaleset_id is not None
|
||||
and request.machine_id is not None
|
||||
and request.dst_port is not None
|
||||
):
|
||||
scaleset = Scaleset.get_by_id(request.scaleset_id)
|
||||
if isinstance(scaleset, Error):
|
||||
return not_ok(scaleset, context="ProxyGet")
|
||||
@ -56,6 +61,12 @@ def get(req: func.HttpRequest) -> func.HttpResponse:
|
||||
)
|
||||
|
||||
return ok(get_result(forwards[0], proxy))
|
||||
else:
|
||||
proxies = [
|
||||
ProxyInfo(region=x.region, proxy_id=x.proxy_id, state=x.state)
|
||||
for x in Proxy.search()
|
||||
]
|
||||
return ok(ProxyList(proxies=proxies))
|
||||
|
||||
|
||||
def post(req: func.HttpRequest) -> func.HttpResponse:
|
||||
|
@ -1468,6 +1468,9 @@ class ScalesetProxy(Endpoint):
|
||||
),
|
||||
)
|
||||
|
||||
def list(self) -> responses.ProxyList:
|
||||
return self._req_model("GET", responses.ProxyList, data=requests.ProxyGet())
|
||||
|
||||
|
||||
class Command:
|
||||
def __init__(self, onefuzz: "Onefuzz", logger: logging.Logger):
|
||||
|
@ -3,10 +3,10 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
from typing import Dict, List, Optional
|
||||
from typing import Any, Dict, List, Optional
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import AnyHttpUrl, BaseModel, Field, validator
|
||||
from pydantic import AnyHttpUrl, BaseModel, Field, root_validator, validator
|
||||
|
||||
from .consts import ONE_HOUR, SEVEN_DAYS
|
||||
from .enums import (
|
||||
@ -107,9 +107,20 @@ class PoolStop(BaseRequest):
|
||||
|
||||
|
||||
class ProxyGet(BaseRequest):
|
||||
scaleset_id: UUID
|
||||
machine_id: UUID
|
||||
dst_port: int
|
||||
scaleset_id: Optional[UUID]
|
||||
machine_id: Optional[UUID]
|
||||
dst_port: Optional[int]
|
||||
|
||||
@root_validator()
|
||||
def check_proxy_get(cls, value: Any) -> Any:
|
||||
check_keys = ["scaleset_id", "machine_id", "dst_port"]
|
||||
included = [x in value for x in check_keys]
|
||||
if any(included) and not all(included):
|
||||
raise ValueError(
|
||||
"ProxyGet must provide all or none of the following: %s"
|
||||
% ", ".join(check_keys)
|
||||
)
|
||||
return value
|
||||
|
||||
|
||||
class ProxyCreate(BaseRequest):
|
||||
|
@ -3,11 +3,12 @@
|
||||
# Copyright (c) Microsoft Corporation.
|
||||
# Licensed under the MIT License.
|
||||
|
||||
from typing import Dict, Optional
|
||||
from typing import Dict, List, Optional
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .enums import VmState
|
||||
from .models import Forward, NodeCommandEnvelope
|
||||
from .primitives import Region
|
||||
|
||||
@ -25,6 +26,16 @@ class ProxyGetResult(BaseResponse):
|
||||
forward: Forward
|
||||
|
||||
|
||||
class ProxyInfo(BaseModel):
|
||||
region: Region
|
||||
proxy_id: UUID
|
||||
state: VmState
|
||||
|
||||
|
||||
class ProxyList(BaseResponse):
|
||||
proxies: List[ProxyInfo]
|
||||
|
||||
|
||||
class Version(BaseResponse):
|
||||
git: str
|
||||
build: str
|
||||
|
Reference in New Issue
Block a user