forked from Netflix/dispatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
127 lines (86 loc) · 2.76 KB
/
Copy pathmodels.py
File metadata and controls
127 lines (86 loc) · 2.76 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from datetime import datetime
from typing import List, Optional
from pydantic import BaseModel
from sqlalchemy import Boolean, Column, DateTime, Integer, String, event, ForeignKey
from sqlalchemy.ext.declarative import declared_attr
# SQLAlchemy models...
class TimeStampMixin(object):
""" Timestamping mixin"""
created_at = Column(DateTime, default=datetime.utcnow)
created_at._creation_order = 9998
updated_at = Column(DateTime, default=datetime.utcnow)
updated_at._creation_order = 9998
@staticmethod
def _updated_at(mapper, connection, target):
target.updated_at = datetime.utcnow()
@classmethod
def __declare_last__(cls):
event.listen(cls, "before_update", cls._updated_at)
class ContactMixin(TimeStampMixin):
""" Contact mixin"""
is_active = Column(Boolean, default=True)
is_external = Column(Boolean, default=False)
contact_type = Column(String)
email = Column(String, unique=True)
company = Column(String)
notes = Column(String)
owner = Column(String)
class ResourceMixin(TimeStampMixin):
"""Resource mixin."""
resource_type = Column(String)
resource_id = Column(String)
weblink = Column(String)
@declared_attr
def incident_id(cls): # noqa
return Column(Integer, ForeignKey("incident.id"))
# Pydantic models...
class DispatchBase(BaseModel):
class Config:
orm_mode = True
validate_assignment = True
class ContactBase(DispatchBase):
email: str
name: Optional[str] = None
is_active: Optional[bool] = True
is_external: Optional[bool] = False
company: Optional[str] = None
contact_type: Optional[str] = None
notes: Optional[str] = None
owner: Optional[str] = None
class PluginOptionModel(DispatchBase):
pass
# self referential models
class TermNested(DispatchBase):
id: Optional[int]
text: str
# disabling this for now as recursive models break swagger api gen
# definitions: Optional[List["DefinitionNested"]] = []
class DefinitionNested(DispatchBase):
id: Optional[int]
text: str
terms: Optional[List["TermNested"]] = []
class ServiceNested(DispatchBase):
pass
class IndividualNested(DispatchBase):
pass
class TeamNested(DispatchBase):
pass
class TermReadNested(DispatchBase):
id: int
text: str
class DefinitionReadNested(DispatchBase):
id: int
text: str
class ServiceReadNested(DispatchBase):
name: Optional[str] = None
external_id: Optional[str] = None
is_active: Optional[bool] = None
type: Optional[str] = None
class IndividualReadNested(ContactBase):
title: Optional[str] = None
weblink: Optional[str]
title: Optional[str]
class TeamReadNested(ContactBase):
pass
class PolicyReadNested(DispatchBase):
pass