How to use the ckanapi.errors.NotAuthorized function in ckanapi

To help you get started, we’ve selected a few ckanapi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ckan / ckanapi / ckanapi / common.py View on Github external
etype = err.get('__type')
    emessage = err.get('message', '').split(': ', 1)[-1]
    if etype == 'Search Query Error':
        # I refuse to eval(emessage), even if it would be more correct
        raise SearchQueryError(emessage)
    elif etype == 'Search Error':
        # I refuse to eval(emessage), even if it would be more correct
        raise SearchError(emessage)
    elif etype == 'Search Index Error':
        raise SearchIndexError(emessage)
    elif etype == 'Validation Error':
        raise ValidationError(err)
    elif etype == 'Not Found Error':
        raise NotFound(emessage)
    elif etype == 'Authorization Error':
        raise NotAuthorized(err)

    # don't recognize the error
    raise CKANAPIError(repr([url, status, response]))
github ckan / ckanapi / ckanapi / cli / dump.py View on Github external
name = json.loads(line.decode('utf-8'))
        except UnicodeDecodeError as e:
            reply('UnicodeDecodeError')
            continue

        try:
            requests_kwargs = None
            if arguments['--insecure']:
                requests_kwargs = {'verify': False}
            obj = ckan.call_action(thing_show, {'id': name,
                'include_datasets': False,
                'include_password_hash': True,
                }, requests_kwargs=requests_kwargs)
        except NotFound:
            reply('NotFound')
        except NotAuthorized:
            reply('NotAuthorized')
        else:
            if thing == 'datasets' and arguments['--datastore-fields']:
                for res in obj.get('resources', []):
                    populate_datastore_res_fields(ckan, res)
            reply(None, obj)
github ckan / ckanapi / ckanapi / cli / load.py View on Github external
r = ckan.call_action(thing_create, obj)
                if thing == 'datasets' and 'resources' in obj:# check if it is needed to upload resources when creating/updating packages
                    _upload_resources(ckan,obj,arguments)
                elif thing in ['groups','organizations'] and 'image_display_url' in obj:   #load images for groups and organizations
                    if arguments['--upload-logo']:
                        users = obj['users']
                        _upload_logo(ckan,obj)
                        obj.pop('image_upload')
                        obj['users'] = users
                        ckan.call_action(thing_update, obj,
                                         requests_kwargs=requests_kwargs)
            except ValidationError as e:
                reply(act, 'ValidationError', e.error_dict)
            except SearchIndexError as e:
                reply(act, 'SearchIndexError', unicode(e))
            except NotAuthorized as e:
                reply(act, 'NotAuthorized', unicode(e))
            except NotFound:
                reply(act, 'NotFound', obj)
            else:
                reply(act, None, r.get('name',r.get('id')))
github ckan / ckanapi / ckanapi / cli / delete.py View on Github external
stdout.flush()

    for line in iter(stdin.readline, b''):
        try:
            name = json.loads(line.decode('utf-8'))
        except UnicodeDecodeError as e:
            reply('UnicodeDecodeError', unicode(e))
            continue

        try:
            requests_kwargs = None
            if arguments['--insecure']:
                requests_kwargs = {'verify': False}
            ckan.call_action(thing_delete, {'id': name},
                             requests_kwargs=requests_kwargs)
        except NotAuthorized as e:
            reply('NotAuthorized', unicode(e))
        except NotFound:
            reply('NotFound', name)
        else:
            reply(None, name)