Skip to content

Commit 8cdc676

Browse files
authored
Merge pull request #113 from packethost/add-user-agent
add user-agent headers to client requests
2 parents a99ea66 + d21e81f commit 8cdc676

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ __pycache__/
66
# C extensions
77
*.so
88
.idea/
9+
.vscode/
910

1011
# Distribution / packaging
1112
.Python

packet/baseapi.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import logging
66
import requests
77

8+
from packet import __version__
9+
810

911
class Error(Exception): # pragma: no cover
1012
"""Base exception class for this module"""
@@ -47,12 +49,19 @@ class BaseAPI(object):
4749
Basic api class for
4850
"""
4951

50-
def __init__(self, auth_token, consumer_token):
52+
def __init__(self, auth_token, consumer_token, user_agent=""):
5153
self.auth_token = auth_token
5254
self.consumer_token = consumer_token
5355
self.end_point = "api.packet.net"
56+
self._user_agent_prefix = user_agent
5457
self._log = logging.getLogger(__name__)
5558

59+
@property
60+
def user_agent(self):
61+
return "{}packet-python/{} {}".format(
62+
self._user_agent_prefix, __version__, requests.utils.default_user_agent()
63+
).strip()
64+
5665
def call_api(self, method, type="GET", params=None): # noqa
5766
if params is None:
5867
params = {}
@@ -63,6 +72,7 @@ def call_api(self, method, type="GET", params=None): # noqa
6372
"X-Auth-Token": self.auth_token,
6473
"X-Consumer-Token": self.consumer_token,
6574
"Content-Type": "application/json",
75+
"User-Agent": self.user_agent,
6676
}
6777

6878
# remove token from log

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ def get_version(rel_path):
3838
long_description=long_description,
3939
long_description_content_type="text/markdown",
4040
url="https://github.com/packethost/packet-python",
41-
author="Packet Developers",
41+
author="Equinix Metal Developers",
42+
author_email="[email protected]",
4243
license="LGPL v3",
4344
keywords="packet api client",
4445
packages=["packet"],

0 commit comments

Comments
 (0)