Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ __pycache__/
# C extensions
*.so
.idea/
.vscode/

# Distribution / packaging
.Python
Expand Down
12 changes: 11 additions & 1 deletion packet/baseapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import logging
import requests

from packet import __version__


class Error(Exception): # pragma: no cover
"""Base exception class for this module"""
Expand Down Expand Up @@ -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 = {}
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down