Skip to content
Snippets Groups Projects
Commit 91d7d10d authored by Mathieu Courtois's avatar Mathieu Courtois
Browse files

[#30000] update FSQ script for REX authentication

parent 9e50597d
No related branches found
No related tags found
No related merge requests found
...@@ -20,10 +20,12 @@ import api_roundup.stats as ST ...@@ -20,10 +20,12 @@ import api_roundup.stats as ST
# labels des versions "précédentes" (histors dans lesquels chercher) # labels des versions "précédentes" (histors dans lesquels chercher)
INFOS = {"vexpl": "15.8", "vdev": "16.4"} INFOS = {"vexpl": "16.6", "vdev": "17.1"}
FILENAME = "rex_all_issues.pick" FILENAME = "rex_all_issues.pick"
CHANGELOG_PATTERN = osp.join(os.environ["HOME"], "dev", "codeaster", "histor", "1[0-9].*") CHANGELOG_PATTERN = osp.join(
os.environ["HOME"], "dev", "codeaster", "changelog", "histor", "v*", "[0-9].*"
)
def is_fixed(vers, issue): def is_fixed(vers, issue):
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
see documentation at http://roundup.sourceforge.net/docs/xmlrpc.html see documentation at http://roundup.sourceforge.net/docs/xmlrpc.html
""" """
import base64
import os import os
import random import random
import re import re
...@@ -12,7 +13,7 @@ import ssl ...@@ -12,7 +13,7 @@ import ssl
import sys import sys
import xmlrpc.client import xmlrpc.client
from contextlib import contextmanager from contextlib import contextmanager
from urllib.request import urlopen from urllib import request
from aslint.baseutils import force_list from aslint.baseutils import force_list
from aslint.config import ASCFG from aslint.config import ASCFG
...@@ -47,12 +48,8 @@ def _get_url(user="readonly", password="", debug=False): ...@@ -47,12 +48,8 @@ def _get_url(user="readonly", password="", debug=False):
return url return url
def _get_connection(user=None, password="", write=False, debug=False): def _get_user_pass(user=None, password="", write=False):
"""Return a connection to the Roundup server. """Return user/password for requests with defaults and error message."""
If user/password are provided they are passed to the connection.
If they are not provided an anonymous user is used if write is False.
If write is True user/password are read from the configuration
([aster] section in ~/.gitconfig, option rex-write-user/rex-write-password)."""
if not user: if not user:
user = os.environ.get("REX_USERNAME", "readonly") user = os.environ.get("REX_USERNAME", "readonly")
if write: if write:
...@@ -63,6 +60,18 @@ def _get_connection(user=None, password="", write=False, debug=False): ...@@ -63,6 +60,18 @@ def _get_connection(user=None, password="", write=False, debug=False):
"Valid REX credentials are required. " "Valid REX credentials are required. "
"Please define REX_USERNAME and REX_PASSWORD environment variables." "Please define REX_USERNAME and REX_PASSWORD environment variables."
) )
return user, password
def _get_connection(user=None, password="", write=False, debug=False):
"""Return a connection to the Roundup server.
If user/password are provided they are passed to the connection.
If they are not provided an anonymous user is used if write is False.
If write is True user/password are read from the configuration
([aster] section in ~/.gitconfig, option rex-write-user/rex-write-password).
"""
user, password = _get_user_pass(user, password, write)
url = _get_url(user, password, debug) url = _get_url(user, password, debug)
if (sys.version_info.major, sys.version_info.minor) < (3, 5): if (sys.version_info.major, sys.version_info.minor) < (3, 5):
server = xmlrpc.client.ServerProxy(url, allow_none=True) server = xmlrpc.client.ServerProxy(url, allow_none=True)
...@@ -414,15 +423,18 @@ def extract_csv(entity): ...@@ -414,15 +423,18 @@ def extract_csv(entity):
columns = ["id", "username", "realname", "organisation", "address", "roles", "loginaster"] columns = ["id", "username", "realname", "organisation", "address", "roles", "loginaster"]
else: else:
raise ValueError("unsupported entity: {0}".format(entity)) raise ValueError("unsupported entity: {0}".format(entity))
url = ( url = ("{rex_url}/{entity}?@action=export_csv_names{columns}&:pagesize=50&:startwith=0").format(
"{rex_url}/{entity}?@action=export_csv_names" "{columns}" "&:pagesize=50&:startwith=0"
).format(
rex_url=ASCFG.get("rex.url"), rex_url=ASCFG.get("rex.url"),
entity=entity, entity=entity,
columns="&:columns=" + ",".join(columns) if columns else "", columns="&:columns=" + ",".join(columns) if columns else "",
) )
req = request.Request(url)
user, password = _get_user_pass()
base64string = base64.b64encode(bytes(f"{user}:{password}", "ascii"))
req.add_header("Authorization", "Basic {}".format(base64string.decode("utf-8")))
logger.info(_("exporting data as csv...")) logger.info(_("exporting data as csv..."))
req = urlopen(url) resp = request.urlopen(req)
content = req.read() content = resp.read()
logger.debug(_("{:10} bytes downloaded").format(len(content))) logger.debug(_("{:10} bytes downloaded").format(len(content)))
return str(content, "utf-8") return str(content, "utf-8")
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment