Пример #1
0
async def resource_id_subpath_put(resource_type, resource_id, subpath, body: http.Body, headers: http.Headers,
                                  storage: Storage):
    try:
        if storage.is_file(resource_type, subpath):
            content_type = headers.get('Content-Type')
            revision = headers.get('Revision')
            return await storage.put_file(resource_type, resource_id, subpath, body, revision, content_type)
        else:
            data = JSONParser().parse(body)
            return await storage.put_subpath(resource_type, resource_id, subpath, data)
    except ResourceTypeNotFound:
        raise NotFound({
            'error_code': 'ResourceTypeDoesNotExist',
            'resource_type': resource_type,
            'message': 'Resource type does not exist',
        })
    except ResourceNotFound:
        raise NotFound({
            'error_code': 'ItemDoesNotExist',
            'item_id': resource_id,
            'message': "Item does not exist",
        })
    except WrongRevision as e:
        raise Conflict({
            'error_code': 'WrongRevision',
            'item_id': resource_id,
            'current': e.current,
            'update': e.update,
            'message': (
                'Updating resource {item_id} failed: resource currently has revision {current}, update wants to '
                'update {update}.'
            ),
        })
Пример #2
0
#     }
#
#
# env = Env()

settings = {
    'TEMPLATES': {
        'ROOT_DIR': 'templates',
        'PACKAGE_DIRS': ['apistar']
    },
    # "DATABASE": {
    #     "URL": env['DATABASE_URL'],
    #     "METADATA": Base.metadata
    #
    # },
    'PARSERS': [JSONParser()],
    'SCHEMA': {
        'TITLE': 'User Authentication',
        'DESCRIPTION': 'authentication'
    },
    'TOKEN_AUTHENTICATION': {
        'IS_EXPIRY_TOKEN': True,
        'EXPIRY_TIME': 30,
        'USERNAME_FIELD': 'username',
        'PASSWORD_FIELD': 'password',
        'ORM': 'django',
        'USER_MODEL': 'User',
        'TOKEN_MODEL': 'AccessToken'
    }
}
Пример #3
0
    },

    'STATICS': {
        'ROOT_DIR': 'static',         # Include the 'static/' directory.
        'PACKAGE_DIRS': ['apistar'],  # Include the builtin apistar static files
    },

    'TEMPLATES': {
        'ROOT_DIR': 'templates',      # Include the 'templates/' directory.
        'PACKAGE_DIRS': ['apistar'],  # Include the built-in apistar templates.
    },

    'RENDERERS': (JSONRenderer(), MessagePackRenderer()),
    # 'RENDERERS': (JSONRenderer(), MessagePackRenderer(), HTMLRenderer()),

    'PARSERS': (JSONParser(), MultiPartParser(), MessagePackParser()),
    # 'PARSERS': (JSONParser(), MultiPartParser()),  # Default.

    'AUTHENTICATION': (JWTAuthentication(), ),
    'JWT': {  # Do NOT PUSH your SECRET into version control!.
        'SECRET': 's0m3-l0ng-s3cr3t',  # Long randomized secret string key.
        'LEEWAY': 60,  # Seconds of expiration time.
    },  # https://github.com/audiolion/apistar-jwt#usage

    'PERMISSIONS': (
        IsAuthenticated(), IsGuestUser(), IsFreeUser(), IsPremiumUser(),
        IsCompanyUser(), IsAdminUser(), IsTesterUser(), IsStaffUser(),
    ),

    'HUEY': {  # https://huey.readthedocs.io
        'FILENAME': 'huey_tasks_queue.db',  # File for Huey DB.