Skip to content

Commit c87ae5e

Browse files
authored
Merge pull request #8150 from chaen/fix_req_compat
Fix req compat
2 parents a88d33d + a24f10b commit c87ae5e

File tree

2 files changed

+42
-60
lines changed

2 files changed

+42
-60
lines changed

src/DIRAC/RequestManagementSystem/Agent/RequestOperations/ForwardDISET.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
""" :mod: ForwardDISET
2-
3-
==================
4-
5-
.. module: ForwardDISET
6-
7-
:synopsis: DISET forwarding operation handler
8-
9-
.. moduleauthor:: [email protected]
10-
11-
DISET forwarding operation handler
12-
"""
13-
141
import importlib
2+
from collections.abc import Sequence
153

164
# imports
175
from DIRAC import S_ERROR, S_OK, gConfig
@@ -65,7 +53,7 @@ def __call__(self):
6553
return S_ERROR(str(error))
6654

6755
# This is the DISET rpcStub
68-
if isinstance(stub, tuple):
56+
if isinstance(stub, Sequence):
6957
# Ensure the forwarded request is done on behalf of the request owner
7058
res = getDNForUsername(self.request.Owner)
7159
if not res["OK"]:

src/DIRAC/RequestManagementSystem/private/RequestValidator.py

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
1-
""" :mod: RequestValidator
1+
""":mod: RequestValidator
22
3-
======================
3+
======================
44
5-
.. module: RequestValidator
5+
.. module: RequestValidator
66
7-
:synopsis: request validator
7+
:synopsis: request validator
88
9-
.. moduleauthor:: [email protected]
9+
.. moduleauthor:: [email protected]
1010
11-
A general and simple request validator checking for required attributes and logic.
12-
It checks if required attributes are set/unset but not for their values.
11+
A general and simple request validator checking for required attributes and logic.
12+
It checks if required attributes are set/unset but not for their values.
1313
14-
RequestValidator class implements the DIRACSingleton pattern, no global object is
15-
required to keep a single instance.
14+
RequestValidator class implements the DIRACSingleton pattern, no global object is
15+
required to keep a single instance.
1616
17-
If you need to extend this one with your own specific checks consider:
17+
If you need to extend this one with your own specific checks consider:
1818
19-
* for adding Operation or Files required attributes use :any:`addReqAttrsCheck` function::
19+
* for adding Operation or Files required attributes use :any:`addReqAttrsCheck` function::
2020
21-
RequestValidator().addReqAttrsCheck( "FooOperation", operationAttrs = [ "Bar", "Buzz"], filesAttrs = [ "LFN" ] )
21+
RequestValidator().addReqAttrsCheck( "FooOperation", operationAttrs = [ "Bar", "Buzz"], filesAttrs = [ "LFN" ] )
2222
23-
* for adding generic check define a new callable object ( function or functor ) which takes only one argument,
24-
say for functor::
23+
* for adding generic check define a new callable object ( function or functor ) which takes only one argument,
24+
say for functor::
2525
26-
class MyValidator( RequestValidator ):
26+
class MyValidator( RequestValidator ):
2727
28-
@staticmethod
29-
def hasFoo( request ):
30-
if not request.Foo:
31-
return S_ERROR("Foo not set")
32-
return S_OK()
28+
@staticmethod
29+
def hasFoo( request ):
30+
if not request.Foo:
31+
return S_ERROR("Foo not set")
32+
return S_OK()
3333
34-
* or function::
34+
* or function::
3535
36-
def hasBar( request ):
37-
if not request.Bar:
38-
return S_ERROR("Bar not set")
39-
return S_OK()
36+
def hasBar( request ):
37+
if not request.Bar:
38+
return S_ERROR("Bar not set")
39+
return S_OK()
4040
41-
and add this one to the validators set by calling `RequestValidator().addValidator`, i.e.::
41+
and add this one to the validators set by calling `RequestValidator().addValidator`, i.e.::
4242
43-
RequestValidator().addValidator( MyValidator.hasFoo )
44-
RequestValidator().addValidator( hasFoo )
43+
RequestValidator().addValidator( MyValidator.hasFoo )
44+
RequestValidator().addValidator( hasFoo )
4545
46-
Notice that all validators should always return S_ERROR/S_OK, no exceptions from that whatsoever!
46+
Notice that all validators should always return S_ERROR/S_OK, no exceptions from that whatsoever!
4747
"""
4848

4949
import inspect
@@ -53,6 +53,7 @@ def hasBar( request ):
5353
from DIRAC.Core.Security.Properties import FULL_DELEGATION, LIMITED_DELEGATION
5454
from DIRAC.Core.Utilities.DIRACSingleton import DIRACSingleton
5555
from DIRAC.ConfigurationSystem.Client import PathFinder
56+
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getUsernameForDN
5657

5758

5859
class RequestValidator(metaclass=DIRACSingleton):
@@ -268,28 +269,21 @@ def setAndCheckRequestOwner(request, remoteCredentials):
268269
269270
:returns: True if everything is fine, False otherwise
270271
"""
271-
272272
credUserName = remoteCredentials["username"]
273273
credGroup = remoteCredentials["group"]
274274
credProperties = remoteCredentials["properties"]
275-
ownershipCheck = None
276-
277-
# FIXME: code for backward compatibility with requests created by 8.0 clients
278-
# The below can be clearly simplified, leaving the extended checks for clarity
279-
if hasattr(request, "OwnerDN") and not hasattr(
280-
request, "Owner"
281-
): # Requests created by v8.0 client for v8.0 servers
282-
ownershipCheck = request.OwnerDN
283-
if not hasattr(request, "OwnerDN") and hasattr(
284-
request, "Owner"
285-
): # Requests created by v9 client for v9 servers
286-
ownershipCheck = request.Owner
287-
if hasattr(request, "OwnerDN") and hasattr(request, "Owner"): # Requests created by v8.0 client for v9 servers
288-
ownershipCheck = request.Owner
289-
# ##
275+
276+
# In case we have an old style request with only a DN and no Owner,
277+
# get the Owner from the DN.
278+
if getattr(request, "OwnerDN", None) and not getattr(request, "Owner", None):
279+
res = getUsernameForDN(request.OwnerDN)
280+
if not res["OK"]:
281+
gLogger.error("Cannot Validate request", res)
282+
return False
283+
request.Owner = res["Value"]
290284

291285
# If the owner or the group was not set, we use the one of the credentials
292-
if not ownershipCheck or not request.OwnerGroup:
286+
if not request.Owner or not request.OwnerGroup:
293287
request.Owner = credUserName
294288
request.OwnerGroup = credGroup
295289
return True

0 commit comments

Comments
 (0)