-
Notifications
You must be signed in to change notification settings - Fork 26
/
services.py
162 lines (157 loc) · 4.18 KB
/
services.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
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
""" Services table
- List of 3rd party services in the framework
- Services have a key, version, and access rights defined by group ids
"""
import sqlalchemy as sa
from sqlalchemy import null
from sqlalchemy.dialects.postgresql import ARRAY, JSONB
from sqlalchemy.sql import expression, func
from .base import metadata
services_meta_data = sa.Table(
"services_meta_data",
metadata,
sa.Column(
"key",
sa.String,
nullable=False,
doc="Hierarchical identifier of the service e.g. simcore/services/dynamic/my-super-service",
),
sa.Column(
"version",
sa.String,
nullable=False,
doc="MAJOR.MINOR.PATCH semantic versioning (see https://semver.org)",
),
sa.Column(
"owner",
sa.BigInteger,
sa.ForeignKey(
"groups.gid",
name="fk_services_meta_data_gid_groups",
onupdate="CASCADE",
ondelete="RESTRICT",
),
nullable=True,
doc="Identifier of the group that owns this service",
),
sa.Column("name", sa.String, nullable=False, doc="Display label"),
sa.Column(
"description", sa.String, nullable=False, doc="Markdown-compatible description"
),
sa.Column(
"thumbnail",
sa.String,
nullable=True,
doc="Link to image to us as service thumbnail",
),
sa.Column(
"classifiers",
ARRAY(sa.String, dimensions=1),
nullable=False,
server_default="{}",
doc="List of standard labels that describe this service (see classifiers table)",
),
sa.Column(
"created",
sa.DateTime(),
nullable=False,
server_default=func.now(),
doc="Timestamp on creation",
),
sa.Column(
"modified",
sa.DateTime(),
nullable=False,
server_default=func.now(),
onupdate=func.now(),
doc="Timestamp with last update",
),
sa.Column(
"deprecated",
sa.DateTime(),
nullable=True,
server_default=null(),
doc="Timestamp with deprecation date",
),
sa.Column(
"quality",
JSONB,
nullable=False,
server_default=sa.text("'{}'::jsonb"),
doc="Free JSON with quality assesment based on TSR",
),
sa.PrimaryKeyConstraint("key", "version", name="services_meta_data_pk"),
)
services_access_rights = sa.Table(
"services_access_rights",
metadata,
sa.Column(
"key",
sa.String,
nullable=False,
doc="Service Key Identifier",
),
sa.Column("version", sa.String, nullable=False, doc="Service version"),
sa.Column(
"gid",
sa.BigInteger,
sa.ForeignKey(
"groups.gid",
name="fk_services_gid_groups",
onupdate="CASCADE",
ondelete="CASCADE",
),
doc="Group Identifier",
),
# Access Rights flags ---
sa.Column(
"execute_access",
sa.Boolean,
nullable=False,
server_default=expression.false(),
doc="If true, group can execute the service",
),
sa.Column(
"write_access",
sa.Boolean,
nullable=False,
server_default=expression.false(),
doc="If true, group can modify the service",
),
# -----
sa.Column(
"product_name",
sa.String,
sa.ForeignKey(
"products.name",
name="fk_services_name_products",
onupdate="CASCADE",
ondelete="CASCADE",
),
doc="Product Identifier",
),
sa.Column(
"created",
sa.DateTime(),
nullable=False,
server_default=func.now(),
doc="Timestamp of creation",
),
sa.Column(
"modified",
sa.DateTime(),
nullable=False,
server_default=func.now(),
onupdate=func.now(),
doc="Timestamp on last update",
),
sa.ForeignKeyConstraint(
["key", "version"],
["services_meta_data.key", "services_meta_data.version"],
onupdate="CASCADE",
ondelete="CASCADE",
),
sa.PrimaryKeyConstraint(
"key", "version", "gid", "product_name", name="services_access_pk"
),
)