From 3df8cdb4d291cfe58dcca411c67189aa25e1ba15 Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Tue, 24 Nov 2020 11:33:14 -0500 Subject: [PATCH 1/2] add user-agent headers to client requests Signed-off-by: Marques Johansson --- packet/baseapi.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packet/baseapi.py b/packet/baseapi.py index 505312a..5a2809d 100644 --- a/packet/baseapi.py +++ b/packet/baseapi.py @@ -5,6 +5,8 @@ import logging import requests +from packet import __version__ + class Error(Exception): # pragma: no cover """Base exception class for this module""" @@ -47,12 +49,19 @@ class BaseAPI(object): Basic api class for """ - def __init__(self, auth_token, consumer_token): + def __init__(self, auth_token, consumer_token, user_agent=""): self.auth_token = auth_token self.consumer_token = consumer_token self.end_point = "api.packet.net" + self._user_agent_prefix = user_agent self._log = logging.getLogger(__name__) + @property + def user_agent(self): + return "{}packet-python/{} {}".format( + self._user_agent_prefix, __version__, requests.utils.default_user_agent() + ).strip() + def call_api(self, method, type="GET", params=None): # noqa if params is None: params = {} @@ -63,6 +72,7 @@ def call_api(self, method, type="GET", params=None): # noqa "X-Auth-Token": self.auth_token, "X-Consumer-Token": self.consumer_token, "Content-Type": "application/json", + "User-Agent": self.user_agent, } # remove token from log From d21e81fd9eeec1218e2a7e64a54b38671b1a6114 Mon Sep 17 00:00:00 2001 From: Marques Johansson Date: Wed, 19 May 2021 21:11:17 -0400 Subject: [PATCH 2/2] define author_email in setup.py (per ./setup.py check) Signed-off-by: Marques Johansson --- .gitignore | 1 + setup.py | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 612d8fd..2d55625 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ __pycache__/ # C extensions *.so .idea/ +.vscode/ # Distribution / packaging .Python diff --git a/setup.py b/setup.py index 8d0d788..563b6c9 100755 --- a/setup.py +++ b/setup.py @@ -38,7 +38,8 @@ def get_version(rel_path): long_description=long_description, long_description_content_type="text/markdown", url="https://github.com/packethost/packet-python", - author="Packet Developers", + author="Equinix Metal Developers", + author_email="support@equinixmetal.com", license="LGPL v3", keywords="packet api client", packages=["packet"],