5
5
import cgi
6
6
import falcon
7
7
import os
8
+ import json
8
9
import urllib .parse
10
+ from talos .core import utils
9
11
from talos .core import config
10
12
from talos .core .i18n import _
11
13
from talos .common import controller as base_controller
12
14
13
15
from artifacts_corepy .common .controller import Collection , Item , POSTCollection
14
16
from artifacts_corepy .common import exceptions
15
17
from artifacts_corepy .apps .package import apiv2 as package_api
18
+ from artifacts_corepy .common import constant
16
19
17
20
CONF = config .CONF
18
21
@@ -45,6 +48,22 @@ def on_get(self, req, resp, **kwargs):
45
48
'message' : 'success'
46
49
}
47
50
51
+
52
+ class CollectionProcessDef (Collection ):
53
+ allow_methods = ('GET' , )
54
+ name = 'artifacts.process.defs'
55
+ resource = package_api .ProcessDef
56
+
57
+ class CollectionUser (Collection ):
58
+ allow_methods = ('GET' , )
59
+ name = 'artifacts.users.list'
60
+ resource = package_api .User
61
+
62
+ class CollectionCiData (POSTCollection ):
63
+ allow_methods = ('POST' ,)
64
+ name = 'artifacts.diffconfigs'
65
+ resource = package_api .CiData
66
+
48
67
class CollectionSystemDesign (Collection ):
49
68
allow_methods = ('GET' , )
50
69
name = 'artifacts.system-designs'
@@ -87,10 +106,23 @@ class CollectionUnitDesignPackages(POSTCollection):
87
106
resource = package_api .UnitDesignPackages
88
107
89
108
109
+ class CollectionPackageStatistics (POSTCollection ):
110
+ allow_methods = ('POST' , )
111
+ name = 'artifacts.packages.statistics'
112
+ resource = package_api .UnitDesignPackages
113
+
114
+ def list (self , req , criteria , ** kwargs ):
115
+ return self .make_resource (req ).get_package_statistics (req .json , ** kwargs )
116
+
90
117
class CollectionUnitDesignNexusPackages (POSTCollection ):
91
118
allow_methods = ('POST' , )
92
119
name = 'artifacts.unit-design.nexus.packages'
93
120
resource = package_api .UnitDesignNexusPackages
121
+
122
+ class ItemUnitDesignNexusPackages (Item ):
123
+ allow_methods = ('GET' , )
124
+ name = 'artifacts.unit-design.nexus.path'
125
+ resource = package_api .UnitDesignNexusPackages
94
126
95
127
96
128
class CollectionUnitDesignNexusPackageUpload (object ):
@@ -99,18 +131,24 @@ class CollectionUnitDesignNexusPackageUpload(object):
99
131
100
132
def on_post (self , req , resp , ** kwargs ):
101
133
download_url = req .params .get ('downloadUrl' , None )
134
+ baseline_package = req .params .get ('baseline_package' , None )
135
+ package_type = req .params .get ('package_type' , None )
136
+ if not package_type :
137
+ raise exceptions .ValidationError (message = _ ('missing query param: package_type' ))
138
+ elif package_type not in [constant .PackageType .app , constant .PackageType .db , constant .PackageType .mixed , constant .PackageType .image , constant .PackageType .rule ]:
139
+ raise exceptions .ValidationError (message = _ ('invalid package_type param value: %s' ) % package_type )
102
140
if not download_url :
103
- raise exceptions .ValidationError (message = _ ('missing query: downloadUrl' ))
104
- form = cgi .FieldStorage (fp = req .stream , environ = req .env )
141
+ raise exceptions .ValidationError (message = _ ('missing query param : downloadUrl' ))
142
+ # form = cgi.FieldStorage(fp=req.stream, environ=req.env)
105
143
resp .json = {
106
144
'code' : 200 ,
107
145
'status' : 'OK' ,
108
- 'data' : self .upload (req , download_url , ** kwargs ),
146
+ 'data' : self .upload (req , download_url , baseline_package , package_type , ** kwargs ),
109
147
'message' : 'success'
110
148
}
111
149
112
- def upload (self , req , download_url , ** kwargs ):
113
- return self .resource ().upload_from_nexus (download_url , ** kwargs )
150
+ def upload (self , req , download_url , baseline_package , package_type , ** kwargs ):
151
+ return self .resource ().upload_from_nexus (download_url , baseline_package , package_type , ** kwargs )
114
152
115
153
116
154
class CollectionUnitDesignPackageUpload (object ):
@@ -119,15 +157,25 @@ class CollectionUnitDesignPackageUpload(object):
119
157
120
158
def on_post (self , req , resp , ** kwargs ):
121
159
form = cgi .FieldStorage (fp = req .stream , environ = req .env )
160
+ baseline_package = None
161
+ package_type = None
162
+ if 'baseline_package' in form :
163
+ baseline_package = form .getvalue ('baseline_package' , None )
164
+ if 'package_type' in form :
165
+ package_type = form .getvalue ('package_type' , None )
166
+ if not package_type :
167
+ raise exceptions .ValidationError (message = _ ('missing form param: package_type' ))
168
+ elif package_type not in [constant .PackageType .app , constant .PackageType .db , constant .PackageType .mixed , constant .PackageType .image , constant .PackageType .rule ]:
169
+ raise exceptions .ValidationError (message = _ ('invalid package_type param value: %s' ) % package_type )
122
170
resp .json = {
123
171
'code' : 200 ,
124
172
'status' : 'OK' ,
125
- 'data' : self .upload (req , form ['file' ].filename , form ['file' ].type , form ['file' ].file , ** kwargs ),
173
+ 'data' : self .upload (req , form ['file' ].filename , form ['file' ].type , form ['file' ].file , baseline_package , package_type , ** kwargs ),
126
174
'message' : 'success'
127
175
}
128
176
129
- def upload (self , req , filename , filetype , fileobj , ** kwargs ):
130
- return self .resource ().upload (filename , filetype , fileobj , ** kwargs )
177
+ def upload (self , req , filename , filetype , fileobj , baseline_package , package_type , ** kwargs ):
178
+ return self .resource ().upload (filename , filetype , fileobj , baseline_package , package_type , ** kwargs )
131
179
132
180
133
181
class ItemPackage (Item ):
@@ -305,10 +353,43 @@ class PushComposePackage(base_controller.Controller):
305
353
resource = package_api .UnitDesignPackages
306
354
307
355
def on_post (self , req , resp , ** kwargs ):
356
+ body_param = {}
357
+ if hasattr (req , 'json' ):
358
+ body_param = req .json
308
359
resp .json = {
309
360
'code' : 200 ,
310
361
'status' : 'OK' ,
311
- 'data' : self .resource ().push_compose_package (** kwargs ),
362
+ 'data' : self .resource ().push_compose_package (body_param , ** kwargs ),
363
+ 'message' : 'success'
364
+ }
365
+ resp .status = falcon .HTTP_200
366
+
367
+ class SystemConfig (base_controller .Controller ):
368
+ allow_methods = ('GET' ,)
369
+ name = 'artifacts.systemconfig'
370
+ resource = package_api .UnitDesignPackages
371
+
372
+ def on_get (self , req , resp , ** kwargs ):
373
+ local_nexus_server = CONF .nexus .server
374
+ remote_nexus_server = CONF .wecube .nexus .server
375
+ push_nexus_server = CONF .pushnexus .server
376
+ local_nexus_server = local_nexus_server .strip ()
377
+ remote_nexus_server = remote_nexus_server .strip ()
378
+ push_nexus_server = push_nexus_server .strip ()
379
+ if utils .bool_from_string (CONF .use_remote_nexus_only ):
380
+ local_nexus_server = remote_nexus_server
381
+ resp .json = {
382
+ 'code' : 200 ,
383
+ 'status' : 'OK' ,
384
+ 'data' : {
385
+ 'upload_enabled' : bool (utils .bool_from_string (CONF .wecube .upload_enabled ) and local_nexus_server ),
386
+ 'upload_from_nexus_enabled' : bool (utils .bool_from_string (CONF .wecube .upload_nexus_enabled ) and remote_nexus_server ),
387
+ 'push_to_nexus_enabled' : True if push_nexus_server else False ,
388
+ 'variable_prefix_encrypt' : [] if not CONF .encrypt_variable_prefix .strip () else [s .strip () for s in CONF .encrypt_variable_prefix .split (',' )],
389
+ 'variable_prefix_file' : [] if not CONF .file_variable_prefix .strip () else [s .strip () for s in CONF .file_variable_prefix .split (',' )],
390
+ 'variable_prefix_default' : [] if not CONF .default_special_replace .strip () else [s .strip () for s in CONF .default_special_replace .split (',' )],
391
+ 'variable_prefix_global' : [] if not CONF .global_variable_prefix .strip () else [s .strip () for s in CONF .global_variable_prefix .split (',' )],
392
+ },
312
393
'message' : 'success'
313
394
}
314
395
resp .status = falcon .HTTP_200
0 commit comments