-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
71 lines (56 loc) · 1.98 KB
/
app.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
from flask import Flask,jsonify,request,redirect
app = Flask(__name__)
from config.config import Config
app.config.from_object(Config)
from DirectoryUtil.create_service import ServiceFactory
from oauth import oauth
app.register_blueprint(oauth,url_prefix="/oauth")
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route("/user_list")
@app.route("/<name>/user_list")
def test(name="default"):
res,service = ServiceFactory.getService(name)
if res:
data = service.users().list(customer='my_customer', maxResults=5,
orderBy='email').execute()
else:
return redirect("/oauth/auth")
return jsonify(data)
@app.route("/adduser",methods=["post"])
@app.route("/<name>/adduser",methods=["post"])
def adduser(name="default"):
data_temp = request.get_json()
data ={
"name": {
"familyName": data_temp.get("familyName"),
"givenName": data_temp.get("givenName")
},
"password": data_temp.get("password"),
"primaryEmail": data_temp.get("account"),
"changePasswordAtNextLogin": True,
"orgUnitPath": data_temp.get("orgUnit")
}
res, service = ServiceFactory.getService(name)
info = {"code":500,"msg":"service create failure"}
if res:
try:
info = service.users().insert(body=data).execute()
except Exception as ex:
return jsonify(msg=ex.args[1].decode(),code=409)
return jsonify(info)
@app.route("/orgunit",methods=["get"])
@app.route("/<name>/orgunit",methods=["get"])
def orgunit(name="default"):
res, service = ServiceFactory.getService(name)
info = {"code": 500, "msg": "service create failure"}
if res:
info = service.orgunits().list(customerId="my_customer").execute()
return jsonify(info)
@app.route("/loaded_service")
def service_list():
data = ServiceFactory.get_service_list()
return jsonify(code=200,msg="success",data=data)
if __name__ == '__main__':
app.run()