Index: cloud_sync.py =================================================================== diff -u -r5e2872a15167f8d66d074d106f3afc78d1da3dea -r3b80d8631090f72584ae2a309efcea2d20b4f62e --- cloud_sync.py (.../cloud_sync.py) (revision 5e2872a15167f8d66d074d106f3afc78d1da3dea) +++ cloud_sync.py (.../cloud_sync.py) (revision 3b80d8631090f72584ae2a309efcea2d20b4f62e) @@ -1,3 +1,5 @@ +"""Implementation of CloudSync controller""" + import argparse import logging import socket @@ -15,12 +17,11 @@ from cloudsync.busses.file_input_bus import FileInputBus from cloudsync.utils.heartbeat import HeartBeatProvider -VERSION = "0.2.3" +VERSION = "0.2.4" arguments = sys.argv log_level = int(arguments[1]) - logging.basicConfig(filename='cloudsync.log', level=log_level) app = Flask(__name__) @@ -69,12 +70,12 @@ @api.route("/version") class Version(Resource): - @api.response(200, "Success") + @api.response(OK, "Success") def get(self): app.logger.info("Received /version HTTP request") return { "version": VERSION - }, 200 + }, OK @api.route("/credentials") @@ -87,8 +88,8 @@ }) @api.doc(body=FIELD_CREDENTIALS, validate=True) - @api.response(200, "Success") - @api.response(400, "Validation Error") + @api.response(OK, "Success") + @api.response(BAD_REQUEST, "Validation Error") def put(self): """ 4. Update the device's certificate and keys @@ -107,7 +108,7 @@ if public_key is None: invalid_params.append("public_key") if len(invalid_params) > 0: - return {"invalidAttributes": invalid_params}, 400 + return {"invalidAttributes": invalid_params}, BAD_REQUEST r = NetworkRequest(request_type=NetworkRequestType.MFT2CS_REQ_SET_CREDENTIALS, url=request.url, @@ -119,13 +120,13 @@ return { "invalidAttributes": [], - }, 200 + }, OK @api.route("/validate") class Validate(Resource): - @api.response(200, "Success") + @api.response(OK, "Success") def head(self): """ 5. Initiate device connectivity test @@ -142,13 +143,13 @@ network_request_handler.enqueue_request(r) # no body is returned - return {}, 200 + return {}, OK @api.route("/reset") class Reset(Resource): - @api.response(200, "Success") + @api.response(OK, "Success") def head(self): """ 13. Initiate a factory reset @@ -168,32 +169,32 @@ heartbeat_provider.send_heartbeat = True - return {}, 200 + return {}, OK # END - REGISTRATION ENDPOINTS @api.route("/config") class Config(Resource): - @api.response(200, "Success") + @api.response(OK, "Success") def get(self): """ Get the current json config """ app.logger.info("Received /config HTTP request") - return g_config, 200 + return g_config, OK @api.route("/token") class Config(Resource): - @api.response(200, "Success") + @api.response(OK, "Success") def get(self): """ Get the currently stored token """ app.logger.info("Received /token HTTP request") - return helpers_read_access_token(DEVICE_KEBORMED_ACCESS_TOKEN_PATH), 200 + return helpers_read_access_token(DEVICE_KEBORMED_ACCESS_TOKEN_PATH), OK @api.route("/logs")