1
+ import logging
1
2
from cssefserver .utils import get_empty_return_dict
2
3
from cssefserver .utils import CssefRPCEndpoint
3
4
from cssefserver .taskutils import model_del
@@ -12,8 +13,13 @@ class OrganizationAdd(CssefRPCEndpoint):
12
13
name = "Organization Add"
13
14
rpc_name = "organizationadd"
14
15
menu_path = "organization.add"
15
- onRequestArgs = ['auth' ]
16
- def on_request (self , auth , ** kwargs ):
16
+ args = [
17
+ {'name' : 'name' , 'type' : 'str' , 'required' : True },
18
+ {'name' : 'description' , 'type' : 'str' , 'required' : True },
19
+ {'name' : 'can_add_users' , 'type' : 'bool' , 'required' : False },
20
+ {'name' : 'can_delete_users' , 'type' : 'bool' , 'required' : False }]
21
+
22
+ def on_request (self , ** kwargs ):
17
23
"""Celery task to create a new organization.
18
24
19
25
Args:
@@ -23,10 +29,7 @@ def on_request(self, auth, **kwargs):
23
29
A return_dict dictionary containing the results of the API call. See
24
30
get_empty_return_dict for more information.
25
31
"""
26
- try :
27
- authorize_access (self .database_connection , auth , self .config )
28
- except CssefException as err :
29
- return err .as_return_dict ()
32
+ authorize_access (self .database_connection , self .auth , self .config )
30
33
organization = Organization .from_dict (self .database_connection , kwargs )
31
34
return_dict = get_empty_return_dict ()
32
35
return_dict ['content' ].append (organization .as_dict ())
@@ -36,9 +39,10 @@ class OrganizationDel(CssefRPCEndpoint):
36
39
name = "Organization Delete"
37
40
rpc_name = "organizationdel"
38
41
menu_path = "organization.del"
39
- takesKwargs = False
40
- onRequestArgs = ['auth' , 'pkid' ]
41
- def on_request (self , auth , pkid ):
42
+ args = [
43
+ {'name' : 'pkid' , 'type' : 'int' , 'required' : True }]
44
+
45
+ def on_request (self , pkid ):
42
46
"""Celery task to delete an existing organization.
43
47
44
48
Args:
@@ -48,15 +52,21 @@ def on_request(self, auth, pkid):
48
52
A return_dict dictionary containing the results of the API call. See
49
53
get_empty_return_dict for more information.
50
54
"""
51
- authorize_access (self .database_connection , auth , self .config )
55
+ authorize_access (self .database_connection , self . auth , self .config )
52
56
return model_del (Organization , self .database_connection , pkid )
53
57
54
58
class OrganizationSet (CssefRPCEndpoint ):
55
59
name = "Organization Set"
56
60
rpc_name = "organizationset"
57
61
menu_path = "organization.set"
58
- onRequestArgs = ['auth' , 'pkid' ]
59
- def on_request (self , auth , pkid , ** kwargs ):
62
+ args = [
63
+ {'name' : 'pkid' , 'type' : 'int' , 'required' : True },
64
+ {'name' : 'name' , 'type' : 'str' , 'required' : False },
65
+ {'name' : 'description' , 'type' : 'str' , 'required' : False },
66
+ {'name' : 'can_add_users' , 'type' : 'bool' , 'required' : False },
67
+ {'name' : 'can_delete_users' , 'type' : 'bool' , 'required' : False }]
68
+
69
+ def on_request (self , pkid , ** kwargs ):
60
70
"""Celery task to edit an existing organization.
61
71
62
72
Args:
@@ -67,15 +77,21 @@ def on_request(self, auth, pkid, **kwargs):
67
77
A return_dict dictionary containing the results of the API call. See
68
78
get_empty_return_dict for more information.
69
79
"""
70
- authorize_access (self .database_connection , auth , self .config )
80
+ authorize_access (self .database_connection , self . auth , self .config )
71
81
return model_set (Organization , self .database_connection , pkid , ** kwargs )
72
82
73
83
class OrganizationGet (CssefRPCEndpoint ):
74
84
name = "Organization Get"
75
85
rpc_name = "organizationget"
76
86
menu_path = "organization.get"
77
- onRequestArgs = ['auth' ]
78
- def on_request (self , auth , ** kwargs ):
87
+ args = [
88
+ {'name' : 'pkid' , 'type' : 'str' , 'required' : False },
89
+ {'name' : 'name' , 'type' : 'str' , 'required' : False },
90
+ {'name' : 'description' , 'type' : 'str' , 'required' : False },
91
+ {'name' : 'can_add_users' , 'type' : 'bool' , 'required' : False },
92
+ {'name' : 'can_delete_users' , 'type' : 'bool' , 'required' : False }]
93
+
94
+ def on_request (self , ** kwargs ):
79
95
"""Celery task to get one or more existing organization.
80
96
81
97
Args:
@@ -85,15 +101,20 @@ def on_request(self, auth, **kwargs):
85
101
A return_dict dictionary containing the results of the API call. See
86
102
get_empty_return_dict for more information.
87
103
"""
88
- authorize_access (self .database_connection , auth , self .config )
104
+ authorize_access (self .database_connection , self . auth , self .config )
89
105
return model_get (Organization , self .database_connection , ** kwargs )
90
106
91
107
class UserAdd (CssefRPCEndpoint ):
92
108
name = "User Add"
93
109
rpc_name = "useradd"
94
110
menu_path = "user.add"
95
- onRequestArgs = ['auth' ]
96
- def on_request (self , auth , ** kwargs ):
111
+ args = [
112
+ {'name' : 'name' , 'type' : 'str' , 'required' : True },
113
+ {'name' : 'username' , 'type' : 'str' , 'required' : True },
114
+ {'name' : 'password' , 'type' : 'str' , 'required' : True },
115
+ {'name' : 'organization' , 'type' : 'int' , 'required' : True }]
116
+
117
+ def on_request (self , ** kwargs ):
97
118
"""Celery task to create a new user.
98
119
99
120
Args:
@@ -105,7 +126,7 @@ def on_request(self, auth, **kwargs):
105
126
get_empty_return_dict for more information.
106
127
"""
107
128
try :
108
- authorize_access (self .database_connection , auth , self .config )
129
+ authorize_access (self .database_connection , self . auth , self .config )
109
130
except CssefException as err :
110
131
return err .as_return_dict ()
111
132
#kwargs['organization'] = organization
@@ -118,9 +139,10 @@ class UserDel(CssefRPCEndpoint):
118
139
name = "User Delete"
119
140
rpc_name = "userdel"
120
141
menu_path = "user.del"
121
- takesKwargs = False
122
- onRequestArgs = ['auth' , 'pkid' ]
123
- def on_request (self , auth , pkid ):
142
+ args = [
143
+ {'name' : 'pkid' , 'type' : 'int' , 'required' : True }]
144
+
145
+ def on_request (self , pkid ):
124
146
"""Celery task to delete an existing user.
125
147
126
148
Args:
@@ -130,15 +152,20 @@ def on_request(self, auth, pkid):
130
152
A return_dict dictionary containing the results of the API call. See
131
153
get_empty_return_dict for more information.
132
154
"""
133
- authorize_access (self .database_connection , auth , self .config )
155
+ authorize_access (self .database_connection , self . auth , self .config )
134
156
return model_del (User , self .database_connection , pkid )
135
157
136
158
class UserSet (CssefRPCEndpoint ):
137
159
name = "User Set"
138
160
rpc_name = "userset"
139
161
menu_path = "user.set"
140
- onRequestArgs = ['auth' , 'pkid' ]
141
- def on_request (self , auth , pkid , ** kwargs ):
162
+ args = [
163
+ {'name' : 'pkid' , 'type' : 'int' , 'required' : True },
164
+ {'name' : 'name' , 'type' : 'str' , 'required' : False },
165
+ {'name' : 'username' , 'type' : 'str' , 'required' : False },
166
+ {'name' : 'password' , 'type' : 'str' , 'required' : False }]
167
+
168
+ def on_request (self , pkid , ** kwargs ):
142
169
"""Celery task to edit an existing user.
143
170
144
171
Args:
@@ -149,15 +176,20 @@ def on_request(self, auth, pkid, **kwargs):
149
176
A return_dict dictionary containing the results of the API call. See
150
177
get_empty_return_dict for more information.
151
178
"""
152
- authorize_access (self .database_connection , auth , self .config )
179
+ authorize_access (self .database_connection , self . auth , self .config )
153
180
return model_set (User , self .database_connection , pkid , ** kwargs )
154
181
155
182
class UserGet (CssefRPCEndpoint ):
156
183
name = "User Get"
157
184
rpc_name = "userget"
158
185
menu_path = "user.get"
159
- onRequestArgs = ['auth' ]
160
- def on_request (self , auth , ** kwargs ):
186
+ args = [
187
+ {'name' : 'pkid' , 'type' : 'int' , 'required' : False },
188
+ {'name' : 'name' , 'type' : 'str' , 'required' : False },
189
+ {'name' : 'username' , 'type' : 'str' , 'required' : False },
190
+ {'name' : 'organization' , 'type' : 'int' , 'required' : False }]
191
+
192
+ def on_request (self , ** kwargs ):
161
193
"""Celery task to get one or more existing users.
162
194
163
195
Args:
@@ -167,7 +199,7 @@ def on_request(self, auth, **kwargs):
167
199
A return_dict dictionary containing the results of the API call. See
168
200
get_empty_return_dict for more information.
169
201
"""
170
- authorize_access (self .database_connection , auth , self .config )
202
+ authorize_access (self .database_connection , self . auth , self .config )
171
203
return model_get (User , self .database_connection , ** kwargs )
172
204
173
205
def endpoint_source ():
0 commit comments