Merged in feature/app-config (pull request #57)

Add application config endpoint
develop
Ensar Sarajcic 2018-11-04 12:47:50 +00:00
commit 5b71145f17
6 changed files with 136 additions and 2 deletions

View File

@ -32,7 +32,7 @@ def add_resources():
DashboardListResource, DashboardListResource,
DashboardWidgetResource, DashboardWidgetResource,
DashboardWidgetListResource) DashboardWidgetListResource)
from .resources.app import MqttConfigResource from .resources.app import MqttConfigResource, AppConfigResource
api.add_resource(AccountResource, '/v1/accounts/<int:account_id>') api.add_resource(AccountResource, '/v1/accounts/<int:account_id>')
api.add_resource(AccountListResource, '/v1/accounts') api.add_resource(AccountListResource, '/v1/accounts')
@ -74,6 +74,7 @@ def add_resources():
api.add_resource(DashboardWidgetListResource, api.add_resource(DashboardWidgetListResource,
'/v1/dashboards/<int:dashboard_id>/widgets') '/v1/dashboards/<int:dashboard_id>/widgets')
api.add_resource(MqttConfigResource, '/v1/config/mqtt') api.add_resource(MqttConfigResource, '/v1/config/mqtt')
api.add_resource(AppConfigResource, '/v1/config')
add_resources() add_resources()

View File

@ -29,6 +29,38 @@ class MqttConfigSchema(BaseResourceSchema):
endpoints = fields.Nested(BasicMqttEndpointSchema, many=True) 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): def get_mqtt_broker_info(config):
return { return {
'url': config['MQTT_BROKER_URL'], '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): class MqttConfigResource(ProtectedResource):
@swag_from('swagger/get_mqtt_config_spec.yaml') @swag_from('swagger/get_mqtt_config_spec.yaml')
def get(self): def get(self):
@ -75,3 +127,13 @@ class MqttConfigResource(ProtectedResource):
'broker': get_mqtt_broker_info(app.config), 'broker': get_mqtt_broker_info(app.config),
'endpoints': get_mqtt_endpoints(app.config) 'endpoints': get_mqtt_endpoints(app.config)
}), 200 }), 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

View File

@ -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'

View File

@ -13,4 +13,3 @@ responses:
properties: properties:
content: content:
$ref: '#/definitions/MqttConfig' $ref: '#/definitions/MqttConfig'

View File

@ -328,6 +328,61 @@ definitions:
name: name:
ref: '#definitions/genericname' 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: MqttBroker:
type: object type: object
required: required:

View File

@ -3,6 +3,8 @@ import os
# App configuration # App configuration
DEBUG = os.environ['DEBUG'] DEBUG = os.environ['DEBUG']
APP_VERSION = '0.4.2' APP_VERSION = '0.4.2'
APP_RELEASE_VERSION_STRING = (os.environ.get('HEROKU_RELEASE_VERSION')
or 'Unknown')
# Define the application directory # Define the application directory
BASE_DIR = os.path.abspath(os.path.dirname(__file__)) BASE_DIR = os.path.abspath(os.path.dirname(__file__))
@ -56,6 +58,7 @@ MAIL_PASSWORD = os.environ['APP_MAIL_PASSWORD']
# mail accounts # mail accounts
MAIL_DEFAULT_SENDER = 'final.iot.backend.mailer@gmail.com' MAIL_DEFAULT_SENDER = 'final.iot.backend.mailer@gmail.com'
MAIL_CONTACT_ACCOUNTS = ['esarajcic1@etf.unsa.ba', 'valjic1@etf.unsa.ba']
# frontend # frontend
FRONTEND_URL = (os.environ.get('IOT_FRONTEND_URL') or FRONTEND_URL = (os.environ.get('IOT_FRONTEND_URL') or