Commit 7ec321c4 authored by David Mendez's avatar David Mendez
Browse files

Set host in swagger description from config

parent 14a58681
......@@ -20,7 +20,11 @@ def create_app():
flask_app.config['SQLALCHEMY_DATABASE_URI'] = RUN_CONFIG.get('sql_alchemy').get('database_uri')
flask_app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = RUN_CONFIG.get('sql_alchemy').get('track_modifications')
flask_app.config['SECRET_KEY'] = RUN_CONFIG.get('server_secret_key')
CORS(flask_app)
enable_cors = RUN_CONFIG.get('enable_cors', False)
if enable_cors:
CORS(flask_app)
authorizations = {
'jobKey': {
......
......@@ -246,7 +246,7 @@ def create_params_file(job, input_files_desc):
'inputs': prepare_job_inputs(job, input_files_desc),
'output_dir': get_job_output_dir_path(job),
'status_update_endpoint': {
'url': f'{RUN_CONFIG.get("job_feedback_base_url", "http://127.0.0.1:5000")}'
'url': f'http://{RUN_CONFIG.get("server_public_host")}'
f'{RUN_CONFIG.get("base_path", "")}/status/{job.id}',
'method': 'PATCH'
},
......
......@@ -6,6 +6,8 @@ from pathlib import Path
from flask import Blueprint, jsonify
import yaml
from app.config import RUN_CONFIG
SWAGGER_BLUEPRINT = Blueprint('swagger', __name__)
@SWAGGER_BLUEPRINT.route('/swagger.json')
......@@ -16,4 +18,5 @@ def get_json():
with open(yaml_file_path, 'r') as stream:
swagger_desc = yaml.safe_load(stream)
swagger_desc['host'] = RUN_CONFIG.get('server_public_host')
return jsonify(swagger_desc)
......@@ -71,6 +71,9 @@ except FileNotFoundError:
RUN_CONFIG = yaml.load(raw_config, Loader=yaml.FullLoader)
# Load defaults
if not RUN_CONFIG.get('server_public_host'):
RUN_CONFIG['server_public_host'] = '0.0.0.0:5000'
# Hash keys and passwords
RUN_CONFIG['admin_password'] = hash_secret(RUN_CONFIG.get('admin_password'))
......
---
swagger: "2.0"
swagger: '2.0'
info:
description: "This is a sample Petstore server. You can find \nout more about Swagger\
\ at \n[http://swagger.io](http://swagger.io) or on \n[irc.freenode.net, #swagger](http://swagger.io/irc/).\n"
version: "1.0.0"
title: "Swagger Petstore"
termsOfService: "http://swagger.io/terms/"
description: 'API that runs jobs using the LSF Cluster'
version: '1.0.0'
title: 'Delayed Jobs API'
contact:
email: "apiteam@swagger.io"
email: 'chembl-help@ebi.ac.uk'
license:
name: "Apache 2.0"
url: "http://www.apache.org/licenses/LICENSE-2.0.html"
host: "virtserver.swaggerhub.com"
#host: Will be set dynamically by Swagger Description Blueprint
basePath: "/nclopezo/DelayedJobs/1.0.0"
tags:
- name: "pet"
......@@ -21,11 +19,6 @@ tags:
url: "http://swagger.io"
- name: "store"
description: "Access to Petstore orders"
- name: "user"
description: "Operations about user"
externalDocs:
description: "Find out more about our store"
url: "http://swagger.io"
schemes:
- "https"
- "http"
......@@ -389,195 +382,6 @@ paths:
"404":
description: "Order not found"
x-swagger-router-controller: "swagger_server.controllers.store_controller"
/user:
post:
tags:
- "user"
summary: "Create user"
description: "This can only be done by the logged in user."
operationId: "create_user"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "Created user object"
required: true
schema:
$ref: "#/definitions/User"
responses:
default:
description: "successful operation"
x-swagger-router-controller: "swagger_server.controllers.user_controller"
/user/createWithArray:
post:
tags:
- "user"
summary: "Creates list of users with given input array"
operationId: "create_users_with_array_input"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "List of user object"
required: true
schema:
type: "array"
items:
$ref: "#/definitions/User"
responses:
default:
description: "successful operation"
x-swagger-router-controller: "swagger_server.controllers.user_controller"
/user/createWithList:
post:
tags:
- "user"
summary: "Creates list of users with given input array"
operationId: "create_users_with_list_input"
produces:
- "application/json"
- "application/xml"
parameters:
- in: "body"
name: "body"
description: "List of user object"
required: true
schema:
type: "array"
items:
$ref: "#/definitions/User"
responses:
default:
description: "successful operation"
x-swagger-router-controller: "swagger_server.controllers.user_controller"
/user/login:
get:
tags:
- "user"
summary: "Logs user into the system"
operationId: "login_user"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "query"
description: "The user name for login"
required: true
type: "string"
- name: "password"
in: "query"
description: "The password for login in clear text"
required: true
type: "string"
responses:
"200":
description: "successful operation"
headers:
X-Rate-Limit:
type: "integer"
format: "int32"
description: "calls per hour allowed by the user"
X-Expires-After:
type: "string"
format: "date-time"
description: "date in UTC when token expires"
schema:
type: "string"
"400":
description: "Invalid username/password supplied"
x-swagger-router-controller: "swagger_server.controllers.user_controller"
/user/logout:
get:
tags:
- "user"
summary: "Logs out current logged in user session"
operationId: "logout_user"
produces:
- "application/json"
- "application/xml"
parameters: []
responses:
default:
description: "successful operation"
x-swagger-router-controller: "swagger_server.controllers.user_controller"
/user/{username}:
get:
tags:
- "user"
summary: "Get user by user name"
operationId: "get_user_by_name"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "path"
description: "The name that needs to be fetched. Use user1 for testing."
required: true
type: "string"
responses:
"200":
description: "successful operation"
schema:
$ref: "#/definitions/User"
"400":
description: "Invalid username supplied"
"404":
description: "User not found"
x-swagger-router-controller: "swagger_server.controllers.user_controller"
put:
tags:
- "user"
summary: "Updated user"
description: "This can only be done by the logged in user."
operationId: "update_user"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "path"
description: "name that need to be updated"
required: true
type: "string"
- in: "body"
name: "body"
description: "Updated user object"
required: true
schema:
$ref: "#/definitions/User"
responses:
"400":
description: "Invalid user supplied"
"404":
description: "User not found"
x-swagger-router-controller: "swagger_server.controllers.user_controller"
delete:
tags:
- "user"
summary: "Delete user"
description: "This can only be done by the logged in user."
operationId: "delete_user"
produces:
- "application/json"
- "application/xml"
parameters:
- name: "username"
in: "path"
description: "The name that needs to be deleted"
required: true
type: "string"
responses:
"400":
description: "Invalid username supplied"
"404":
description: "User not found"
x-swagger-router-controller: "swagger_server.controllers.user_controller"
securityDefinitions:
petstore_auth:
type: "oauth2"
......@@ -638,39 +442,6 @@ definitions:
example:
name: "name"
id: 6
User:
type: "object"
properties:
id:
type: "integer"
format: "int64"
username:
type: "string"
firstName:
type: "string"
lastName:
type: "string"
email:
type: "string"
password:
type: "string"
phone:
type: "string"
userStatus:
type: "integer"
format: "int32"
description: "User Status"
xml:
name: "User"
example:
firstName: "firstName"
lastName: "lastName"
password: "password"
userStatus: 6
phone: "phone"
id: 0
email: "email"
username: "username"
Tag:
type: "object"
properties:
......@@ -750,6 +521,3 @@ definitions:
code: 0
type: "type"
message: "message"
externalDocs:
description: "Find out more about Swagger"
url: "http://swagger.io"
......@@ -10,5 +10,6 @@ jobs_run_dir: 'Where the job runs'
jobs_scripts_dir: 'Where the job scripts are'
run_jobs: False # If False, do not actually run any job, useful for testing. Assumed to be true if missing.
logger: 'gunicorn.error' #Logger to use for the app logs
job_feedback_base_url: http://some_server:30001 # The base url for the jobs to send feedback to the server, if unset,
# it will be http://0.0.0.0:5000/
\ No newline at end of file
server_public_host: some_server:30001 # The base url for the jobs to send feedback to the server, if unset,
# it will be 0.0.0.0:5000
enable_cors: True
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment