commit
5b71145f17
|
@ -32,7 +32,7 @@ def add_resources():
|
|||
DashboardListResource,
|
||||
DashboardWidgetResource,
|
||||
DashboardWidgetListResource)
|
||||
from .resources.app import MqttConfigResource
|
||||
from .resources.app import MqttConfigResource, AppConfigResource
|
||||
|
||||
api.add_resource(AccountResource, '/v1/accounts/<int:account_id>')
|
||||
api.add_resource(AccountListResource, '/v1/accounts')
|
||||
|
@ -74,6 +74,7 @@ def add_resources():
|
|||
api.add_resource(DashboardWidgetListResource,
|
||||
'/v1/dashboards/<int:dashboard_id>/widgets')
|
||||
api.add_resource(MqttConfigResource, '/v1/config/mqtt')
|
||||
api.add_resource(AppConfigResource, '/v1/config')
|
||||
|
||||
|
||||
add_resources()
|
||||
|
|
|
@ -29,6 +29,38 @@ class MqttConfigSchema(BaseResourceSchema):
|
|||
endpoints = fields.Nested(BasicMqttEndpointSchema, many=True)
|
||||
|
||||
|
||||
class BasicVersionInfoSchema(Schema):
|
||||
name = fields.String()
|
||||
build_number = fields.String()
|
||||
|
||||
|
||||
class VersionInfoSchema(BaseResourceSchema, BasicVersionInfoSchema):
|
||||
pass
|
||||
|
||||
|
||||
class BasicFrontendInfoSchema(Schema):
|
||||
url = fields.String()
|
||||
|
||||
|
||||
class FrontendInfoSchema(BaseResourceSchema, BasicFrontendInfoSchema):
|
||||
pass
|
||||
|
||||
|
||||
class BasicEmailInfoSchema(Schema):
|
||||
mailer_account = fields.String()
|
||||
contact_accounts = fields.List(fields.String, many=True)
|
||||
|
||||
|
||||
class EmailInfoSchema(BaseResourceSchema, BasicEmailInfoSchema):
|
||||
pass
|
||||
|
||||
|
||||
class AppConfigSchema(BaseResourceSchema):
|
||||
version = fields.Nested(BasicVersionInfoSchema)
|
||||
frontend = fields.Nested(BasicFrontendInfoSchema)
|
||||
email = fields.Nested(BasicEmailInfoSchema)
|
||||
|
||||
|
||||
def get_mqtt_broker_info(config):
|
||||
return {
|
||||
'url': config['MQTT_BROKER_URL'],
|
||||
|
@ -68,6 +100,26 @@ def get_mqtt_endpoints(config):
|
|||
]
|
||||
|
||||
|
||||
def get_app_version_info(config):
|
||||
return {
|
||||
'name': config['APP_VERSION'],
|
||||
'build_number': config['APP_RELEASE_VERSION_STRING']
|
||||
}
|
||||
|
||||
|
||||
def get_frontend_info(config):
|
||||
return {
|
||||
'url': config['FRONTEND_URL']
|
||||
}
|
||||
|
||||
|
||||
def get_email_info(config):
|
||||
return {
|
||||
'mailer_account': config['MAIL_DEFAULT_SENDER'],
|
||||
'contact_accounts': config['MAIL_CONTACT_ACCOUNTS']
|
||||
}
|
||||
|
||||
|
||||
class MqttConfigResource(ProtectedResource):
|
||||
@swag_from('swagger/get_mqtt_config_spec.yaml')
|
||||
def get(self):
|
||||
|
@ -75,3 +127,13 @@ class MqttConfigResource(ProtectedResource):
|
|||
'broker': get_mqtt_broker_info(app.config),
|
||||
'endpoints': get_mqtt_endpoints(app.config)
|
||||
}), 200
|
||||
|
||||
|
||||
class AppConfigResource(ProtectedResource):
|
||||
@swag_from('swagger/get_app_config_spec.yaml')
|
||||
def get(self):
|
||||
return AppConfigSchema().dump({
|
||||
'version': get_app_version_info(app.config),
|
||||
'frontend': get_frontend_info(app.config),
|
||||
'email': get_email_info(app.config)
|
||||
}), 200
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
Gets server app configuration and description
|
||||
---
|
||||
tags:
|
||||
- Config
|
||||
responses:
|
||||
200:
|
||||
description: Success
|
||||
schema:
|
||||
type: object
|
||||
required:
|
||||
- content
|
||||
properties:
|
||||
content:
|
||||
$ref: '#/definitions/AppConfig'
|
|
@ -13,4 +13,3 @@ responses:
|
|||
properties:
|
||||
content:
|
||||
$ref: '#/definitions/MqttConfig'
|
||||
|
||||
|
|
|
@ -328,6 +328,61 @@ definitions:
|
|||
name:
|
||||
ref: '#definitions/genericname'
|
||||
|
||||
VersionInfo:
|
||||
type: object
|
||||
required:
|
||||
- name
|
||||
- build_number
|
||||
properties:
|
||||
name:
|
||||
type: string
|
||||
description: Version name following semantic versioning
|
||||
example: 0.4.3
|
||||
build_number:
|
||||
type: string
|
||||
description: Number of current build/release
|
||||
example: v72
|
||||
|
||||
FrontendInfo:
|
||||
type: object
|
||||
required:
|
||||
- url
|
||||
properties:
|
||||
url:
|
||||
type: string
|
||||
description: URL of frontend used with this backend.
|
||||
example: https://iot-frontend-app.herokuapp.com
|
||||
|
||||
EmailConfigInfo:
|
||||
type: object
|
||||
required:
|
||||
- mailer_account
|
||||
- contact_accounts
|
||||
properties:
|
||||
mailer_account:
|
||||
type: string
|
||||
description: Account used to send emails to users
|
||||
example: final.iot.backend.mailer@gmail.com
|
||||
contact_accounts:
|
||||
type: string
|
||||
description: Emails used to contact developers
|
||||
example: []
|
||||
|
||||
AppConfig:
|
||||
type: object
|
||||
required:
|
||||
- version
|
||||
- frontend
|
||||
- email
|
||||
properties:
|
||||
version:
|
||||
$ref: '#/definitions/VersionInfo'
|
||||
frontend:
|
||||
$ref: '#/definitions/FrontendInfo'
|
||||
email:
|
||||
$ref: '#/definitions/EmailConfigInfo'
|
||||
|
||||
|
||||
MqttBroker:
|
||||
type: object
|
||||
required:
|
||||
|
|
|
@ -3,6 +3,8 @@ import os
|
|||
# App configuration
|
||||
DEBUG = os.environ['DEBUG']
|
||||
APP_VERSION = '0.4.2'
|
||||
APP_RELEASE_VERSION_STRING = (os.environ.get('HEROKU_RELEASE_VERSION')
|
||||
or 'Unknown')
|
||||
|
||||
# Define the application directory
|
||||
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
|
||||
|
@ -56,6 +58,7 @@ MAIL_PASSWORD = os.environ['APP_MAIL_PASSWORD']
|
|||
|
||||
# mail accounts
|
||||
MAIL_DEFAULT_SENDER = 'final.iot.backend.mailer@gmail.com'
|
||||
MAIL_CONTACT_ACCOUNTS = ['esarajcic1@etf.unsa.ba', 'valjic1@etf.unsa.ba']
|
||||
|
||||
# frontend
|
||||
FRONTEND_URL = (os.environ.get('IOT_FRONTEND_URL') or
|
||||
|
|
Loading…
Reference in New Issue