mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-18 08:29:14 +00:00
Add integration with flask
This commit is contained in:
parent
75e3143c82
commit
99beee40d6
|
@ -9,6 +9,8 @@ from flask_restful import Api
|
|||
from flask_swagger import swagger
|
||||
from flask_swagger_ui import get_swaggerui_blueprint
|
||||
|
||||
from strawberry.flask.views import AsyncGraphQLView
|
||||
|
||||
from selfprivacy_api.resources.users import User, Users
|
||||
from selfprivacy_api.resources.common import ApiVersion
|
||||
from selfprivacy_api.resources.system import api_system
|
||||
|
@ -21,6 +23,8 @@ from selfprivacy_api.migrations import run_migrations
|
|||
|
||||
from selfprivacy_api.utils.auth import is_token_valid
|
||||
|
||||
from selfprivacy_api.graphql import schema
|
||||
|
||||
swagger_blueprint = get_swaggerui_blueprint(
|
||||
"/api/docs", "/api/swagger.json", config={"app_name": "SelfPrivacy API"}
|
||||
)
|
||||
|
@ -83,6 +87,13 @@ def create_app(test_config=None):
|
|||
return jsonify(swag)
|
||||
return jsonify({}), 404
|
||||
|
||||
app.add_url_rule(
|
||||
"/graphql",
|
||||
view_func=AsyncGraphQLView.as_view(
|
||||
"graphql", shema=schema
|
||||
)
|
||||
)
|
||||
|
||||
if app.config["ENABLE_SWAGGER"] == "1":
|
||||
app.register_blueprint(swagger_blueprint, url_prefix="/api/docs")
|
||||
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
"""GraphQL API for SelfPrivacy."""
|
||||
# pylint: disable=too-few-public-methods
|
||||
import typing
|
||||
import strawberry
|
||||
|
||||
from selfprivacy_api.graphql.queries.system import System
|
||||
from selfprivacy_api.graphql.queries.api import Api
|
||||
|
||||
@strawberry.type
|
||||
class Query:
|
||||
"""Root schema for queries"""
|
||||
system: System
|
||||
api: Api
|
||||
|
||||
schema = strawberry.Schema(query=Query)
|
|
@ -1,9 +1,12 @@
|
|||
"""API access status"""
|
||||
# pylint: disable=too-few-public-methods
|
||||
import datetime
|
||||
import string
|
||||
import typing
|
||||
import strawberry
|
||||
|
||||
from selfprivacy_api.resolvers.api import get_api_version
|
||||
|
||||
@strawberry.type
|
||||
class ApiDevice:
|
||||
name: str
|
||||
|
@ -20,6 +23,6 @@ class ApiRecoveryKeyStatus:
|
|||
|
||||
@strawberry.type
|
||||
class Api:
|
||||
version: str
|
||||
version: str = strawberry.field(resolver=get_api_version)
|
||||
devices: typing.List[ApiDevice]
|
||||
recovery_key: ApiRecoveryKeyStatus
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
"""Common system information and settings"""
|
||||
# pylint: disable=too-few-public-methods
|
||||
import typing
|
||||
import strawberry
|
||||
|
||||
|
@ -6,6 +8,7 @@ from selfprivacy_api.graphql.queries.providers import DnsProvider, ServerProvide
|
|||
|
||||
@strawberry.type
|
||||
class DnsRecord:
|
||||
"""DNS record"""
|
||||
recordType: str
|
||||
name: str
|
||||
content: str
|
||||
|
@ -14,6 +17,7 @@ class DnsRecord:
|
|||
|
||||
@strawberry.type
|
||||
class SystemDomainInfo:
|
||||
"""Information about the system domain"""
|
||||
domain: str
|
||||
hostname: str
|
||||
provider: DnsProvider
|
||||
|
@ -21,28 +25,33 @@ class SystemDomainInfo:
|
|||
|
||||
@strawberry.type
|
||||
class AutoUpgradeOptions:
|
||||
"""Automatic upgrade options"""
|
||||
enable: bool
|
||||
allow_reboot: bool
|
||||
|
||||
@strawberry.type
|
||||
class SshSettings:
|
||||
"""SSH settings and root SSH keys"""
|
||||
enable: bool
|
||||
password_authentication: bool
|
||||
root_ssh_keys: typing.List[str]
|
||||
|
||||
@strawberry.type
|
||||
class SystemSettings:
|
||||
"""Common system settings"""
|
||||
auto_upgrade: AutoUpgradeOptions
|
||||
ssh: SshSettings
|
||||
timezone: str
|
||||
|
||||
@strawberry.type
|
||||
class SystemInfo:
|
||||
"""System components versions"""
|
||||
system_version: str
|
||||
python_version: str
|
||||
|
||||
@strawberry.type
|
||||
class SystemProviderInfo:
|
||||
"""Information about the VPS/Dedicated server provider"""
|
||||
provider: ServerProvider
|
||||
id: str
|
||||
|
||||
|
@ -56,4 +65,4 @@ class System:
|
|||
settings: SystemSettings
|
||||
info: SystemInfo
|
||||
provider: SystemProviderInfo
|
||||
busy: bool
|
||||
busy: bool
|
||||
|
|
5
selfprivacy_api/resolvers/api.py
Normal file
5
selfprivacy_api/resolvers/api.py
Normal file
|
@ -0,0 +1,5 @@
|
|||
"""Resolvers for API module"""
|
||||
|
||||
def get_api_version() -> str:
|
||||
"""Get API version"""
|
||||
return "1.2.7"
|
|
@ -1,7 +1,7 @@
|
|||
#!/usr/bin/env python3
|
||||
"""Unassigned views"""
|
||||
from flask_restful import Resource
|
||||
|
||||
from selfprivacy_api.resolvers.api import get_api_version
|
||||
|
||||
class ApiVersion(Resource):
|
||||
"""SelfPrivacy API version"""
|
||||
|
@ -23,4 +23,4 @@ class ApiVersion(Resource):
|
|||
401:
|
||||
description: Unauthorized
|
||||
"""
|
||||
return {"version": "1.2.7"}
|
||||
return {"version": get_api_version()}
|
||||
|
|
Loading…
Reference in a new issue