Skip to content

Commit

Permalink
Add Extra Args to CartAPI (#20)
Browse files Browse the repository at this point in the history
This adds optional extra args hash that will be added to the cart
creation document.

Signed-off-by: David Brown <dmlb2000@gmail.com>
  • Loading branch information
dmlb2000 committed Jan 28, 2020
1 parent 9c75267 commit 93fe66c
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pacifica/downloader/cartapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from uuid import uuid4 as uuid
import time
from json import dumps
from json import dumps, loads
from .common import CommonBase


Expand All @@ -24,6 +24,7 @@ class CartAPI(CommonBase):
_port = None
_cart_api_url = None
_auth = None
_extra_args = None

def __init__(self, **kwargs):
"""
Expand Down Expand Up @@ -55,6 +56,7 @@ def __init__(self, **kwargs):
self._cart_api_url = '{}://{}:{}'.format(self._proto, self._addr, self._port)

self._auth = kwargs.get('auth', {})
self._extra_args = kwargs.get('extra_args', {})

LOGGER.debug('CartAPI URL %s auth %s', self._cart_api_url, self._auth)

Expand All @@ -78,11 +80,11 @@ def setup_cart(self, yield_files):
This method returns the full url to the cart created.
"""
cart_url = '{}/{}'.format(self._cart_api_url, uuid())
data = {key: loads(dumps(self._extra_args[key])) for key in self._extra_args.items()}
data['fileids'] = list(yield_files())
resp = self.session.post(
cart_url,
data=dumps({
'fileids': list(yield_files())
}),
data=dumps(data),
headers={'Content-Type': 'application/json'},
**self._auth
)
Expand Down

0 comments on commit 93fe66c

Please sign in to comment.