Skip to content

Commit

Permalink
fix: clean up upgrade.py and apis
Browse files Browse the repository at this point in the history
- added postman export
- not found handler
  • Loading branch information
dcai committed Aug 12, 2019
1 parent 0ca52a0 commit 4ba7a02
Show file tree
Hide file tree
Showing 7 changed files with 243 additions and 38 deletions.
26 changes: 26 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true

# Matches multiple files with brace expansion notation
# Set default charset
[*.{js,py}]
charset = utf-8

# 4 space indentation
[*.py]
indent_style = space
indent_size = 4

# Tab indentation (no size specified)
[Makefile]
indent_style = tab

# Matches the exact files either package.json or .travis.yml
[{package.json,*.yml}]
indent_style = space
indent_size = 2
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ test:
true

format:
black --exclude "venv\/|venv3.6\/|build/|buck-out/|dist/|_build/|\.eggs/|\.git/|\.hg/|\.mypy_cache/|\.nox/|\.tox/|\.venv/" .
black --exclude "ENV\/|venv\/|venv3.6\/|build/|buck-out/|dist/|_build/|\.eggs/|\.git/|\.hg/|\.mypy_cache/|\.nox/|\.tox/|\.venv/" .
7 changes: 7 additions & 0 deletions airnotifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,12 @@
_logger = logging.getLogger("AirNotifierApp")


class NotFoundHandler(tornado.web.RequestHandler):
def prepare(self): # for all methods
self.set_status(404, None)
self.finish()


class AirNotifierApp(tornado.web.Application):
def init_routes(self, dir):
from routes import RouteLoader
Expand Down Expand Up @@ -205,6 +211,7 @@ def __init__(self, services):
cookie_secret=options.cookiesecret,
login_url=r"/auth/login",
autoescape=None,
default_handler_class=NotFoundHandler,
)
self.services = services

Expand Down
26 changes: 0 additions & 26 deletions api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,32 +468,6 @@ def get(self):
self.send_response(OK, users)


@route(r"/users/([^/]+)")
@route(r"/api/v2/users/([^/]+)")
class UserHandler(APIBaseHandler):
def delete(self, userId):
""" Delete user """
pass

def put(self, userId):
""" Update """
pass

def get(self, userId):
"""Get user details by ID
"""
username = self.get_argument("username", None)
email = self.get_argument("email", None)
userid = self.get_argument("userid", None)
conditions = {}
if username:
conditions["username"] = username
if email:
conditions["email"] = email
if userid:
conditions["id"] = userid


@route(r"/objects/([^/]+)/([^/]+)")
@route(r"/api/v2/objects/([^/]+)/([^/]+)")
class ObjectHandler(APIBaseHandler):
Expand Down
2 changes: 1 addition & 1 deletion constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

RELEASE = "1.2.0"
VERSION = 20190124
VERSION = 20190125

