From 60d06b257fff390520e3b7ed36d72f6f759dc965 Mon Sep 17 00:00:00 2001 From: vanzhiganov Date: Sun, 12 Jun 2016 01:34:09 +0300 Subject: [PATCH] 66 API --- SWSCloudAPI/API/__init__.py | 2 +- SWSCloudAPI/API/containers.py | 2 +- SWSCloudAPI/API/datacenters.py | 2 +- SWSCloudAPI/API/pricing.py | 2 +- SWSCloudAPI/API/vms.py | 2 +- SWSCloudAPI/application.py | 4 +++- cloud-runserver.py | 2 +- extra/nginx_ssl.conf | 30 +++++++++++++++++++++--------- extra/{uwsgi.ini => uwsgi-web.ini} | 2 +- setup.py | 4 ++-- 10 files changed, 33 insertions(+), 19 deletions(-) rename extra/{uwsgi.ini => uwsgi-web.ini} (89%) diff --git a/SWSCloudAPI/API/__init__.py b/SWSCloudAPI/API/__init__.py index aa67939..1f4ec2c 100644 --- a/SWSCloudAPI/API/__init__.py +++ b/SWSCloudAPI/API/__init__.py @@ -6,7 +6,7 @@ from SWSCloudCore.controllers.users import ControllerAPI from SWSCloudCore.controllers.users import ControllerUsers -api = Blueprint('api', __name__, url_prefix='') +api = Blueprint('api', __name__, url_prefix='/api/v1') auth = HTTPBasicAuth() """ diff --git a/SWSCloudAPI/API/containers.py b/SWSCloudAPI/API/containers.py index cca7826..599509c 100644 --- a/SWSCloudAPI/API/containers.py +++ b/SWSCloudAPI/API/containers.py @@ -13,7 +13,7 @@ from SWSCloudCore.controllers.tasks import ControllerTasks from SWSCloudCore.controllers.containers import ( ControllerContainers, ControllerContainersStatistics, ControllerContainersStatisticsState) -api_v1_containers = Blueprint('containers', __name__, url_prefix='/containers') +api_v1_containers = Blueprint('containers', __name__, url_prefix='/api/v1/containers') @api_v1_containers.route('/', methods=['GET']) diff --git a/SWSCloudAPI/API/datacenters.py b/SWSCloudAPI/API/datacenters.py index 7f980ad..89ed8ce 100644 --- a/SWSCloudAPI/API/datacenters.py +++ b/SWSCloudAPI/API/datacenters.py @@ -5,7 +5,7 @@ from SWSCloudAPI.API import auth from SWSCloudCore.controllers.datacenters import ControllerDataCenters -api_v1_datacenters = Blueprint('datacenters', __name__, url_prefix='/datacenters') +api_v1_datacenters = Blueprint('datacenters', __name__, url_prefix='/api/v1/datacenters') @api_v1_datacenters.route('/', methods=['GET']) diff --git a/SWSCloudAPI/API/pricing.py b/SWSCloudAPI/API/pricing.py index 3f025d0..deb3408 100644 --- a/SWSCloudAPI/API/pricing.py +++ b/SWSCloudAPI/API/pricing.py @@ -4,7 +4,7 @@ from flask import Blueprint, jsonify from SWSCloudAPI.API import auth from SWSCloudCore.controllers.plans import ControllerPlans -api_v1_pricing = Blueprint('pricing', __name__, url_prefix='/pricing') +api_v1_pricing = Blueprint('pricing', __name__, url_prefix='/api/v1/pricing') @api_v1_pricing.route('/pricing/vms/') diff --git a/SWSCloudAPI/API/vms.py b/SWSCloudAPI/API/vms.py index 7544243..77085bb 100644 --- a/SWSCloudAPI/API/vms.py +++ b/SWSCloudAPI/API/vms.py @@ -12,7 +12,7 @@ from SWSCloudCore.controllers.common import ControllerCommon, ControllerMessages from SWSCloudCore.controllers.tasks import ControllerTasks from SWSCloudCore.controllers.vms import ControllerVMS -api_v1_vms = Blueprint('vms', __name__, url_prefix='/vms') +api_v1_vms = Blueprint('vms', __name__, url_prefix='/api/v1/vms') @api_v1_vms.route('/', methods=['GET']) diff --git a/SWSCloudAPI/application.py b/SWSCloudAPI/application.py index 89f5d72..e7398ad 100644 --- a/SWSCloudAPI/application.py +++ b/SWSCloudAPI/application.py @@ -11,7 +11,8 @@ from SWSCloudCore.models import database from SWSCloudCore.config import config app = Flask(__name__) -app.config["APPLICATION_ROOT"] = "/api/v1" +# Думал, что получится сделать автопрефик для всего приложения, но это не сработало +# app.config["APPLICATION_ROOT"] = "/api/v1" # app.config['SERVER_NAME'] = settings.get('Application', 'SERVER_NAME') app.config['DEBUG'] = config.getboolean('Application', 'DEBUG') app.config['SECRET_KEY'] = config.get("Application", "SECRET_KEY") @@ -67,6 +68,7 @@ def before_first_request(): @app.after_request def after_request(response): # TODO: report about access + app.logger.info('') return response diff --git a/cloud-runserver.py b/cloud-runserver.py index fa7280f..3b663e8 100644 --- a/cloud-runserver.py +++ b/cloud-runserver.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # coding: utf-8 -from SWSCloudCore import app +from SWSCloudWeb import app if __name__ == '__main__': app.run(host='0.0.0.0', port=5000, debug=True) diff --git a/extra/nginx_ssl.conf b/extra/nginx_ssl.conf index ad8c86c..9a84515 100644 --- a/extra/nginx_ssl.conf +++ b/extra/nginx_ssl.conf @@ -1,7 +1,7 @@ server { listen 80; server_name gocloud.ru www.gocloud.ru; - rewrite ^(.*)$ https://$server_name$1 permanent; + rewrite ^(.*)$ https://gocloud.ru$1 permanent; } server { @@ -12,23 +12,35 @@ server { error_log /var/log/nginx/gocloud.ru_error.log; ssl on; - ssl_certificate /var/lib/gocloud.ru/control/ssl/1_gocloud.ru_bundle.crt; - ssl_certificate_key /var/lib/gocloud.ru/control/ssl/2_gocloud.ru.key; + ssl_certificate /etc/nginx/ssl/gocloud/1_gocloud.ru_bundle.crt; + ssl_certificate_key /etc/nginx/ssl/gocloud/2_gocloud.ru.key; - ssl_protocols SSLv2 SSLv3 TLSv1; - ssl_ciphers ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP; + #ssl_protocols SSLv2 SSLv3 TLSv1 TLSv1.1 TLSv1.2; + ssl_protocols SSLv2 TLSv1 TLSv1.1 TLSv1.2; + ssl_ciphers 'ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES128-SHA256:DHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4'; + ssl_session_cache builtin:1000 shared:SSL:10m; + ssl_stapling on; + ssl_stapling_verify on; ssl_prefer_server_ciphers on; + location /api/ { + #proxy_pass http://127.0.0.1:5001; + include uwsgi_params; + uwsgi_pass unix:/var/run/sws/gocloud_api.sock; + } + location / { #proxy_pass http://127.0.0.1:5001; include uwsgi_params; - uwsgi_pass unix:/var/run/gocloudru_control.sock; + uwsgi_pass unix:/var/run/sws/gocloud.sock; } - location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|bmp)$ { - root /var/lib/gocloud.ru/control/app; + location ~* ^.+\.(jpg|jpeg|gif|css|png|js|ico|bmp|txt|xml|woff|woff2)$ { + # root /var/lib/gocloud/control/app/static; access_log off; expires 10d; - break; + + include uwsgi_params; + uwsgi_pass unix:/var/run/sws/gocloud.sock; } } diff --git a/extra/uwsgi.ini b/extra/uwsgi-web.ini similarity index 89% rename from extra/uwsgi.ini rename to extra/uwsgi-web.ini index e91f2d4..cfcfdc8 100644 --- a/extra/uwsgi.ini +++ b/extra/uwsgi-web.ini @@ -9,7 +9,7 @@ virtualenv = /home/gocloud/env socket = /var/run/sws/gocloud.sock chmod-socket = 777 -module = SWSCloudCore:app +module = SWSCloudWeb:app master = true processes = 2 diff --git a/setup.py b/setup.py index 34ec412..af4301a 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ setup( 'SWSCloudCore.controllers.kb', 'SWSCloudCore.controllers.payments', 'SWSCloudCore.controllers.plans', - 'SWSCloudCore.controllers.server_api', + 'SWSCloudCore.controllers.ServerAPI', 'SWSCloudCore.controllers.servers', 'SWSCloudCore.controllers.settings', 'SWSCloudCore.controllers.tasks', @@ -38,7 +38,7 @@ setup( 'SWSCloudCore.views.documents', 'SWSCloudCore.views.kb', 'SWSCloudCore.views.payments', - 'SWSCloudCore.views.server_api', + 'SWSCloudCore.views.ServerAPI', 'SWSCloudCore.views.settings', 'SWSCloudCore.views.support', 'SWSCloudCore.views.tasks',