This repository has been archived by the owner on Sep 22, 2020. It is now read-only.
/
api.py
76 lines (52 loc) · 1.96 KB
/
api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Copyright 2015 elastic-search-api authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
import json
import os
import requests
from flask import Flask, request
from flask.ext.basicauth import BasicAuth
app = Flask(__name__)
app.config['BASIC_AUTH_USERNAME'] = os.environ.get("ES_BROKER_USERNAME", 'admin')
app.config['BASIC_AUTH_PASSWORD'] = os.environ.get("ES_BROKER_PASSWORD", 'password')
basic_auth = BasicAuth(app)
app.config['BASIC_AUTH_FORCE'] = True
ELASTICSEARCH_HOST = os.environ.get("ELASTICSEARCH_HOST")
ELASTICSEARCH_PORT = os.environ.get("ELASTICSEARCH_PORT", '9200')
@app.route("/resources/plans", methods=["GET"])
def plans():
plans = [{"name": "shared_data", "description": "shared elasticsearch server"}]
return json.dumps(plans), 200
@app.route("/resources", methods=["POST"])
def add_instance():
# use the given parameters to create the instance
return "", 201
@app.route("/resources/<name>", methods=["DELETE"])
def remove_instance(name):
return "", 200
@app.route("/resources/<name>/bind-app", methods=["POST"])
def bind_app(name):
envs = {
"ELASTICSEARCH_HOST": ELASTICSEARCH_HOST,
"ELASTICSEARCH_PORT": ELASTICSEARCH_PORT,
}
return json.dumps(envs), 201
@app.route("/resources/<name>/bind", methods=["POST"])
def bind(name):
return "", 201
@app.route("/resources/<name>/status", methods=["GET"])
def status(name):
elasticsearch_url = "http://{0}:{1}/".format(ELASTICSEARCH_HOST, ELASTICSEARCH_PORT)
es_state = requests.get(elasticsearch_url)
if es_state.status_code == 200:
return "", 204
else:
Flask.abort(500)
@app.route("/resources/<name>/bind-app", methods=["DELETE"])
def unbind_app(name):
return "", 200
@app.route("/resources/<name>/bind", methods=["DELETE"])
def unbind(name):
return "", 200
if __name__ == "__main__":
app.run(host="0.0.0.0", port=os.environ.get("PORT", 5000))