Commit 89538a0d authored by Idriss Neumann's avatar Idriss Neumann
Browse files

Extract some endpoints in new files

parent d8b85266
Pipeline #6351 passed with stages
in 2 minutes and 42 seconds
......@@ -15,7 +15,7 @@ mirror:
kompose-api-x86:
stage: publish
script:
- setsid ./ci/docker-deliver.sh "kompose-api" "3.0" "x86"
- setsid ./ci/docker-deliver.sh "kompose-api" "3.1" "x86"
only:
refs:
- /^(main.*)$/
......
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 *
from api_manifest import ManifestApi
from api_versions import VersionsApi
from api_doc import DocApi
app = Flask(__name__)
api = Api(app)
class VersionsApi(Resource):
def get(self):
return {
'status': 'ok',
'kompose_versions': get_kompose_available_versions(),
'kubectl_versions': get_available_versions("K8S_VERSION"),
'help': "Go see the documentation here: {}".format(os.environ['KOMPOSE_DOC_URL'])
}
class KomposeApi(Resource):
def get(self):
return {
......@@ -66,28 +59,6 @@ class KomposeApi(Resource):
tmp_file.save(filename)
return Response(konvert(filename, requested_version, provider, namespace, apply), mimetype='application/x-yaml')
class ManifestEndPoint(Resource):
def get(self):
try:
with open(os.environ['MANIFEST_FILE_PATH']) as manifest_file:
manifest = json.load(manifest_file)
return manifest
except IOError as err:
return {
'status': 'error',
'reason': err
}, 500
class DocEndPoint(Resource):
def get(self):
try:
with open(os.environ['README_FILE_PATH'], 'r') as doc:
html = markdown.markdown(doc.read())
return Response(html, mimetype='text/html')
except IOError as err:
return {'status': 'error', 'reason': err}, 500
kompose_routes = ['/', '/v1', '/v1/']
versions_routes = ['/versions', '/versions/', '/v1/versions', '/v1/versions/']
manifest_routes = ['/manifest', '/manifest/', '/v1/manifest', '/v1/manifest/']
......@@ -95,8 +66,8 @@ doc_routes = ['/doc', '/doc/', '/v1/doc', '/v1/doc/']
api.add_resource(KomposeApi, *kompose_routes)
api.add_resource(VersionsApi, *versions_routes)
api.add_resource(ManifestEndPoint, *manifest_routes)
api.add_resource(DocEndPoint, *doc_routes)
api.add_resource(ManifestApi, *manifest_routes)
api.add_resource(DocApi, *doc_routes)
if __name__ == '__main__':
app.run()
import os
import markdown
from flask import Response
from flask_restful import Resource
class DocApi(Resource):
def get(self):
try:
with open(os.environ['README_FILE_PATH'], 'r') as doc:
html = markdown.markdown(doc.read())
return Response(html, mimetype='text/html')
except IOError as err:
return {'status': 'error', 'reason': err}, 500
from flask_restful import Resource
import os
import json
class ManifestApi(Resource):
def get(self):
try:
with open(os.environ['MANIFEST_FILE_PATH']) as manifest_file:
manifest = json.load(manifest_file)
return manifest
except IOError as err:
return 500, {'status': 'error', 'reason': err}
import os
from flask_restful import Resource
from kompose_api_utils import *
class VersionsApi(Resource):
def get(self):
return {
'status': 'ok',
'kompose_versions': get_kompose_available_versions(),
'kubectl_versions': get_available_versions("K8S_VERSION"),
'help': "Go see the documentation here: {}".format(os.environ['KOMPOSE_DOC_URL'])
}
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