RequestValidator
- mod:
RequestValidator
- synopsis:
request validator
A general and simple request validator checking for required attributes and logic. It checks if required attributes are set/unset but not for their values.
RequestValidator class implements the DIRACSingleton pattern, no global object is required to keep a single instance.
If you need to extend this one with your own specific checks consider:
for adding Operation or Files required attributes use
addReqAttrsCheck
function:RequestValidator().addReqAttrsCheck( "FooOperation", operationAttrs = [ "Bar", "Buzz"], filesAttrs = [ "LFN" ] )for adding generic check define a new callable object ( function or functor ) which takes only one argument, say for functor:
class MyValidator( RequestValidator ): @staticmethod def hasFoo( request ): if not request.Foo: return S_ERROR("Foo not set") return S_OK()or function:
def hasBar( request ): if not request.Bar: return S_ERROR("Bar not set") return S_OK()
and add this one to the validators set by calling RequestValidator().addValidator, i.e.:
RequestValidator().addValidator( MyValidator.hasFoo )
RequestValidator().addValidator( hasFoo )
Notice that all validators should always return S_ERROR/S_OK, no exceptions from that whatsoever!
- class DIRAC.RequestManagementSystem.private.RequestValidator.RequestValidator(*args, **kwargs)
Bases:
object
- class RequestValidator
This class validates newly created requests (before saving them in RequestDB) for required attributes.
- __init__()
c’tor
just setting validation order
- classmethod addReqAttrsCheck(operationType, operationAttrs=None, filesAttrs=None)
add required attributes of Operation of type :operationType:
- classmethod addValidator(fcnObj)
add fcnObj validator
- instance = None
- opHandlers = {}
- reqAttrs = {'ForwardDISET': {'Files': [], 'Operation': ['Arguments']}, 'PhysicalRemoval': {'Files': ['LFN'], 'Operation': ['TargetSE']}, 'PutAndRegister': {'Files': ['LFN', 'PFN'], 'Operation': ['TargetSE']}, 'ReTransfer': {'Files': ['LFN', 'PFN'], 'Operation': ['TargetSE']}, 'RegisterFile': {'Files': ['LFN', 'PFN', 'ChecksumType', 'Checksum', 'GUID'], 'Operation': []}, 'RegisterReplica': {'Files': ['LFN', 'PFN'], 'Operation': ['TargetSE']}, 'RemoveFile': {'Files': ['LFN'], 'Operation': []}, 'RemoveReplica': {'Files': ['LFN'], 'Operation': ['TargetSE']}, 'ReplicateAndRegister': {'Files': ['LFN'], 'Operation': ['TargetSE']}}
- static setAndCheckRequestOwner(request, remoteCredentials)
- CAUTION: meant to be called on the server side.
(does not make much sense otherwise)
Sets the owner and ownerGroup of the Request from the client’s credentials.
If they are already set, make sure the client is allowed to do so (FULL_DELEGATION or LIMITED_DELEGATION). This is the case of pilots or the RequestExecutingAgent
- Parameters:
request – the request to test
remoteCredentials – credentials from the clients
- Returns:
True if everything is fine, False otherwise