summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNejc Habjan <hab.nejc@gmail.com>2021-01-31 11:10:41 +0100
committerNejc Habjan <hab.nejc@gmail.com>2021-01-31 17:56:53 +0100
commit4bb201b92ef0dcc14a7a9c83e5600ba5b118fc33 (patch)
treebb6a33482b65595d372f6508974bdee7f45da935
parent48cb89bad043f7e406e2358a20512653fc40556d (diff)
downloadgitlab-4bb201b92ef0dcc14a7a9c83e5600ba5b118fc33.tar.gz
feat(api,cli): make user agent configurable
-rw-r--r--gitlab/__init__.py19
-rw-r--r--gitlab/__version__.py6
-rw-r--r--gitlab/config.py12
-rw-r--r--gitlab/const.py5
-rw-r--r--setup.py2
5 files changed, 35 insertions, 9 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index 98c4144..5cdcef2 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -24,19 +24,20 @@ import requests
import requests.utils
import gitlab.config
+from gitlab.__version__ import (
+ __author__,
+ __copyright__,
+ __email__,
+ __license__,
+ __title__,
+ __version__,
+)
from gitlab.const import * # noqa
from gitlab.exceptions import * # noqa
from gitlab import utils # noqa
from requests_toolbelt.multipart.encoder import MultipartEncoder
-__title__ = "python-gitlab"
-__version__ = "2.6.0"
-__author__ = "Gauvain Pocentek"
-__email__ = "gauvainpocentek@gmail.com"
-__license__ = "LGPL3"
-__copyright__ = "Copyright 2013-2019 Gauvain Pocentek"
-
warnings.filterwarnings("default", category=DeprecationWarning, module="^gitlab")
REDIRECT_MSG = (
@@ -81,6 +82,7 @@ class Gitlab(object):
per_page=None,
pagination=None,
order_by=None,
+ user_agent=USER_AGENT,
):
self._api_version = str(api_version)
@@ -90,7 +92,7 @@ class Gitlab(object):
#: Timeout to use for requests to gitlab server
self.timeout = timeout
#: Headers that will be used in request to GitLab
- self.headers = {"User-Agent": "%s/%s" % (__title__, __version__)}
+ self.headers = {"User-Agent": user_agent}
#: Whether SSL certificates should be validated
self.ssl_verify = ssl_verify
@@ -204,6 +206,7 @@ class Gitlab(object):
per_page=config.per_page,
pagination=config.pagination,
order_by=config.order_by,
+ user_agent=config.user_agent,
)
def auth(self):
diff --git a/gitlab/__version__.py b/gitlab/__version__.py
new file mode 100644
index 0000000..1708233
--- /dev/null
+++ b/gitlab/__version__.py
@@ -0,0 +1,6 @@
+__author__ = "Gauvain Pocentek, python-gitlab team"
+__copyright__ = "Copyright 2013-2019 Gauvain Pocentek, 2019-2021 python-gitlab team"
+__email__ = "gauvainpocentek@gmail.com"
+__license__ = "LGPL3"
+__title__ = "python-gitlab"
+__version__ = "2.6.0"
diff --git a/gitlab/config.py b/gitlab/config.py
index c8ba896..4647d61 100644
--- a/gitlab/config.py
+++ b/gitlab/config.py
@@ -18,6 +18,8 @@
import os
import configparser
+from gitlab.const import USER_AGENT
+
def _env_config():
if "PYTHON_GITLAB_CFG" in os.environ:
@@ -177,3 +179,13 @@ class GitlabConfigParser(object):
self.order_by = self._config.get(self.gitlab_id, "order_by")
except Exception:
pass
+
+ self.user_agent = USER_AGENT
+ try:
+ self.user_agent = self._config.get("global", "user_agent")
+ except Exception:
+ pass
+ try:
+ self.user_agent = self._config.get(self.gitlab_id, "user_agent")
+ except Exception:
+ pass
diff --git a/gitlab/const.py b/gitlab/const.py
index bdd3d73..36e3c1a 100644
--- a/gitlab/const.py
+++ b/gitlab/const.py
@@ -15,6 +15,9 @@
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+from gitlab.__version__ import __title__, __version__
+
+
NO_ACCESS = 0
MINIMAL_ACCESS = 5
GUEST_ACCESS = 10
@@ -51,3 +54,5 @@ SEARCH_SCOPE_GLOBAL_SNIPPET_TITLES = "snippet_titles"
# specific project scope
SEARCH_SCOPE_PROJECT_NOTES = "notes"
+
+USER_AGENT = "{}/{}".format(__title__, __version__)
diff --git a/setup.py b/setup.py
index 816d363..95390a6 100644
--- a/setup.py
+++ b/setup.py
@@ -6,7 +6,7 @@ from setuptools import find_packages
def get_version():
- with open("gitlab/__init__.py") as f:
+ with open("gitlab/__version__.py") as f:
for line in f:
if line.startswith("__version__"):
return eval(line.split("=")[-1])