
The SSL and websockets ports are related to the Wok server. So create a specific API to care about these information. During the Wok/Kimchi split, these information was wrongly moved to Kimchi plugin, but as it is related to the server it should be on Wok. Signed-off-by: Aline Manera <alinefm@linux.vnet.ibm.com> --- docs/API/config.md | 27 ++++++++++++++++++++++ src/wok/control/config.py | 31 ++++++++++++++++++++++++++ src/wok/model/config.py | 34 ++++++++++++++++++++++++++++ tests/test_api.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 149 insertions(+) create mode 100644 docs/API/config.md create mode 100644 src/wok/control/config.py create mode 100644 src/wok/model/config.py create mode 100644 tests/test_api.py diff --git a/docs/API/config.md b/docs/API/config.md new file mode 100644 index 0000000..c18b605 --- /dev/null +++ b/docs/API/config.md @@ -0,0 +1,27 @@ +## REST API Specification for Config + +### Resource: Config + +**URI:** /config + +Contains information about the application environment and configuration. + +**Methods:** + +* **GET**: Retrieve configuration information + * ssl_port: SSL port to list on + * websockets_port: Port for websocket proxy to listen on + * version: Wok version +* **POST**: *See Task Actions* + +**Actions (POST):** + +*No actions defined* + +#### Examples +GET /config +{ + ssl_port: 8001, + websockets_port: 64667, + version: 2.0 +} diff --git a/src/wok/control/config.py b/src/wok/control/config.py new file mode 100644 index 0000000..c1e5ef0 --- /dev/null +++ b/src/wok/control/config.py @@ -0,0 +1,31 @@ +# +# Project Wok +# +# Copyright IBM, Corp. 2016 +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +from wok.control.base import Resource +from wok.control.utils import UrlSubNode + + +@UrlSubNode("config") +class Config(Resource): + def __init__(self, model, id=None): + super(Config, self).__init__(model, id) + + @property + def data(self): + return self.info diff --git a/src/wok/model/config.py b/src/wok/model/config.py new file mode 100644 index 0000000..d39222a --- /dev/null +++ b/src/wok/model/config.py @@ -0,0 +1,34 @@ +# +# Project Wok +# +# Copyright IBM, Corp. 2016 +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +from wok.config import config as kconfig +from wok.config import get_version + + +class ConfigModel(object): + def __init__(self, **kargs): + pass + + def lookup(self, name): + ssl_port = kconfig.get('server', 'ssl_port') + websockets_port = kconfig.get('server', 'websockets_port') + + return {'ssl_port': ssl_port, + 'websockets_port': websockets_port, + 'version': get_version()} diff --git a/tests/test_api.py b/tests/test_api.py new file mode 100644 index 0000000..39888c8 --- /dev/null +++ b/tests/test_api.py @@ -0,0 +1,57 @@ +# +# Project Wok +# +# Copyright IBM, Corp. 2016 +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +import json +import unittest +from functools import partial + +import utils + + +test_server = None +model = None +host = None +port = None +ssl_port = None + + +def setUpModule(): + global test_server, model, host, port, ssl_port + + utils.patch_auth() + host = '127.0.0.1' + port = utils.get_free_port('http') + ssl_port = utils.get_free_port('https') + test_server = utils.run_server(host, port, ssl_port, test_mode=True) + + +def tearDownModule(): + test_server.stop() + + +class APITests(unittest.TestCase): + + def setUp(self): + self.request = partial(utils.request, host, ssl_port) + + def test_config(self): + resp = self.request('/config').read() + conf = json.loads(resp) + keys = ["ssl_port", "websockets_port", "version"] + self.assertEquals(sorted(keys), sorted(conf.keys())) -- 2.5.0