Beispiel #1
0
    def get(self, request):
        """Returns active user allocations on TACC resources

        : returns: {'response': {'active': allocations, 'portal_alloc': settings.PORTAL_ALLOCATION, 'inactive': inactive, 'hosts': hosts}}
        : rtype: dict
        """
        data = get_allocations(request.user.username)

        return JsonResponse({"response": data})
Beispiel #2
0
    def has_required_systems(self):
        systems = self.settings['required_systems']
        if len(systems) == 0:
            return True

        resources = []
        try:
            resources = get_allocations(self.user.username)['hosts'].keys()
            # If the intersection of the set of systems and resources has
            # items, the user has the necessary allocation
            return len(set(systems).intersection(resources)) > 0
        except Exception as e:
            logger.error(e)
            self.fail("We were unable to retrieve your allocations.")
            return False
Beispiel #3
0
    def get(self, request, operation=None, scheme=None, system=None, path='/'):
        try:
            client = request.user.agave_oauth.client
        except AttributeError:
            # Make sure that we only let unauth'd users see public systems
            if next(sys for sys in settings.PORTAL_DATAFILES_STORAGE_SYSTEMS
                    if sys['system'] == system and sys['scheme'] == 'public'):
                client = service_account()
            else:
                return JsonResponse(
                    {'message': 'This data requires authentication to view.'},
                    status=403)
        try:
            METRICS.info("user:{} op:{} api:tapis scheme:{} "
                         "system:{} path:{} filesize:{}".format(
                             request.user.username, operation, scheme, system,
                             path, request.GET.get('length')))
            response = tapis_get_handler(client, scheme, system, path,
                                         operation, **request.GET.dict())

            operation in NOTIFY_ACTIONS and \
                notify(request.user.username, operation, 'success', {'response': response})
        except HTTPError as e:
            error_status = e.response.status_code
            error_json = e.response.json()
            operation in NOTIFY_ACTIONS and notify(request.user.username,
                                                   operation, 'error', {})
            if error_status == 502:
                # In case of 502 determine cause
                system = dict(client.systems.get(systemId=system))
                allocations = get_allocations(request.user.username)

                # If user is missing a non-corral allocation mangle error to a 403
                if not any(
                        system['storage']['host'].endswith(ele)
                        for ele in list(allocations['hosts'].keys()) +
                    ['cloud.corral.tacc.utexas.edu', 'data.tacc.utexas.edu']):
                    e.response.status_code = 403
                    raise e

                # If a user needs to push keys, return a response specifying the system
                error_json['system'] = system
                return JsonResponse(error_json, status=error_status)
            raise e

        return JsonResponse({'data': response})
Beispiel #4
0
def get_user_storage_systems(username, systems):
    """Create list of accessible storage system names for a user

        Returns a list of storage systems a user can access. In
        settings.PORTAL_DATA_DEPOT_LOCAL_STORAGE_SYSTEMS, each system which
        includes an allocation name in the 'requires_allocation' field will
        be displayed if the user has an allocation for that system.

        :param str username: string username to check allocations for
        :param obj systems: systems object from portal settings
        :returns: filtered object of systems to setup for user
    """
    if not username:
        return {}
    try:
        user_allocations = get_allocations(username)
    except Exception:
        user_allocations = get_tas_allocations(username)

    systems_to_configure = {}
    user_resources = []

    try:
        # get list of user's allocation resources
        for alloc in user_allocations['active'] + user_allocations['inactive']:
            for sys in alloc['systems']:
                user_resources.append(sys['allocation']['resource'].lower())

        # return systems on this portal that user has allocations for
        for sys_name, sys_detail in systems.items():
            required_allocation = sys_detail.get('requires_allocation', None)
            if not required_allocation or (required_allocation
                                           and required_allocation
                                           in user_resources):
                systems_to_configure[sys_name] = sys_detail
    except Exception as e:
        # In case of error, return the default storage system
        logger.exception(e)
        default_system = settings.PORTAL_DATA_DEPOT_LOCAL_STORAGE_SYSTEM_DEFAULT
        systems_to_configure = {default_system: systems[default_system]}

    return systems_to_configure
Beispiel #5
0
 def test_force_get_allocations(self, mock_get, mock_idx):
     mock_get.return_value = []
     get_allocations("username", force=True)
     mock_get.assert_called_with("username")
Beispiel #6
0
 def test_allocation_fallback(self, mock_get_alloc, mock_idx):
     mock_idx.from_username.side_effect = NotFoundError
     get_allocations('testuser')
     mock_get_alloc.assert_called_with('testuser')
     mock_idx().save.assert_called_with()
Beispiel #7
0
 def test_checks_allocations(self, mock_idx):
     get_allocations('testuser')
     mock_idx.from_username.assert_called_with('testuser')
Beispiel #8
0
 def process(self):
     self.state = SetupState.PROCESSING
     self.log("Retrieving your allocations")
     # Force allocation retrieval from TAS and refresh elasticsearch
     allocations = get_allocations(self.user.username, force=True)
     self.complete("Allocations retrieved", data=allocations)