forked from mehdiBezahaf/intent-deploy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.py
65 lines (41 loc) · 1.54 KB
/
types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from __future__ import annotations
from typing import Generic, Literal, TypeVar
from pydantic.config import BaseConfig
from pydantic.generics import GenericModel
from pydantic import UUID4, BaseModel
from intent_deployer.state_track import ActiveIntent
class APIResponseStatus(BaseModel):
code: int
details: str
class APIResponse(BaseModel):
status: APIResponseStatus
class CreatedIntentResponse(APIResponse):
intent_id: UUID4
class ListIntentResponse(APIResponse):
intents: list[ActiveIntent]
class GetIntentResponse(APIResponse):
intent: ActiveIntent
class NileIntentRequest(BaseModel):
type: Literal["nile"]
intent: str
# @simmsb: I don't think this is acutually used any more
class Policy(BaseModel):
"""A policy with the onos-reroute-api"""
api_key: str
class Config(BaseConfig):
allow_mutation = False
# class Config:
# # needed, otherwise when we cast subclasses of 'Policy' to 'Policy' when
# # constructing a 'DeployResponse' we lose the extra fields
# extra = "allow"
# PolicyT is covariant, we can view a F[subtype(Policy)] as an F[Policy]
PolicyT = TypeVar("PolicyT", bound=Policy, covariant=True)
class DeployResponseOutput(GenericModel, Generic[PolicyT]):
type: str
policy: PolicyT
class DeployResponse(APIResponse, GenericModel, Generic[PolicyT]):
input: NileIntentRequest
output: DeployResponseOutput[PolicyT]
class IntentDeployException(Exception):
"""Exceptions raised by our application that are safe to expose to users."""
pass