|
14 | 14 | import os
|
15 | 15 | from datetime import datetime
|
16 | 16 |
|
17 |
| -from tornado import gen |
18 |
| -from tornado.ioloop import IOLoop |
19 |
| - |
20 | 17 | import DIRAC
|
21 | 18 |
|
22 | 19 | from DIRAC import gLogger, S_OK
|
@@ -94,10 +91,49 @@ def export_streamToClient(self, myDataToSend, token):
|
94 | 91 |
|
95 | 92 | The handler only define the ``post`` verb. Please refer to :py:meth:`.post` for the details.
|
96 | 93 |
|
| 94 | + The ``POST`` arguments expected are: |
| 95 | +
|
| 96 | + * ``method``: name of the method to call |
| 97 | + * ``args``: JSON encoded arguments for the method |
| 98 | + * ``extraCredentials``: (optional) Extra informations to authenticate client |
| 99 | + * ``rawContent``: (optionnal, default False) If set to True, return the raw output |
| 100 | + of the method called. |
| 101 | +
|
| 102 | + If ``rawContent`` was requested by the client, the ``Content-Type`` |
| 103 | + is ``application/octet-stream``, otherwise we set it to ``application/json`` |
| 104 | + and JEncode retVal. |
| 105 | +
|
| 106 | + If ``retVal`` is a dictionary that contains a ``Callstack`` item, |
| 107 | + it is removed, not to leak internal information. |
| 108 | +
|
| 109 | +
|
| 110 | + Example of call using ``requests``:: |
| 111 | +
|
| 112 | + In [20]: url = 'https://server:8443/DataManagement/TornadoFileCatalog' |
| 113 | + ...: cert = '/tmp/x509up_u1000' |
| 114 | + ...: kwargs = {'method':'whoami'} |
| 115 | + ...: caPath = '/home/dirac/ClientInstallDIR/etc/grid-security/certificates/' |
| 116 | + ...: with requests.post(url, data=kwargs, cert=cert, verify=caPath) as r: |
| 117 | + ...: print r.json() |
| 118 | + ...: |
| 119 | + {u'OK': True, |
| 120 | + u'Value': {u'DN': u'/C=ch/O=DIRAC/OU=DIRAC CI/CN=ciuser/[email protected]', |
| 121 | + u'group': u'dirac_user', |
| 122 | + u'identity': u'/C=ch/O=DIRAC/OU=DIRAC CI/CN=ciuser/[email protected]', |
| 123 | + u'isLimitedProxy': False, |
| 124 | + u'isProxy': True, |
| 125 | + u'issuer': u'/C=ch/O=DIRAC/OU=DIRAC CI/CN=ciuser/[email protected]', |
| 126 | + u'properties': [u'NormalUser'], |
| 127 | + u'secondsLeft': 85441, |
| 128 | + u'subject': u'/C=ch/O=DIRAC/OU=DIRAC CI/CN=ciuser/[email protected]/CN=2409820262', |
| 129 | + u'username': u'adminusername', |
| 130 | + u'validDN': False, |
| 131 | + u'validGroup': False}} |
| 132 | +
|
97 | 133 | """
|
98 | 134 |
|
99 |
| - # Prefix of methods names |
100 |
| - METHOD_PREFIX = "export_" |
| 135 | + # To access DIRAC services, RPC requests are used only through the HTTP POST method |
| 136 | + SUPPORTED_METHODS = ["POST"] |
101 | 137 |
|
102 | 138 | @classmethod
|
103 | 139 | def _getServiceName(cls, request):
|
@@ -151,67 +187,6 @@ def _getMethodArgs(self, args):
|
151 | 187 | args_encoded = self.get_body_argument("args", default=encode([]))
|
152 | 188 | return (decode(args_encoded)[0], {})
|
153 | 189 |
|
154 |
| - # Make post a coroutine. |
155 |
| - # See https://www.tornadoweb.org/en/branch5.1/guide/coroutines.html#coroutines |
156 |
| - # for details |
157 |
| - @gen.coroutine |
158 |
| - def post(self, *args, **kwargs): # pylint: disable=arguments-differ |
159 |
| - """ |
160 |
| - Method to handle incoming ``POST`` requests. |
161 |
| - Note that all the arguments are already prepared in the :py:meth:`.prepare` |
162 |
| - method. |
163 |
| -
|
164 |
| - The ``POST`` arguments expected are: |
165 |
| -
|
166 |
| - * ``method``: name of the method to call |
167 |
| - * ``args``: JSON encoded arguments for the method |
168 |
| - * ``extraCredentials``: (optional) Extra informations to authenticate client |
169 |
| - * ``rawContent``: (optionnal, default False) If set to True, return the raw output |
170 |
| - of the method called. |
171 |
| -
|
172 |
| - If ``rawContent`` was requested by the client, the ``Content-Type`` |
173 |
| - is ``application/octet-stream``, otherwise we set it to ``application/json`` |
174 |
| - and JEncode retVal. |
175 |
| -
|
176 |
| - If ``retVal`` is a dictionary that contains a ``Callstack`` item, |
177 |
| - it is removed, not to leak internal information. |
178 |
| -
|
179 |
| -
|
180 |
| - Example of call using ``requests``:: |
181 |
| -
|
182 |
| - In [20]: url = 'https://server:8443/DataManagement/TornadoFileCatalog' |
183 |
| - ...: cert = '/tmp/x509up_u1000' |
184 |
| - ...: kwargs = {'method':'whoami'} |
185 |
| - ...: caPath = '/home/dirac/ClientInstallDIR/etc/grid-security/certificates/' |
186 |
| - ...: with requests.post(url, data=kwargs, cert=cert, verify=caPath) as r: |
187 |
| - ...: print r.json() |
188 |
| - ...: |
189 |
| - {u'OK': True, |
190 |
| - u'Value': {u'DN': u'/C=ch/O=DIRAC/OU=DIRAC CI/CN=ciuser/[email protected]', |
191 |
| - u'group': u'dirac_user', |
192 |
| - u'identity': u'/C=ch/O=DIRAC/OU=DIRAC CI/CN=ciuser/[email protected]', |
193 |
| - u'isLimitedProxy': False, |
194 |
| - u'isProxy': True, |
195 |
| - u'issuer': u'/C=ch/O=DIRAC/OU=DIRAC CI/CN=ciuser/[email protected]', |
196 |
| - u'properties': [u'NormalUser'], |
197 |
| - u'secondsLeft': 85441, |
198 |
| - u'subject': u'/C=ch/O=DIRAC/OU=DIRAC CI/CN=ciuser/[email protected]/CN=2409820262', |
199 |
| - u'username': u'adminusername', |
200 |
| - u'validDN': False, |
201 |
| - u'validGroup': False}} |
202 |
| - """ |
203 |
| - # Execute the method in an executor (basically a separate thread) |
204 |
| - # Because of that, we cannot calls certain methods like `self.write` |
205 |
| - # in _executeMethod. This is because these methods are not threadsafe |
206 |
| - # https://www.tornadoweb.org/en/branch5.1/web.html#thread-safety-notes |
207 |
| - # However, we can still rely on instance attributes to store what should |
208 |
| - # be sent back (reminder: there is an instance |
209 |
| - # of this class created for each request) |
210 |
| - retVal = yield IOLoop.current().run_in_executor(*self._prepareExecutor(args)) |
211 |
| - |
212 |
| - # retVal is :py:class:`tornado.concurrent.Future` |
213 |
| - self._finishFuture(retVal) |
214 |
| - |
215 | 190 | auth_ping = ["all"]
|
216 | 191 |
|
217 | 192 | def export_ping(self):
|
|
0 commit comments