Skip to content

Commit 3ed14d0

Browse files
committed
Supply user.name when calling package repository
PNDA-4562
1 parent 2de5989 commit 3ed14d0

File tree

3 files changed

+82
-27
lines changed

3 files changed

+82
-27
lines changed

README.md

Lines changed: 69 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,16 @@ To build the Deployment Manager, change to the `api` directory, which contains t
9696

9797
?recency=n may be used to control how many versions of each package are listed, by default recency=1
9898
````
99-
GET /repository/packages
99+
GET /repository/packages?user.name=<username>
100100
101101
Response Codes:
102102
200 - OK
103+
403 - Unauthorised user
103104
500 - Server Error
104105
106+
Query Parameters:
107+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
108+
105109
Example response:
106110
[
107111
{
@@ -118,24 +122,32 @@ Example response:
118122

119123
### List packages currently deployed to the cluster
120124
````
121-
GET /packages
125+
GET /packages?user.name=<username>
122126
123127
Response Codes:
124128
200 - OK
129+
403 - Unauthorised user
125130
500 - Server Error
126131
132+
Query Parameters:
133+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
134+
127135
Example response:
128136
["spark-batch-example-app-1.0.23"]
129137
````
130138

131139
### Get the status for _package_
132140
````
133-
GET /packages/<package>/status
141+
GET /packages/<package>/status?user.name=<username>
134142
135143
Response Codes:
136144
200 - OK
145+
403 - Unauthorised user
137146
500 - Server Error
138147
148+
Query Parameters:
149+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
150+
139151
Example response:
140152
{"status": "DEPLOYED", "information": "human readable error message or other information about this status"}
141153
@@ -148,12 +160,16 @@ UNDEPLOYING
148160

149161
### Get full information for _package_
150162
````
151-
GET /packages/<package>
163+
GET /packages/<package>?user.name=<username>
152164
153165
Response Codes:
154166
200 - OK
167+
403 - Unauthorised user
155168
500 - Server Error
156169
170+
Query Parameters:
171+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
172+
157173
Example response:
158174
{
159175
"status": "DEPLOYED",
@@ -179,61 +195,80 @@ Example response:
179195

180196
### Deploy _package_ to the cluster
181197
````
182-
PUT /packages/<package>
198+
PUT /packages/<package>?user.name=<username>
183199
184200
Response Codes:
185201
202 - Accepted, poll /packages/<package>/status for status
202+
403 - Unauthorised user
186203
404 - Package not found in repository
187204
409 - Package already deployed
188205
500 - Server Error
206+
207+
Query Parameters:
208+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
189209
````
190210

191211
### Undeploy _package_ from the cluster
192212
````
193-
DELETE /packages/<package>
213+
DELETE /packages/<package>?user.name=<username>
194214
195215
Response Codes:
196216
202 - Accepted, poll /packages/<package>/status for status
197217
403 - Unauthorised user
198218
404 - Package not deployed
199219
500 - Server Error
220+
221+
Query Parameters:
222+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
200223
````
201224

202225
## Applications API
203226

204227
### List all applications
205228
````
206-
GET /applications
229+
GET /applications?user.name=<username>
207230
208231
Response Codes:
209232
200 - OK
233+
403 - Unauthorised user
210234
500 - Server Error
211235
236+
Query Parameters:
237+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
238+
212239
Example response:
213240
["spark-batch-example-app-instance"]
214241
````
215242

216243
### List applications that have been created from _package_
217244
````
218-
GET /packages/<package>/applications
245+
GET /packages/<package>/applications?user.name=<username>
219246
220247
Response Codes:
221248
200 - OK
249+
403 - Unauthorised user
222250
500 - Server Error
223251
252+
Query Parameters:
253+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
254+
224255
Example response:
225256
["spark-batch-example-app-instance"]
226257
````
227258

228259
### Get the status for _application_
229260
````
230-
GET /applications/<application>/status
261+
GET /applications/<application>/status?user.name=<username>
231262
232263
Response Codes:
233264
200 - OK
265+
403 - Unauthorised user
234266
404 - Application not known
235267
500 - Server Error
236268
269+
Query Parameters:
270+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
271+
237272
Example response:
238273
{"status": "STARTED", "information": "human readible error message or other information about this status"}
239274
@@ -249,13 +284,17 @@ DESTROYING
249284

250285
### Get run-time details for _application_
251286
````
252-
GET /applications/<application>/detail
287+
GET /applications/<application>/detail?user.name=<username>
253288
254289
Response Codes:
255290
200 - OK
291+
403 - Unauthorised user
256292
404 - Application not known
257293
500 - Server Error
258294
295+
Query Parameters:
296+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
297+
259298
{
260299
"yarn_applications": {
261300
"oozie-example": {
@@ -274,12 +313,16 @@ Response Codes:
274313

275314
### Get the summary status for _application_
276315
````
277-
GET /applications/<application>/summary
316+
GET /applications/<application>/summary?user.name=<username>
278317
279318
Response Codes:
280319
200 - OK
320+
403 - Unauthorised user
281321
404 - Application not known
282322
500 - Server Error
323+
324+
Query Parameters:
325+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
283326
````
284327

285328
### Summary status in case of oozie component
@@ -368,7 +411,7 @@ Response Codes:
368411
500 - Server Error
369412
370413
Query Parameters:
371-
user - User with permisson to perform this action on the application should be passed.
414+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
372415
````
373416

374417
### Stop _application_
@@ -382,18 +425,22 @@ Response Codes:
382425
500 - Server Error
383426
384427
Query Parameters:
385-
user - User with permisson to perform this action on the application should be passed.
428+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
386429
````
387430

388431
### Get full information for _application_
389432
````
390-
GET /applications/<application>
433+
GET /applications/<application>?user.name=<username>
391434
392435
Response Codes:
393436
200 - OK
437+
403 - Unauthorised user
394438
404 - Application not known
395439
500 - Server Error
396440
441+
Query Parameters:
442+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
443+
397444
Example response:
398445
{
399446
"status": "CREATED",
@@ -441,12 +488,13 @@ PUT /applications/<application>?user.name=<username>
441488
Response Codes:
442489
202 - Accepted, poll /applications/<application>/status for status
443490
400 - Request body failed validation
491+
403 - Unauthorised user
444492
404 - Package not found
445493
409 - Application already exists
446494
500 - Server Error
447495
448496
Query Parameters:
449-
user - User creating this application should be passed.
497+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
450498
451499
Example body:
452500
{
@@ -472,18 +520,22 @@ Response Codes:
472520
500 - Server Error
473521
474522
Query Parameters:
475-
user - User with permisson to perform this action on the application should be passed.
523+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
476524
````
477525

478526
## Environment Endpoints API
479527
### List environment variables known to the deployment manager
480528
````
481-
GET /environment/endpoints
529+
GET /environment/endpoints?user.name=<username>
482530
483531
Response Codes:
484532
200 - OK
533+
403 - Unauthorised user
485534
500 - Server Error
486535
536+
Query Parameters:
537+
user.name - User name to run this command as. Should have permissions to perform the action as defined in authorizer_rules.yaml.
538+
487539
Example response:
488540
{"zookeeper_port": "2181", "cluster_root_user": "cloud-user", ... }
489541
````

api/src/main/resources/deployment_manager.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,12 @@ def __init__(self, repository, package_registrar, application_registrar, applica
8585
def _get_groups(self, user):
8686
groups = []
8787
if user:
88-
groups = [g.gr_name for g in grp.getgrall() if user in g.gr_mem]
89-
gid = pwd.getpwnam(user).pw_gid
90-
groups.append(grp.getgrgid(gid).gr_name)
88+
try:
89+
groups = [g.gr_name for g in grp.getgrall() if user in g.gr_mem]
90+
gid = pwd.getpwnam(user).pw_gid
91+
groups.append(grp.getgrgid(gid).gr_name)
92+
except:
93+
raise Forbidden('Failed to find details for user "%s"' % user)
9194
return groups
9295

9396
def _authorize(self, user_name, resource_type, resource_owner, action_name):
@@ -119,7 +122,7 @@ def _assert_package_status(self, package, required_status):
119122
def list_repository(self, recency, user_name):
120123
self._authorize(user_name, Resources.REPOSITORY, None, Actions.READ)
121124
logging.info("list_available: %s", recency)
122-
available = self._repository.get_package_list(recency)
125+
available = self._repository.get_package_list(user_name, recency)
123126
return available
124127

125128
def _get_saved_package_data(self, package):
@@ -226,7 +229,7 @@ def _do_deploy():
226229
package_file = package + '.tar.gz'
227230
logging.info("deploy: %s", package)
228231
# download package:
229-
package_data_path = self._repository.get_package(package_file)
232+
package_data_path = self._repository.get_package(package_file, user_name)
230233
# put package in database:
231234
metadata = self._package_parser.get_package_metadata(package_data_path)
232235
self._application_creator.validate_package(package, metadata)

api/src/main/resources/package_repo_rest_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,27 @@ def put_package(self, package_name, package_data):
4747
logging.debug("response code: %s", str(response.status_code))
4848
assert response.status_code == 200
4949

50-
def get_package(self, package_name, expected_codes=None):
50+
def get_package(self, package_name, user_name, expected_codes=None):
5151
"""
5252
gets a package from the repository
5353
:param package_nam:
5454
:return: local path to file
5555
"""
5656
if not expected_codes:
5757
expected_codes = [200]
58-
response = self.make_rest_get_request("/packages/" + package_name, expected_codes)
58+
response = self.make_rest_get_request("/packages/%s?user.name=%s" % (package_name, user_name), expected_codes)
5959
local_path = "%s/%s" % (self._package_local_dir_path, package_name)
6060
with open(local_path, 'wb') as local_file:
6161
local_file.write(response.content)
6262
return local_path
6363

64-
def get_package_list(self, recency=None):
64+
def get_package_list(self, user_name, recency=None):
6565
"""
6666
:return: a list of all packages in the repository
6767
"""
68-
url = "/packages"
68+
url = "/packages?user.name=%s" % user_name
6969
if recency:
70-
url = url + "?recency=" + str(recency)
70+
url = url + "&recency=" + str(recency)
7171
response = self.make_rest_get_request(url)
7272
return json.loads(response.content)
7373

0 commit comments

Comments
 (0)