def connect(self, auth_info): rodsUserName = auth_info.username rodsHost = get_config_parameter('RODSHOST') rodsPort = get_config_parameter('RODSPORT') rodsZone = get_config_parameter('RODSZONE') conn, err = rcConnect(rodsHost, rodsPort, rodsUserName, rodsZone ) if err.status != 0: current_app.logger.error('Connecting to iRODS failed %s' % _getErrorName(err.status)) raise InternalException('Connecting to iRODS failed') with suppress_stdout_stderr(): err = clientLoginWithPassword(conn, auth_info.password) if err == 0: current_app.logger.debug('Created a storage connection') self.connection = conn return True else: conn.disconnect() return False
def choose_access_module(): access_module = None if common.request_is_cdmi(): if get_config_parameter('ACTIVATE_CDMI', False): access_module = cdmi else: abort(400) elif common.request_wants_json(): if get_config_parameter('ACTIVATE_JSON', False): access_module = json else: abort(400) else: access_module = noncdmi return access_module
def connect(self, auth_info): rodsUserName = auth_info.username rodsHost = get_config_parameter('RODSHOST') rodsPort = get_config_parameter('RODSPORT') rodsZone = get_config_parameter('RODSZONE') conn, err = rcConnect(rodsHost, rodsPort, rodsUserName, rodsZone) if err.status != 0: current_app.logger.error('Connecting to iRODS failed %s' % _getErrorName(err.status)) raise InternalException('Connecting to iRODS failed') with suppress_stdout_stderr(): err = clientLoginWithPassword(conn, auth_info.password) if err == 0: current_app.logger.debug('Created a storage connection') self.connection = conn return True else: conn.disconnect() return False
def authenticate(auth_info): """Authenticate with username, password. Returns True or False. Don't mistake this for real authentication, please. It just help tests passing. If users are defined in the config, it checks for valid accounts and passwords. Otherwise it allows everyone. """ if auth_info.method == AuthMethod.Pass: current_app.logger.debug('authenticate by PASS: %s' % auth_info.username) if get_config_parameter('USERS') is not None: return (auth_info.username in get_config_parameter('USERS') and (get_config_parameter('USERS')[auth_info.username] == auth_info.password)) else: return True elif auth_info.method == AuthMethod.Gsi: if auth_info.userverifiedok: return True return False
def check_path_with_exported(path): # normpath also removes the trailing slash. # since we hand it through for directories, we have # to make an exception for that. path_end = None if len(path) > 1 and path[-1] == '/': path_end = -1 if os.path.normpath(path) != path[:path_end]: raise MalformedPathException('Malformed path') if any(map(lambda p: path.startswith(p), get_config_parameter('EXPORTEDPATHS'))): return else: raise NotFoundException('No such file or directory')
def check_path_with_exported(path): # normpath also removes the trailing slash. # since we hand it through for directories, we have # to make an exception for that. path_end = None if len(path) > 1 and path[-1] == '/': path_end = -1 if os.path.normpath(path) != path[:path_end]: raise MalformedPathException('Malformed path') if any( map(lambda p: path.startswith(p), get_config_parameter('EXPORTEDPATHS'))): return else: raise NotFoundException('No such file or directory')
def _src_is_local(uri): """Checks if the URI is in the local CDMI domain. This check is broader than normally necessary on purpose, because I am not sure to which values the CDMI domain can and should be set. """ cdmi_domain = get_config_parameter('CDMI_DOMAIN', None) if cdmi_domain is not None: uri_location = urlparse(uri).netloc if cdmi_domain in uri_location: current_app.logger.debug('found this location to be local: %s' % uri_location) return True else: current_app.logger.debug('found this location to be remote: %s' % uri_location) return False current_app.logger.debug('CDMI domain is not set. can\'t find local src.') return False
# -*- coding: utf-8 -*- from __future__ import with_statement from flask import current_app from eudat_http_api.http_storage.common import get_config_parameter if get_config_parameter('STORAGE') == 'local': current_app.logger.debug('using local storage backend') from eudat_http_api.http_storage.localstorage import * elif get_config_parameter('STORAGE') == 'irods': current_app.logger.debug('using irods storage backend') from eudat_http_api.http_storage.irodsstorage import * elif get_config_parameter('STORAGE') == 'dmlite': current_app.logger.debug('using dmlite storage backend') from eudat_http_api.http_storage.dmlitestorage import * else: raise NotImplementedError('%s does not exist' % get_config_parameter('STORAGE'))
def _get_cdmi_json_generator(path, obj_type, **data): base_uri, obj_name = common.split_path(path) meta = metadata.stat(path, user_metadata=True) parent_uri = common.add_trailing_slash(base_uri) current_app.logger.debug('get stat for name, base: %s, %s' % (obj_name, base_uri)) parent_object_id = None try: parent_meta = metadata.get_user_metadata(base_uri, user_metadata=['objectID']) current_app.logger.debug('got parent meta: %s' % parent_meta) parent_object_id = parent_meta.get('objectID', None) except storage.NotFoundException: pass def get_range(range_max, range_tuple=(0, None)): if range_tuple is None: range_start, range_end = 0, None else: range_start, range_end = range_tuple if range_end is None or range_end > range_max: range_end = range_max yield flask_json.dumps('%s-%s' % (range_start, range_end)) def wrap_json_string(gen): yield '"' for part in gen: yield b64encode(part) yield '"' def json_list_gen(iterable, func): yield '[\n' for i, el in enumerate(iterable): if i > 0: yield ',\n "%s"' % func(el) else: yield ' "%s"' % func(el) yield '\n ]' def get_hex_object_id_or_none(meta): user_meta = meta.get('user_metadata', None) if user_meta is not None: obj_id = user_meta.get('objectID', None) if obj_id is not None: # obj_id is already stored in hex return obj_id return None yield ('objectType', lambda x=None: 'application/cdmi-%s' % obj_type) yield ('objectID', lambda x=None: get_hex_object_id_or_none(meta)) yield ('objectName', lambda x=None: obj_name) yield ('parentURI', lambda x=None: parent_uri) yield ('parentID', lambda x=None: parent_object_id) yield ('domainURI', lambda x=None: '/cdmi_domains/%s/' % get_config_parameter('CDMI_DOMAIN', None)) yield ('capabilitiesURI', lambda x=None: '/cdmi_capabilities/%s/' % ('dataobject' if obj_type == 'object' else obj_type)) yield ('completionStatus', lambda x=None: 'Complete') #'percentComplete': '%s', # optional yield ('metadata', lambda x=None: meta['user_metadata']) #'exports': {}, # optional #'snapshots': [], # optional if obj_type == 'container': yield ('childrenrange', partial(get_range, meta.get('children', None))) yield ('children', lambda t=(0, None): json_list_gen( islice(data['dir_listing'], t[0], t[1]), lambda x: x.name)) if obj_type == 'object': yield ('mimetype', lambda x=None: 'mime') yield ('valuerange', partial(get_range, meta['size'])) yield ('valuetransferencoding', lambda x=None: 'base64') yield ('value', lambda x=None: wrap_json_string(data['value_gen']))