Skip to content

Instantly share code, notes, and snippets.

@tecoholic
Last active February 25, 2016 18:42
Show Gist options
  • Select an option

  • Save tecoholic/e9a0ec46ca1c28677e51 to your computer and use it in GitHub Desktop.

Select an option

Save tecoholic/e9a0ec46ca1c28677e51 to your computer and use it in GitHub Desktop.
dummy gluuapi to help easily develop the web UI client
from flask import Flask, make_response
from flask_restful import Resource, Api
app = Flask(__name__)
@app.route('/')
def index():
return 'You are using the dummy version of gluu-api'
api = Api(app)
post_node = {
"provider_id": "58848b94-0671-48bc-9c94-04b0351886f0",
"name": "gluuopendj_f42dd3bf-28c8-450c-b221-77b677b59043",
"ldap_port": "1389",
"ldap_admin_port": "4444",
"ip": "",
"ldap_binddn": "cn=directory manager",
"ldaps_port": "1636",
"cluster_id": "9ea4d520-bbba-46f6-b779-c29ee99d2e9e",
"weave_ip": "",
"type": "ldap",
"id": "",
"ldap_jmx_port": "1689",
"state": "IN-PROGRESS",
"domain_name": ""
}
node = {
"provider_id": "283bfa41-2121-4433-9741-875004518677",
"name": "gluuopendj_f42dd3bf-28c8-450c-b221-77b677b59043",
"ldap_port": "1389",
"ldap_admin_port": "4444",
"ip": "172.17.0.9",
"ldap_binddn": "cn=directory manager",
"ldaps_port": "1636",
"cluster_id": "1279de28-b6d0-4052-bd0c-cc46a6fd5f9f",
"weave_ip": "10.2.1.1",
"type": "ldap",
"id": "9d99c95c4043",
"ldap_jmx_port": "1689",
"state": "SUCCESS",
"domain_name": "9d99c95c4043.ldap.gluu.local"
}
class Nodes(Resource):
def get(self, id=None):
if id:
return node
return [node]
def post(self):
return post_node
def delete(self, id):
resp = make_response('', 204)
resp.headers.extend({'X-Node-Teardown-Log': 'http://localhost:8080/node_logs/gluuopendj_f42dd3bf-28c8-450c-b221-77b677b59043/teardown'})
resp.headers['Content-Type'] = 'application/json'
return resp
cluster = {
"inum_org": "@!FDF8.652A.6EFF.F5A3!0001!DA7B.9EB2",
"oxauth_nodes": [],
"inum_appliance": "@!FDF8.652A.6EFF.F5A3!0002!FA83.4368",
"admin_email": "[email protected]",
"inum_appliance_fn": "FDF8652A6EFFF5A30002FA834368",
"description": None,
"city": "Austin",
"base_inum": "@!FDF8.652A.6EFF.F5A3",
"inum_org_fn": "FDF8652A6EFFF5A30001DA7B9EB2",
"weave_ip_network": "10.2.1.0/24",
"ldaps_port": "1636",
"ox_cluster_hostname": "ox.example.com",
"state": "TX",
"country_code": "US",
"ldap_nodes": [],
"nginx_nodes": [],
"org_short_name": "my-org",
"org_name": "my-org",
"id": "1279de28-b6d0-4052-bd0c-cc46a6fd5f9f",
"oxtrust_nodes": [],
"name": "cluster1",
"oxidp_nodes": []
}
class Clusters(Resource):
def get(self, id=None):
if id:
return cluster
return [cluster]
def post(self):
return cluster
def delete(self, id):
return '', 204
master = {
"docker_base_url": "128.199.198.172:2376",
"hostname": "master-host",
"id": "283bfa41-2121-4433-9741-875004518677",
"type": "master"
}
consumer = {
"docker_base_url": "128.199.198.173:2376",
"hostname": "consumer-host",
"id": "283bfa41-2121-4433-9741-875004518678",
"type": "consumer"
}
class Providers(Resource):
def get(self, id=None):
if id == master['id']:
return master
elif id == consumer['id']:
return consumer
return [master, consumer]
def post(self):
return consumer
def delete(self, id):
return '', 204
def put(self, id):
if id == master['id']:
return master
elif id == consumer['id']:
return consumer
return "", 404
post_key = {
"code": "your-code",
"id": "3bade490-defe-477d-8146-be0f621940ed",
"license_password": "your-license-password",
"name": "testing",
"public_key": "your-public-key",
"public_password": "your-public-password",
"valid": False,
"metadata": {}
}
full_key = {
"code": "your-code",
"id": "3bade490-defe-477d-8146-be0f621940ed",
"license_password": "your-license-password",
"name": "testing",
"public_key": "your-public-key",
"public_password": "your-public-password",
"metadata": {
"expiration_date": None,
"license_count_limit": 20,
"license_features": [
"gluu_server"
],
"license_name": "testing-license",
"license_type": None,
"multi_server": True,
"thread_count": 3
},
"valid": True
}
class LicenseKeys(Resource):
def get(self, id=None):
if id:
return full_key
return [full_key]
def post(self):
return post_key
def put(self, id):
return full_key
def delete(self, id):
return '', 204
log_exist = {
"id": "gluuopendj_f42dd3bf-28c8-450c-b221-77b677b59043",
"node_name": "gluuopendj_f42dd3bf-28c8-450c-b221-77b677b59043"
}
setup = [
"2016-02-23 00:48:47,052 - gluuopendj_f42dd3bf-28c8-450c-b221-77b677b59043 - INFO - Waiting for minion to connect; sleeping for 10 seconds",
"2016-02-23 00:48:57,058 - gluuopendj_f42dd3bf-28c8-450c-b221-77b677b59043 - INFO - Preparing remote execution; sleeping for 15 seconds",
"2016-02-23 00:49:12,074 - gluuopendj_f42dd3bf-28c8-450c-b221-77b677b59043 - INFO - attaching weave IP address 10.2.0.1/16",
"2016-02-23 00:53:17,153 - gluuopendj_f42dd3bf-28c8-450c-b221-77b677b59043 - INFO - gluuopendj setup is finished (242.836978912 seconds)"
]
teardown = [
"2016-02-23 00:53:17,153 - gluuopendj_f42dd3bf-28c8-450c-b221-77b677b59043 - INFO - gluuopendj teardown is finished (20.836978912 seconds)"
]
class NodeLogs(Resource):
def get(self, id=None, log_type=None):
if id:
if log_type == 'setup':
return setup
elif log_type == 'teardown':
return teardown
elif log_type is None:
return log_exist
return [log_exist]
def delete(self, id):
return '', 204
api.add_resource(Nodes, '/nodes', '/nodes/<string:id>')
api.add_resource(Clusters, '/clusters', '/clusters/<string:id>')
api.add_resource(Providers, '/providers', '/providers/<string:id>')
api.add_resource(LicenseKeys, '/license_keys', '/license_keys/<string:id>')
api.add_resource(NodeLogs, '/node_logs', '/node_logs/<string:id>', '/node_logs/<string:id>/<string:log_type>')
if __name__ == '__main__':
app.run(debug=True, port=8080)
Flask>=0.10.1
Flask-RESTful>=0.3.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment