def authenticate(self): """ Does authentication """ headers = {'X-Storage-User': self.username, 'X-Storage-Pass': self.api_key, 'Content-Length': '0'} http = httplib2.Http() http.disable_ssl_certificate_validation = True res, content = http.request(self.auth_url, 'GET', headers=headers) response = Response() response.headers = res response.status_code = int(res.status) response.content = content if response.status_code == 401: raise errors.AuthenticationError('Invalid Credentials') response.raise_for_status() try: storage_options = json.loads(response.content)['storage'] except ValueError: raise errors.StorageURLNotFound("Could not parse services JSON.") self.auth_token = response.headers['x-auth-token'] self.storage_url = self.get_storage_url(storage_options) if not self.storage_url: self.storage_url = response.headers['x-storage-url'] if not self.auth_token or not self.storage_url: raise errors.AuthenticationError('Invalid Authentication Response')
def authenticate(self): """ Does authentication """ headers = { 'X-Storage-User': self.username, 'X-Storage-Pass': self.api_key, 'Content-Length': '0' } http = httplib2.Http() http.disable_ssl_certificate_validation = True res, content = http.request(self.auth_url, 'GET', headers=headers) response = Response() response.headers = res response.status_code = int(res.status) response.content = content if response.status_code == 401: raise errors.AuthenticationError('Invalid Credentials') response.raise_for_status() try: storage_options = json.loads(response.content)['storage'] except ValueError: raise errors.StorageURLNotFound("Could not parse services JSON.") self.auth_token = response.headers['x-auth-token'] self.storage_url = self.get_storage_url(storage_options) if not self.storage_url: self.storage_url = response.headers['x-storage-url'] if not self.auth_token or not self.storage_url: raise errors.AuthenticationError('Invalid Authentication Response')
def authenticate(self): """ Does authentication """ headers = { 'X-Storage-User': self.username, 'X-Storage-Pass': self.api_key, 'Content-Length': '0' } response = requests.get(self.auth_url, headers=headers, verify=False) if response.status_code == 401: raise errors.AuthenticationError('Invalid Credentials') response.raise_for_status() try: storage_options = json.loads(response.content)['storage'] except ValueError: raise errors.StorageURLNotFound("Could not parse services JSON.") self.auth_token = response.headers['x-auth-token'] self.storage_url = self.get_storage_url(storage_options) if not self.storage_url: self.storage_url = response.headers['x-storage-url'] if not self.auth_token or not self.storage_url: raise errors.AuthenticationError('Invalid Authentication Response')
def _formatter(res): containers = [] if res.content: items = json.loads(res.content if isinstance(res.content, six.string_types) else res.content.decode('utf8')) for item in items: name = item.get('name', None) containers.append(self.container(name, item)) return containers
def _formatter(res): containers = [] if res.content: items = json.loads(res.content.decode('utf-8')) for item in items: name = item.get('name', None) containers.append(self.container(name, item)) return containers
def _formatter(res): containers = [] if res.content: items = json.loads(res.content) for item in items: name = item.get('name', None) containers.append(self.container(name, item)) return containers
def _formatter(res): objects = {} if res.content: items = json.loads(res.content) for item in items: if 'name' in item: objects[item['name']] = self.storage_object(item['name'], item) elif 'subdir' in item: item['name'] = item['subdir'].rstrip('/') item['content_type'] = 'application/directory' objects[item['name']] = self.storage_object(item['name'], item) return objects.values()
def _formatter(res): objects = {} if res.content: items = json.loads(res.content) for item in items: if "name" in item: objects[item["name"]] = self.client.storage_object(self.container, item["name"], headers=item) elif "subdir" in item: name = item["subdir"].rstrip("/") item["name"] = name item["content_type"] = "application/directory" objects[item["name"]] = self.client.storage_object(self.container, item["name"], headers=item) return objects.values()
def _formatter(res): objects = {} if res.content: items = json.loads(res.content) for item in items: if 'name' in item: objects[item['name']] = self.client.storage_object(self.container, item['name'], headers=item) elif 'subdir' in item: name = item['subdir'].rstrip('/') item['name'] = name item['content_type'] = 'application/directory' objects[item['name']] = self.client.storage_object(self.container, item['name'], headers=item) return objects.values()
def _formatter(res): objects = {} if res.content: items = json.loads(res.content if isinstance(res.content, six.string_types) else res.content.decode('utf8')) for item in items: if 'name' in item: objects[item['name']] = self.storage_object( item['name'], item) elif 'subdir' in item: item['name'] = item['subdir'].rstrip('/') item['content_type'] = 'application/directory' objects[item['name']] = self.storage_object( item['name'], item) return objects.values()
def __init__(self, username, api_key, auth_token=None, bluemix=False, *args, **kwargs): super(Authentication, self).__init__(*args, **kwargs) self.username = username self.api_key = api_key self.auth_token = auth_token if os.getenv('VCAP_SERVICES'): self.bluemix = True # Find the bluemix app name to use as the SL objectstore user VCAP_APPLICATION = os.getenv('VCAP_APPLICATION') decoded_application = json.loads(VCAP_APPLICATION) self.bluemixappname = decoded_application['name'] if self.auth_token: self.authenticated = True
def _formatter(res): objects = {} if res.content: items = json.loads(res.content.decode('utf-8')) for item in items: if 'name' in item: objects[item['name']] = self.client.storage_object( self.container, item['name'], headers=item) elif 'subdir' in item: name = item['subdir'].rstrip('/') item['name'] = name item['content_type'] = 'application/directory' objects[item['name']] = self.client.storage_object( self.container, item['name'], headers=item) return objects.values()
def _formatter(res): objects = {} if res.content: items = json.loads( res.content if isinstance(res.content, six.string_types) else res.content.decode('utf8')) for item in items: if 'name' in item: objects[item['name']] = self.storage_object( item['name'], item) elif 'subdir' in item: item['name'] = item['subdir'].rstrip('/') item['content_type'] = 'application/directory' objects[item['name']] = self.storage_object( item['name'], item) return objects.values()
def _formatter(response): """ Formats search results. """ headers = response.headers content = response.content items = json.loads(content) objs = [] for item in items: if 'type' not in item or item['type'] == 'container': objs.append(self.container(item['name'], headers=item)) elif item['type'] == 'object': obj = self.storage_object(item['container'], item['name'], headers=item) objs.append(obj) count = int(headers.get('x-search-items-count', 0)) total = int(headers.get('x-search-items-total', 0)) return {'count': count, 'total': total, 'results': objs}
def _formatter(response): """ Formats search results. """ headers = response.headers items = json.loads(response.content) objs = [] for item in items: if 'type' not in item or item['type'] == 'container': objs.append(self.container(item['name'], headers=item)) elif item['type'] == 'object': obj = self.storage_object(item['container'], item['name'], headers=item) objs.append(obj) count = int(headers.get('x-search-items-count', 0)) total = int(headers.get('x-search-items-total', 0)) offset = int(headers.get('x-search-items-offset', 0)) return {'count': count, 'total': total, 'offset': offset, 'results': objs}
def _authenticate(self, response): if response.status_code == 401: raise errors.AuthenticationError('Invalid Credentials') response.raise_for_status() try: storage_options = json.loads(response.content)['storage'] except ValueError: raise errors.StorageURLNotFound("Could not parse services JSON.") self.auth_token = response.headers.get('x-auth-token', 'huh?') self.storage_url = self.get_storage_url(storage_options) if not self.storage_url: self.storage_url = response.headers['x-storage-url'] raise errors.StorageURLNotFound("Could not find defined storage URL. Using default.") if not self.auth_token or not self.storage_url: raise errors.AuthenticationError('Invalid Authentication Response')
def _authenticate(self, response): if response.status_code == 401: raise errors.AuthenticationError('Invalid Credentials') response.raise_for_status() try: storage_options = json.loads(response.content)['storage'] except ValueError: raise errors.StorageURLNotFound("Could not parse services JSON.") self.auth_token = response.headers.get('x-auth-token', 'huh?') self.storage_url = self.get_storage_url(storage_options) if not self.storage_url: self.storage_url = response.headers['x-storage-url'] raise errors.StorageURLNotFound( "Could not find defined storage URL. Using default.") if not self.auth_token or not self.storage_url: raise errors.AuthenticationError('Invalid Authentication Response')
def _formatter(response): """ Formats search results. """ headers = response.headers items = json.loads(response.content if isinstance(response.content, six.string_types) else response.content.decode('utf8')) objs = [] for item in items: if 'type' not in item or item['type'] == 'container': objs.append(self.container(item['name'], headers=item)) elif item['type'] == 'object': obj = self.storage_object(item['container'], item['name'], headers=item) objs.append(obj) count = int(headers.get('x-search-items-count', 0)) total = int(headers.get('x-search-items-total', 0)) offset = int(headers.get('x-search-items-offset', 0)) return {'count': count, 'total': total, 'offset': offset, 'results': objs}
def authenticate(self): """ Does authentication """ headers = {'X-Storage-User': self.username, 'X-Storage-Pass': self.api_key, 'Content-Length': '0'} http = httplib2.Http() http.disable_ssl_certificate_validation = True if self.bluemix: userAndPass = b64encode(bytes(self.username + ':' + self.api_key, 'utf-8')).decode("ISO-8859-1") bluemix_headers = {'Authorization': 'Basic %s' % userAndPass} res, content = http.request(self.auth_url + '/' + self.bluemixappname, 'GET', headers=bluemix_headers) else: res, content = http.request(self.auth_url, 'GET', headers=headers) response = Response() response.headers = res response.status_code = int(res.status) response.content = content if response.status_code == 401: raise errors.AuthenticationError('Invalid Credentials') response.raise_for_status() if not self.bluemix: try: storage_options = json.loads(response.content)['storage'] except ValueError: raise errors.StorageURLNotFound("Could not parse " "services JSON.") self.storage_url = self.get_storage_url(storage_options) self.auth_token = response.headers['x-auth-token'] if not self.storage_url: self.storage_url = response.headers['x-storage-url'] if not self.auth_token or not self.storage_url: raise errors.AuthenticationError('Invalid Authentication Response')
def authenticate(self): """ Does authentication """ headers = {'X-Storage-User': self.username, 'X-Storage-Pass': self.api_key, 'Content-Length': '0'} response = requests.get(self.auth_url, headers=headers, verify=False) if response.status_code == 401: raise errors.AuthenticationError('Invalid Credentials') response.raise_for_status() try: storage_options = json.loads(response.content)['storage'] except ValueError: raise errors.StorageURLNotFound("Could not parse services JSON.") self.auth_token = response.headers['x-auth-token'] self.storage_url = self.get_storage_url(storage_options) if not self.storage_url: self.storage_url = response.headers['x-storage-url'] if not self.auth_token or not self.storage_url: raise errors.AuthenticationError('Invalid Authentication Response')
def authenticate(self): """ Does authentication """ headers = {"X-Storage-User": self.username, "X-Storage-Pass": self.api_key, "Content-Length": "0"} response = requests.get(self.auth_url, headers=headers, verify=False) if response.status_code == 401: raise errors.AuthenticationError("Invalid Credentials") response.raise_for_status() try: storage_options = json.loads(response.content)["storage"] except ValueError: raise errors.StorageURLNotFound("Could not parse services JSON.") self.auth_token = response.headers["x-auth-token"] self.storage_url = self.get_storage_url(storage_options) self.auth_headers = {"X-Auth-Token": self.auth_token} if not self.storage_url: self.storage_url = response.headers["x-storage-url"] raise errors.StorageURLNotFound("Could not find defined storage URL. Using default.") if not self.auth_token or not self.storage_url: raise errors.AuthenticationError("Invalid Authentication Response")