Commit 2fa4d761 authored by Joao Pedro Lopes's avatar Joao Pedro Lopes
Browse files

FTS-1735: Use fts3 package version to set the HTTP User-Agent header with client version

  - In addition the User-Agent header will also distinguish if the request was made using the CLI or the python bindings
parent 761037f8
Pipeline #3223883 passed with stage
in 2 minutes and 17 seconds
......@@ -23,7 +23,7 @@ import socket
import sys
from import Context
from fts3 import __version__ as CLIENT_VERSION
......@@ -138,7 +138,8 @@ class Base(object):
raise NotImplementedError('Run method not implemented in %s' % type(self).__name__)
def _create_context(self):
user_agent = "fts-rest-cli/" + CLIENT_VERSION
return Context(
self.options.endpoint, ukey=self.options.ukey, ucert=self.options.ucert, verify=self.options.verify,
access_token=self.options.access_token, capath=self.options.capath
access_token=self.options.access_token, capath=self.options.capath, user_agent=user_agent
......@@ -17,6 +17,8 @@
from datetime import datetime
from M2Crypto import X509, RSA, EVP, BIO
from fts3 import __version__ as CLIENT_VERSION
from M2Crypto.ASN1 import UTC
......@@ -145,11 +147,18 @@ class Context(object):
raise BadEndpoint("%s (%s)" % (self.endpoint, str(e))), None, sys.exc_info()[2]
return endpoint_info
def _set_user_agent(self, user_agent=None):
if user_agent is None:
self.user_agent = 'fts-python-bindings/' + CLIENT_VERSION
self.user_agent = user_agent
def __init__(self, endpoint, ucert=None, ukey=None, verify=True, access_token=None, no_creds=False, capath=None,
request_class=PycurlRequest, connectTimeout=30, timeout=30):
request_class=PycurlRequest, connectTimeout=30, timeout=30, user_agent=None):
self.passwd = None
self.access_method = None
if no_creds:
self.ucert = self.ukey = self.access_token = None
......@@ -180,21 +189,24 @@ class Context(object):
query = '&'.join(map(lambda (k, v): "%s=%s" % (k, urllib.quote(v)), args.iteritems()))
path += '?' + query
return self._requester.method('GET',
"%s/%s" % (self.endpoint, path))
"%s/%s" % (self.endpoint, path),
headers = {'User-Agent': self.user_agent})
def put(self, path, body):
return self._requester.method('PUT',
"%s/%s" % (self.endpoint, path),
body = body, headers = {'User-Agent': self.user_agent})
def delete(self, path):
return self._requester.method('DELETE',
"%s/%s" % (self.endpoint, path))
"%s/%s" % (self.endpoint, path),
headers = {'User-Agent': self.user_agent})
def post_json(self, path, body):
if not isinstance(body, str) and not isinstance(body, unicode):
body = json.dumps(body)
headers = {'Content-Type': 'application/json', 'User-Agent': self.user_agent}
return self._requester.method('POST',
"%s/%s" % (self.endpoint, path),
headers={'Content-Type': 'application/json'})
body = body,
headers = headers)
......@@ -129,7 +129,7 @@ class PycurlRequest(object):
elif method == 'PUT':
self.curl_handle.setopt(pycurl.UPLOAD, True)
_headers = {'Accept': 'application/json', "User-Agent": "fts-rest-client/3.11.0"}
_headers = {'Accept': 'application/json'}
if headers:
if self.access_token:
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment