Commit e5352ec3 authored by Giorgos Korfiatis's avatar Giorgos Korfiatis

Add User-Agent header in pithos requests

parent 607db7e4
......@@ -22,7 +22,7 @@ import stat
from functools import wraps
from agkyra.syncer.utils import join_path, ThreadSafeDict
from agkyra.syncer.utils import join_path, ThreadSafeDict, patch_user_agent
from agkyra.syncer.database import TransactedConnection
from agkyra.syncer.messaging import Messager
from agkyra.syncer import utils, common, database
......@@ -33,6 +33,8 @@ from kamaki.clients.astakos import AstakosClient
from kamaki.clients.pithos import PithosClient
from kamaki.clients.utils import https
AgkyraPithosClient = patch_user_agent(PithosClient)
logger = logging.getLogger(__name__)
......@@ -251,13 +253,14 @@ class SyncerSettings():
logger.error("Failed to authenticate user token")
raise
try:
PITHOS_URL = astakos.get_endpoint_url(PithosClient.service_type)
PITHOS_URL = astakos.get_endpoint_url(
AgkyraPithosClient.service_type)
except ClientError:
logger.error("Failed to get endpoints for Pithos")
raise
try:
account = astakos.user_info['id']
return PithosClient(PITHOS_URL, token, account, container)
return AgkyraPithosClient(PITHOS_URL, token, account, container)
except ClientError:
logger.error("Failed to initialize Pithos client")
raise
......
......@@ -25,6 +25,7 @@ import time
logger = logging.getLogger(__name__)
import agkyra
from agkyra.syncer.common import OBJECT_DIRSEP
ENCODING = sys.getfilesystemencoding() or 'UTF-8'
......@@ -110,6 +111,33 @@ def reg_name(settings, objname):
return objname
def user_agent():
return "agkyra %s" % agkyra.__version__
def patch_request(client_class, headers=None, params=None):
if headers is None:
headers = {}
if params is None:
params = {}
class PatchedClient(client_class):
def request(
self, method, path,
async_headers=dict(), async_params=dict(),
**kwargs):
async_headers.update(headers)
async_params.update(params)
return client_class.request(
self, method, path,
async_headers=async_headers, async_params=async_params,
**kwargs)
return PatchedClient
def patch_user_agent(client_class):
return patch_request(client_class, headers={'User-Agent': user_agent()})
BaseStoppableThread = watchdog.utils.BaseThread
......
Markdown is supported
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