Commit d8b85266 authored by Idriss Neumann's avatar Idriss Neumann
Browse files

Refactoring: extract utils functions in a new file

parent db16159d
Pipeline #6350 passed with stages
in 2 minutes and 39 seconds
from flask import Flask, request, Response
from flask_restful import Resource, Api, reqparse
from werkzeug.datastructures import FileStorage
from subprocess import check_output
from multiprocessing import Process
import os
import json
import uuid
import markdown
from flask import Flask, request, Response
from flask_restful import Resource, Api, reqparse
from werkzeug.datastructures import FileStorage
from kompose_api_utils import *
app = Flask(__name__)
api = Api(app)
def get_script_output (cmd):
try:
return check_output(cmd, shell=True, text=True)
except:
return check_output(cmd, shell=True, universal_newlines=True)
def is_forbidden (var):
forbidden_chars = ["'" , "\"", "&", ";", "|", "\\"]
return any(char in var for char in forbidden_chars)
def is_not_empty (var):
if (isinstance(var, bool)):
return var
elif (isinstance(var, int)):
return False
empty_chars = ["", "null", "nil", "false", "none"]
return var is not None and not any(c == var.lower() for c in empty_chars)
def is_empty (var):
return not is_not_empty(var)
def is_empty_request_field (name):
body = request.get_json(force=True)
return not name in body or is_empty(body[name])
def get_available_versions(var):
return json.loads(get_script_output("/versions.sh {}".format(var)))
def get_kompose_available_versions():
return get_available_versions("KOMPOSE_VERSION")
def konvert (filename, version, provider, namespace, apply):
return get_script_output("/konvert.sh {} {} {} {} {}".format(filename, version, provider, namespace, apply))
class VersionsApi(Resource):
def get(self):
return {
......
import json
from flask import request
from subprocess import check_output
def get_script_output (cmd):
try:
return check_output(cmd, shell=True, text=True)
except:
return check_output(cmd, shell=True, universal_newlines=True)
def is_forbidden (var):
forbidden_chars = ["'" , "\"", "&", ";", "|", "\\"]
return any(char in var for char in forbidden_chars)
def is_not_empty (var):
if (isinstance(var, bool)):
return var
elif (isinstance(var, int)):
return False
empty_chars = ["", "null", "nil", "false", "none"]
return var is not None and not any(c == var.lower() for c in empty_chars)
def is_empty (var):
return not is_not_empty(var)
def is_empty_request_field (name):
body = request.get_json(force=True)
return not name in body or is_empty(body[name])
def get_available_versions(var):
return json.loads(get_script_output("/versions.sh {}".format(var)))
def get_kompose_available_versions():
return get_available_versions("KOMPOSE_VERSION")
def konvert (filename, version, provider, namespace, apply):
return get_script_output("/konvert.sh {} {} {} {} {}".format(filename, version, provider, namespace, apply))
......@@ -2,7 +2,7 @@ version: "3.3"
services:
kompose-api:
image: comworkio/kompose-api:2.13
image: comworkio/kompose-api:latest
user: root
environment:
- FLASK_RUN_PORT=8072
......
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