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/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 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"],