Skip to content

Commit 1e8d4a2

Browse files
TaykYokufstagni
andcommitted
fix: use lowercase style for decorators
Co-Authored-By: fstagni <[email protected]>
1 parent b2c8dd3 commit 1e8d4a2

File tree

4 files changed

+24
-33
lines changed

4 files changed

+24
-33
lines changed

src/DIRAC/Core/Tornado/Server/HandlerManager.py

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22
This module contains the necessary tools to discover and load
33
the handlers for serving HTTPS
44
"""
5-
6-
from __future__ import absolute_import
7-
from __future__ import division
8-
from __future__ import print_function
9-
10-
__RCSID__ = "$Id$"
11-
12-
from tornado.web import url as TornadoURL, RequestHandler
5+
from tornado.web import RequestHandler
136

147
from DIRAC import gConfig, gLogger, S_ERROR, S_OK
158
from DIRAC.ConfigurationSystem.Client import PathFinder
@@ -107,8 +100,8 @@ def __load(self, instances, componentType, pathFinder):
107100
if not instances:
108101
return S_OK()
109102

110-
# Extract ports
111-
ports, instances = self.__extractPorts(instances)
103+
# Extract ports, e.g.: ['Framework/MyService', 'Framework/MyService2:9443]
104+
port, instances = self.__extractPorts(instances)
112105

113106
loader = ModuleLoader(componentType, pathFinder, RequestHandler, moduleSuffix="Handler")
114107

@@ -137,7 +130,7 @@ def __load(self, instances, componentType, pathFinder):
137130
return S_ERROR(f"URL not found for {fullComponentName}")
138131

139132
# Add new handler routes
140-
self.__handlers[fullComponentName] = dict(URLs=list(set(urls)), Port=ports.get(fullComponentName))
133+
self.__handlers[fullComponentName] = dict(URLs=list(set(urls)), Port=port.get(fullComponentName))
141134

142135
return result
143136

src/DIRAC/Core/Tornado/Server/TornadoREST.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
sLog = gLogger.getSubLogger(__name__)
1818

1919
# decorator to determine the path to access the target method
20-
LOCATION = partial(SETTINGS, "LOCATION")
21-
LOCATION.__doc__ = """
20+
location = partial(set_attribute, "location")
21+
location.__doc__ = """
2222
Use this decorator to determine the request path to the target method
2323
2424
Example:
2525
26-
@LOCATION('/test/myAPI')
26+
@location('/test/myAPI')
2727
def post_my_method(self, a, b):
2828
''' Usage:
2929
@@ -128,8 +128,8 @@ def delete_job(self, jobIDs):
128128
'''
129129
return self.j_manager.deleteJob(jobIDs)
130130
131-
@AUTHENTICATION(["VISITOR"])
132-
@AUTHORIZATION(["all"])
131+
@authentication(["VISITOR"])
132+
@authorization(["all"])
133133
def options_job(self):
134134
'''Usage:
135135
@@ -196,7 +196,7 @@ def _pre_initialize(cls) -> list:
196196

197197
# Find target method URL
198198
url = os.path.join(
199-
cls.DEFAULT_LOCATION, getattr(mObj, "LOCATION", "" if methodName == "index" else methodName)
199+
cls.DEFAULT_LOCATION, getattr(mObj, "location", "" if methodName == "index" else methodName)
200200
)
201201
if cls.BASE_URL and cls.BASE_URL.strip("/"):
202202
url = cls.BASE_URL.strip("/") + (f"/{url}" if (url := url.strip("/")) else "")
@@ -327,7 +327,7 @@ def _getMethodArgs(self, args: tuple, kwargs: dict) -> tuple:
327327
# requests.post(url + "/my_api/pos_only_value", data={'standard': standard_value, 'kwd_only': kwd_only_value}, ..
328328
# requests.post(url + "/my_api", json=[pos_only_value, standard_value, kwd_only_value], ..
329329
330-
@LOCATION("/my_api")
330+
@location("/my_api")
331331
def post_note(self, pos_only, /, standard, *, kwd_only):
332332
..
333333

src/DIRAC/Core/Tornado/Server/private/BaseRequestHandler.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@
3535
sLog = gLogger.getSubLogger(__name__.split(".")[-1])
3636

3737

38-
def SETTINGS(attr, val):
38+
def set_attribute(attr, val):
3939
"""Decorator to determine target method settings. Set method attribute.
4040
4141
Usage::
4242
43-
@SETTINGS('my attribure', 'value')
43+
@set_attribute('my attribure', 'value')
4444
def export_myMethod(self):
4545
pass
4646
"""
@@ -52,24 +52,24 @@ def Inner(func):
5252
return Inner
5353

5454

55-
AUTHENTICATION = partial(SETTINGS, "AUTHENTICATION")
56-
AUTHENTICATION.__doc__ = """
55+
authentication = partial(set_attribute, "authentication")
56+
authentication.__doc__ = """
5757
Decorator to determine authentication types
5858
5959
Usage::
6060
61-
@AUTHENTICATION(["SSL", "VISITOR"])
61+
@authentication(["SSL", "VISITOR"])
6262
def export_myMethod(self):
6363
pass
6464
"""
6565

