From 5a2c655866279df5547c2d8b8159afeceb285ee9 Mon Sep 17 00:00:00 2001 From: Tommy Carpenter Date: Tue, 20 Mar 2018 21:39:55 -0400 Subject: Small pythonic cleanups Change-Id: I6be2306e8f42694e6fa8b1d37a07e48730b505ef Issue-ID: DCAEGEN2-348 Signed-off-by: Tommy Carpenter --- Changelog.md | 3 + Dockerfile | 5 +- MANIFEST.in | 1 + bin/run.py | 31 --------- config_binding_service/run.py | 33 +++++++++ config_binding_service/swagger.yaml | 100 ++++++++++++++++++++++++++++ config_binding_service/swagger/swagger.yaml | 100 ---------------------------- pom.xml | 2 +- setup.py | 10 ++- 9 files changed, 147 insertions(+), 138 deletions(-) create mode 100644 MANIFEST.in delete mode 100755 bin/run.py create mode 100644 config_binding_service/run.py create mode 100644 config_binding_service/swagger.yaml delete mode 100644 config_binding_service/swagger/swagger.yaml diff --git a/Changelog.md b/Changelog.md index d5078b7..eae83cc 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [2.1.3] +* Small cleanups; move swagger, remove bin, do proper install in Dockerfile + ## [2.1.2] * Log to a file to be picked up by ELK per DCAEGEN2-387 * Logging not totally finished w.r.t. formats, but this at least logs more and gets them into ELK diff --git a/Dockerfile b/Dockerfile index 35b5d52..7ca987f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,11 +3,10 @@ MAINTAINER tommy@research.att.com ADD . /tmp -#need pip > 8 to have internal pypi repo in requirements.txt RUN pip install --upgrade pip -#do the install WORKDIR /tmp -RUN pip install -e . +#do the install +RUN pip install . EXPOSE 10000 diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..ad8b807 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1 @@ +include config_binding_service/swagger.yaml diff --git a/bin/run.py b/bin/run.py deleted file mode 100755 index 99bf1c7..0000000 --- a/bin/run.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python3 - -# ============LICENSE_START======================================================= -# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END========================================================= -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. - -import connexion -from config_binding_service.logging import create_logger, LOGGER - -if __name__ == '__main__': - create_logger() - try: - app = connexion.App(__name__, specification_dir='../config_binding_service/swagger/') - app.add_api('swagger.yaml', arguments={'title': 'Config Binding Service'}) - app.run(host='0.0.0.0', port=10000, debug=False) - except Exception as exc: - LOGGER.error("Fatal error. Could not start webserver due to: %s", exc) diff --git a/config_binding_service/run.py b/config_binding_service/run.py new file mode 100644 index 0000000..476dc87 --- /dev/null +++ b/config_binding_service/run.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python3 + +# ============LICENSE_START======================================================= +# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. + +import connexion +from config_binding_service.logging import create_logger, LOGGER + + +def main(): + """CBS Entrypoint""" + create_logger() + try: + app = connexion.App(__name__, specification_dir='.') + app.add_api('swagger.yaml', arguments={'title': 'Config Binding Service'}) + app.run(host='0.0.0.0', port=10000, debug=False) + except Exception as exc: + LOGGER.error("Fatal error. Could not start webserver due to: %s", exc) diff --git a/config_binding_service/swagger.yaml b/config_binding_service/swagger.yaml new file mode 100644 index 0000000..cfe0944 --- /dev/null +++ b/config_binding_service/swagger.yaml @@ -0,0 +1,100 @@ +# ============LICENSE_START======================================================= +# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. +# ================================================================================ +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============LICENSE_END========================================================= +# +# ECOMP is a trademark and service mark of AT&T Intellectual Property. + + +--- +swagger: "2.0" +info: + version: "2.1.0" + title: "Config Binding Service" +paths: + /service_component/{service_component_name}: + parameters: + - name: "service_component_name" + in: "path" + description: "Service Component Name. service_component_name must be a key in consul." + required: true + type: "string" + get: + description: "Binds the configuration for service_component_name and returns the bound configuration as a JSON" + operationId: "config_binding_service.controller.bind_config_for_scn" + responses: + 200: + description: OK; the bound config is returned as an object + schema: + type: object + 404: + description: there is no configuration in Consul for this component + + /service_component_all/{service_component_name}: + parameters: + - name: "service_component_name" + in: "path" + description: "Service Component Name. service_component_name must be a key in consul." + required: true + type: "string" + get: + description: "Binds the configuration for service_component_name and returns the bound configuration, policies, and any other keys that are in Consul" + operationId: "config_binding_service.controller.bind_all" + responses: + 200: + description: "OK; returns {config : ..., policies : ....., k : ...} for all other k in Consul" + schema: + type: object + 404: + description: there is no configuration in Consul for this component + + /{key}/{service_component_name}: + parameters: + - name: "key" + in: "path" + description: "this endpoint tries to pull service_component_name:key; key is the key after the colon" + required: true + type: "string" + - name: "service_component_name" + in: "path" + description: "Service Component Name." + required: true + type: "string" + get: + description: "this is an endpoint that fetches a generic service_component_name:key out of Consul. The idea is that we don't want to tie components to Consul directly in case we swap out the backend some day, so the CBS abstracts Consul from clients. The structuring and weird collision of this new API with the above is unfortunate but due to legacy concerns." + operationId: "config_binding_service.controller.get_key" + responses: + 200: + description: "OK; returns service_component_name:key" + schema: + type: object + 404: + description: "key does not exist" + schema: + type: string + 400: + description: "bad request. Currently this is only returned on :policies, which is a complex object, and should be gotten through service_component_all" + schema: + type: string + + /healthcheck: + get: + description: "This is the health check endpoint. If this returns a 200, the server is alive and consul can be reached. If not a 200, either dead, or no connection to consul" + operationId: "config_binding_service.controller.healthcheck" + parameters: [] + responses: + 200: + description: Successful response + 503: + description: the config binding service cannot reach Consul diff --git a/config_binding_service/swagger/swagger.yaml b/config_binding_service/swagger/swagger.yaml deleted file mode 100644 index cfe0944..0000000 --- a/config_binding_service/swagger/swagger.yaml +++ /dev/null @@ -1,100 +0,0 @@ -# ============LICENSE_START======================================================= -# Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. -# ================================================================================ -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# ============LICENSE_END========================================================= -# -# ECOMP is a trademark and service mark of AT&T Intellectual Property. - - ---- -swagger: "2.0" -info: - version: "2.1.0" - title: "Config Binding Service" -paths: - /service_component/{service_component_name}: - parameters: - - name: "service_component_name" - in: "path" - description: "Service Component Name. service_component_name must be a key in consul." - required: true - type: "string" - get: - description: "Binds the configuration for service_component_name and returns the bound configuration as a JSON" - operationId: "config_binding_service.controller.bind_config_for_scn" - responses: - 200: - description: OK; the bound config is returned as an object - schema: - type: object - 404: - description: there is no configuration in Consul for this component - - /service_component_all/{service_component_name}: - parameters: - - name: "service_component_name" - in: "path" - description: "Service Component Name. service_component_name must be a key in consul." - required: true - type: "string" - get: - description: "Binds the configuration for service_component_name and returns the bound configuration, policies, and any other keys that are in Consul" - operationId: "config_binding_service.controller.bind_all" - responses: - 200: - description: "OK; returns {config : ..., policies : ....., k : ...} for all other k in Consul" - schema: - type: object - 404: - description: there is no configuration in Consul for this component - - /{key}/{service_component_name}: - parameters: - - name: "key" - in: "path" - description: "this endpoint tries to pull service_component_name:key; key is the key after the colon" - required: true - type: "string" - - name: "service_component_name" - in: "path" - description: "Service Component Name." - required: true - type: "string" - get: - description: "this is an endpoint that fetches a generic service_component_name:key out of Consul. The idea is that we don't want to tie components to Consul directly in case we swap out the backend some day, so the CBS abstracts Consul from clients. The structuring and weird collision of this new API with the above is unfortunate but due to legacy concerns." - operationId: "config_binding_service.controller.get_key" - responses: - 200: - description: "OK; returns service_component_name:key" - schema: - type: object - 404: - description: "key does not exist" - schema: - type: string - 400: - description: "bad request. Currently this is only returned on :policies, which is a complex object, and should be gotten through service_component_all" - schema: - type: string - - /healthcheck: - get: - description: "This is the health check endpoint. If this returns a 200, the server is alive and consul can be reached. If not a 200, either dead, or no connection to consul" - operationId: "config_binding_service.controller.healthcheck" - parameters: [] - responses: - 200: - description: Successful response - 503: - description: the config binding service cannot reach Consul diff --git a/pom.xml b/pom.xml index be2bf32..43ea442 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ ECOMP is a trademark and service mark of AT&T Intellectual Property. org.onap.dcaegen2.platform configbinding dcaegen2-platform-configbinding - 2.1.2 + 2.1.3 http://maven.apache.org UTF-8 diff --git a/setup.py b/setup.py index 55b684c..35aed26 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ from setuptools import setup, find_packages setup( name='config_binding_service', - version='2.1.2', + version='2.1.3', packages=find_packages(exclude=["tests.*", "tests"]), author="Tommy Carpenter", author_email="tommy@research.att.com", @@ -29,6 +29,10 @@ setup( keywords="", url="https://gerrit.onap.org/r/#/admin/projects/dcaegen2/platform/configbinding", zip_safe=False, - scripts=["bin/run.py"], - install_requires=["requests", "Flask", "connexion", "six"] + entry_points={ + 'console_scripts': [ + 'run.py=config_binding_service.run:main'] + }, + install_requires=["requests", "Flask", "connexion", "six"], + include_package_data=True ) -- cgit 1.2.3-korg