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
21 changes: 13 additions & 8 deletions renga/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,24 @@ class APIClient(

__attrs__ = requests.Session.__attrs__ + ['access_token', 'endpoint']

def __init__(self, endpoint, access_token=None, **kwargs):
def __init__(self, endpoint=None, **kwargs):
"""Create a storage client."""
self.endpoint = endpoint
super(APIClient, self).__init__(**kwargs)

if endpoint.startswith('http:'):
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = 'FIXME'
warnings.warn('Using insecure trasnport protocol, use HTTPS')
@property
def endpoint(self):
"""Return endpoint value."""
return getattr(self, '_endpoint', None)

super(APIClient, self).__init__(**kwargs)
@endpoint.setter
def endpoint(self, endpoint):
"""Set and validate endpoint."""
self._endpoint = endpoint

if access_token:
# NOTE used by storage service
self.access_token = access_token
if endpoint is not None and endpoint.startswith('http:'):
os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = 'FIXME'
warnings.warn('Using insecure trasnport protocol, use HTTPS')

def _url(self, url, *args, **kwargs):
"""Format url for endpoint."""
Expand Down
11 changes: 9 additions & 2 deletions renga/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class RengaClient(object):
Example:

>>> import renga
>>> client = renga.RengaClient('http://localhost', '** TOKEN **')
>>> client = renga.RengaClient('http://localhost')

"""

Expand Down Expand Up @@ -59,7 +59,14 @@ def from_env(cls, environment=None):

endpoint = environment.get('RENGA_ENDPOINT', '')
access_token = environment.get('RENGA_ACCESS_TOKEN')
return cls(endpoint=endpoint, token={'access_token': access_token})
client = cls(endpoint=endpoint, token={'access_token': access_token})

# FIXME temporary solution until the execution id is moved to the token
execution_id = environment.get('RENGA_VERTEX_ID')
if execution_id:
client.api.headers['Renga-Deployer-Execution'] = execution_id

return client

@property
def contexts(self):
Expand Down
16 changes: 12 additions & 4 deletions renga/models/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ def open(self, file_name=None, mode='w'):
client = self._client.__class__(
self._client.api.endpoint, token={'access_token': access_token})

if 'Renga-Deployer-Execution' in self._client.api.headers:
client.api.headers[
'Renga-Deployer-Execution'] = self._client.api.headers[
'Renga-Deployer-Execution']

file_handle = {
'resource_id': resp['id'],
'request_type': FileHandle.REQUEST_TYPE[mode],
Expand Down Expand Up @@ -141,6 +146,11 @@ def open(self, mode='r'):
}
token = self._client.api.storage_authorize(**file_handle)
client = self._client.__class__(self._client.api.endpoint, token=token)
if 'Renga-Deployer-Execution' in self._client.api.headers:
client.api.headers[
'Renga-Deployer-Execution'] = self._client.api.headers[
'Renga-Deployer-Execution']

yield FileHandle(file_handle, client=client)


Expand Down Expand Up @@ -169,10 +179,8 @@ def __getitem__(self, resource_id):

def __iter__(self):
"""Return all files in this bucket."""
return (
File(f, client=self._client, collection=self)
for f in self._client.api.get_bucket_files(self.id)
)
return (File(f, client=self._client, collection=self)
for f in self._client.api.get_bucket_files(self.id))

def create(self, file_name=None):
"""Create an empty file in this bucket."""
Expand Down
2 changes: 1 addition & 1 deletion renga/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@

from __future__ import absolute_import, print_function

__version__ = '0.1.0.dev20170914'
__version__ = '0.1.0.dev20170915'