66-
AUTHORIZATION = partial(SETTINGS, "AUTHORIZATION")
67-
AUTHORIZATION.__doc__ = """
66+
authorization = partial(set_attribute, "authorization")
67+
authorization.__doc__ = """
6868
Decorator to determine authorization requirements
6969
7070
Usage::
7171
72-
@AUTHORIZATION(["authenticated"])
72+
@authorization(["authenticated"])
7373
def export_myMethod(self):
7474
pass
7575
"""
@@ -336,7 +336,7 @@ def __pre_initialize(cls) -> list:
336336
cls._authManager = AuthManager(cls._getCSAuthorizarionSection(cls._fullComponentName))
337337

338338
if not (urls := cls._pre_initialize()):
339-
sLog.warn(f"no one target method found for {cls.__name__}!")
339+
sLog.warn(f"no target method found for {cls.__name__}!")
340340
return urls
341341

342342
@classmethod
@@ -567,7 +567,7 @@ def __getMethodAuthProps(self) -> list:
567567
There are two ways to define authorization requirements for the target method:
568568
Use auth_< method name > class value or use `AUTH` decorator:
569569
570-
@AUTHORIZATION(['authenticated'])
570+
@authorization(['authenticated'])
571571
def export_myMethod(self):
572572
# Do something
573573
@@ -582,7 +582,7 @@ def export_myMethod(self):
582582

583583
# Define target method authorization requirements
584584
return getattr(
585-
self, "auth_" + self.__methodName, getattr(self.methodObj, "AUTHORIZATION", self.DEFAULT_AUTHORIZATION)
585+
self, "auth_" + self.__methodName, getattr(self.methodObj, "authorization", self.DEFAULT_AUTHORIZATION)
586586
)
587587

588588
async def prepare(self):

src/DIRAC/FrameworkSystem/API/AuthHandler.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,14 @@
1212
from dominate import tags as dom
1313

1414
from DIRAC import gConfig
15-
from DIRAC.Core.Tornado.Server.TornadoREST import LOCATION, TornadoREST
15+
from DIRAC.Core.Tornado.Server.TornadoREST import location, TornadoREST
1616
from DIRAC.ConfigurationSystem.Client.Helpers.Registry import getIdPForGroup, getGroupsForUser
1717
from DIRAC.FrameworkSystem.private.authorization.AuthServer import AuthServer
1818
from DIRAC.FrameworkSystem.private.authorization.utils.Requests import createOAuth2Request
1919
from DIRAC.FrameworkSystem.private.authorization.grants.DeviceFlow import DeviceAuthorizationEndpoint
2020
from DIRAC.FrameworkSystem.private.authorization.grants.RevokeToken import RevocationEndpoint
2121
from DIRAC.FrameworkSystem.private.authorization.utils.Utilities import getHTML
2222

23-
__RCSID__ = "$Id$"
24-
2523

2624
class AuthHandler(TornadoREST):
2725
# Authorization access to all methods handled by AuthServer instance
@@ -42,7 +40,7 @@ def initializeRequest(self):
4240
"""Called at every request"""
4341
self.currentPath = self.request.protocol + "://" + self.request.host + self.request.path
4442

45-
@LOCATION(".well-known/(oauth-authorization-server|openid-configuration)")
43+
@location(".well-known/(oauth-authorization-server|openid-configuration)")
4644
def get_index(self, **kwargs):
4745
"""Well known endpoint, specified by
4846
`RFC8414 <https://tools.ietf.org/html/rfc8414#section-3>`_

0 commit comments

Comments
 (0)