DEVICE_TYPE_IOS = "ios"
DEVICE_TYPE_ANDROID = "android"
Expand Down
198 changes: 198 additions & 0 deletions postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
{
"info": {
"_postman_id": "d9a00aff-fe72-990e-b2b1-d931bc1aac33",
"name": "airnotifier v2 API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "push",
"request": {
"method": "POST",
"header": [
{
"key": "X-AN-APP-NAME",
"value": "moodle"
},
{
"key": "X-AN-APP-KEY",
"value": "eb9977f82282513bfac8292702e4cf37"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"device\": \"fcm\",\n \"alert\": {\n \"title\": \"hello ts: {{$timestamp}}\",\n \"body\": \"Hello from AirNotifier {{$guid}}\"\n },\n \"token\": \"{{airnotifier-device-token}}\"\n}"
},
"url": {
"raw": "{{airnotifier-host}}/api/v2/push",
"host": [
"{{airnotifier-host}}"
],
"path": [
"api",
"v2",
"push"
]
}
},
"response": []
},
{
"name": "create access key",
"request": {
"method": "POST",
"header": [
{
"key": "X-AN-APP-NAME",
"value": "moodle"
},
{
"key": "X-AN-APP-KEY",
"value": "eb9977f82282513bfac8292702e4cf37"
},
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\n \"device\": \"fcm\",\n \"alert\": {\n \"title\": \"hello ts: {{$timestamp}}\",\n \"body\": \"Hello from AirNotifier {{$guid}}\"\n },\n \"token\": \"{{airnotifier-device-token}}\"\n}"
},
"url": {
"raw": "{{airnotifier-host}}/api/v2/accesskeys",
"host": [
"{{airnotifier-host}}"
],
"path": [
"api",
"v2",
"accesskeys"
]
}
},
"response": []
},
{
"name": "create user",
"request": {
"method": "POST",
"header": [
{
"key": "X-AN-APP-NAME",
"value": "moodle"
},
{
"key": "X-AN-APP-KEY",
"value": "eb9977f82282513bfac8292702e4cf37"
},
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "username",
"value": "test{{$randomInt}}",
"type": "text"
},
{
"key": "password",
"value": "test",
"type": "text"
},
{
"key": "email",
"value": "[email protected]",
"type": "text"
}
]
},
"url": {
"raw": "{{airnotifier-host}}/api/v2/users",
"host": [
"{{airnotifier-host}}"
],
"path": [
"api",
"v2",
"users"
]
}
},
"response": []
},
{
"name": "find users",
"protocolProfileBehavior": {
"disableBodyPruning": true
},
"request": {
"method": "GET",
"header": [
{
"key": "X-AN-APP-NAME",
"value": "moodle"
},
{
"key": "X-AN-APP-KEY",
"value": "eb9977f82282513bfac8292702e4cf37"
},
{
"key": "Content-Type",
"name": "Content-Type",
"value": "application/x-www-form-urlencoded",
"type": "text"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "username",
"value": "test{{$randomInt}}",
"type": "text"
},
{
"key": "password",
"value": "test",
"type": "text"
},
{
"key": "email",
"value": "[email protected]",
"type": "text"
}
]
},
"url": {
"raw": "{{airnotifier-host}}/api/v2/users?where={\"username\":\"test205\"}",
"host": [
"{{airnotifier-host}}"
],
"path": [
"api",
"v2",
"users"
],
"query": [
{
"key": "where",
"value": "{\"username\":\"test205\"}"
}
]
}
},
"response": []
}
]
}
20 changes: 10 additions & 10 deletions upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@
app["wnstokentype"] = ""
if not "wnstokenexpiry" in app:
app["wnstokenexpiry"] = ""
masterdb.applications.update({"_id": appid}, app, upsert=True)
masterdb["options"].update(
masterdb.applications.update_one({"_id": appid}, app, upsert=True)
masterdb["options"].update_one(
{"name": "version"}, {"$set": {"value": 20140720}}, upsert=True
)

Expand All @@ -137,8 +137,8 @@
app["mpnscertificatefile"] = os.path.basename(
app.get("mpnscertificatefile")
)
masterdb.applications.update({"_id": appid}, app, upsert=True)
masterdb["options"].update(
masterdb.applications.update_one({"_id": appid}, app, upsert=True)
masterdb["options"].update_one(
{"name": "version"}, {"$set": {"value": 20140814}}, upsert=True
)

Expand All @@ -154,8 +154,8 @@
app["clickatellpassword"] = ""
if not "clickatellappid" in app:
app["clickatellappid"] = ""
masterdb.applications.update({"_id": appid}, app, upsert=True)
masterdb["options"].update(
masterdb.applications.update_one({"_id": appid}, app, upsert=True)
masterdb["options"].update_one(
{"name": "version"}, {"$set": {"value": 20140820}}, upsert=True
)

Expand All @@ -170,13 +170,13 @@
print("Adding index to %s%s['logs'].%s" % (appprefix, appname, "created"))
db["logs"].create_index(indexes)

masterdb["options"].update(
masterdb["options"].update_one(
{"name": "version"}, {"$set": {"value": 20151101}}, upsert=True
)

if version < 20190124:
masterdb["options"].update(
{"name": "version"}, {"$set": {"value": 20190124}}, upsert=True
if version < 20190125:
masterdb["options"].update_one(
{"name": "version"}, {"$set": {"value": 20190125}}, upsert=True
)

version_object = masterdb["options"].find_one({"name": "version"})
Expand Down

0 comments on commit 4ba7a02

Please sign in to comment.