Skip to content

Commit d7901f1

Browse files
fix: Isort fixed, authorization header and doc
1 parent 6c4efbc commit d7901f1

File tree

2 files changed

+21
-35
lines changed

2 files changed

+21
-35
lines changed

Pilot/pilotTools.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,6 @@
1818
from functools import partial, wraps
1919
from threading import RLock
2020

21-
try:
22-
from Pilot.proxyTools import (
23-
X509BasedRequest
24-
)
25-
except ImportError:
26-
from proxyTools import (
27-
X509BasedRequest
28-
)
29-
3021
############################
3122
# python 2 -> 3 "hacks"
3223
try:
@@ -78,9 +69,9 @@ def load_module_from_path(module_name, path_to_module):
7869
basestring = str
7970

8071
try:
81-
from Pilot.proxyTools import getVO
72+
from Pilot.proxyTools import X509BasedRequest, getVO
8273
except ImportError:
83-
from proxyTools import getVO
74+
from proxyTools import X509BasedRequest, getVO
8475

8576
try:
8677
FileNotFoundError # pylint: disable=used-before-assignment

Pilot/proxyTools.py

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
from __future__ import absolute_import, division, print_function
44

5+
import os
56
import re
6-
from base64 import b16decode
7-
from subprocess import PIPE, Popen
87
import ssl
98
import sys
10-
import os
9+
from base64 import b16decode
10+
from subprocess import PIPE, Popen
1111

1212
try:
1313
IsADirectoryError # pylint: disable=used-before-assignment
@@ -47,15 +47,10 @@ def findExtension(oid, lines):
4747
def getVO(proxy_data):
4848
"""Fetches the VO in a chain certificate
4949
50-
Args:
51-
proxy_data (bytes): Bytes for the proxy chain
52-
53-
Raises:
54-
Exception: Any error related to openssl
55-
NotImplementedError: Not documented error
56-
57-
Returns:
58-
str: A VO
50+
:param proxy_data: Bytes for the proxy chain
51+
:type proxy_data: bytes
52+
:return: A VO
53+
:rtype: str
5954
"""
6055

6156
chain = re.findall(br"-----BEGIN CERTIFICATE-----\n.+?\n-----END CERTIFICATE-----", proxy_data, flags=re.DOTALL)
@@ -100,11 +95,11 @@ def __init__(self, url, caPath, name="unknown"):
10095
def generateUserAgent(self, pilotUUID):
10196
"""To analyse the traffic, we can send a taylor-made User-Agent
10297
103-
Args:
104-
pilotUUID (str): Unique ID of the Pilot
105-
106-
Returns:
107-
str: The generated user agent
98+
:param pilotUUID: Unique ID of the Pilot
99+
:type pilotUUID: str
100+
:type param_name: param_type
101+
:return: The generated user agent
102+
:rtype: str
108103
"""
109104
return "Dirac Pilot [%s]" % pilotUUID
110105

@@ -117,12 +112,12 @@ def _prepareRequest(self):
117112
def executeRequest(self, raw_data, headers={"User-Agent": "Dirac Pilot [Unknown ID]"}):
118113
"""Execute a HTTP request with the data, headers, and the pre-defined data (SSL + auth)
119114
120-
Args:
121-
raw_data (dict): Data to send
122-
headers (dict, optional): Headers to send, helps to track requests. Defaults to {"User-Agent": "Dirac Pilot [Unknown ID]"}.
123-
124-
Returns:
125-
str: Response of the HTTP request
115+
:param raw_data: Data to send
116+
:type raw_data: dict
117+
:param headers: Headers to send, helps to track requests. Defaults to {"User-Agent": "Dirac Pilot [Unknown ID]"}.
118+
:type headers: dict, optional
119+
:return: Response of the HTTP request
120+
:rtype: str
126121
"""
127122
if sys.version_info[0] == 3:
128123
data = urlencode(raw_data).encode("utf-8") # encode to bytes ! for python3
@@ -148,7 +143,7 @@ def __init__(self, url, caPath, jwtData):
148143

149144
def executeRequest(self, raw_data, headers={"User-Agent": "Dirac Pilot [Unknown ID]"}):
150145
# Adds the JWT in the HTTP request (in the Bearer field)
151-
headers["Bearer"] = self.jwtData
146+
headers["Authorization"] = "Bearer: %s" % self.jwtData
152147
return super(TokenBasedRequest, self).executeRequest(raw_data, headers)
153148

154149

0 commit comments

Comments
 (0)