Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Communications Backbone System
communications-backbone
Commits
42c71fa8
Commit
42c71fa8
authored
2 years ago
by
James Kirk
Browse files
Options
Download
Email Patches
Plain Diff
fix: correct error code resp
refactor: better err msgs for invalid JSON
parent
8f1dc3b0
dev
11-add-websockets
master
v1.0.0
v0.1.0
v0.0.1
2 merge requests
!23
Resolve "Release v0.1.0"
,
!17
fix: correct error code resp
Pipeline
#108757
failed with stages
in 26 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
10 deletions
+29
-10
endpoints/client.py
endpoints/client.py
+17
-8
endpoints/notify.py
endpoints/notify.py
+6
-1
endpoints/send.py
endpoints/send.py
+6
-1
No files found.
endpoints/client.py
View file @
42c71fa8
from
flask_restful
import
Resource
,
request
,
abort
import
logging
from
flask_restful
import
Resource
,
abort
,
request
from
marshmallow
import
Schema
,
fields
from
marshmallow
import
Schema
,
fields
import
json
from
werkzeug.exceptions
import
BadRequest
import
os
import
random
import
string
from
models.client_model
import
ClientModel
from
models.client_model
import
ClientModel
logging
.
basicConfig
(
level
=
logging
.
INFO
)
logging
.
getLogger
(
"pika"
).
setLevel
(
logging
.
ERROR
)
class
ClientSchema
(
Schema
):
class
ClientSchema
(
Schema
):
client_id
=
fields
.
Str
(
required
=
True
)
client_id
=
fields
.
Str
(
required
=
True
)
...
@@ -37,7 +39,11 @@ class Client(Resource):
...
@@ -37,7 +39,11 @@ class Client(Resource):
return
client
,
204
return
client
,
204
def
put
(
self
,
client_id
):
def
put
(
self
,
client_id
):
args
=
request
.
get_json
()
try
:
args
=
request
.
get_json
()
except
BadRequest
:
return
"POSTed body is invalid JSON"
,
400
errors
=
self
.
schema
.
validate
(
args
)
errors
=
self
.
schema
.
validate
(
args
)
if
errors
:
if
errors
:
abort
(
400
,
message
=
str
(
errors
))
abort
(
400
,
message
=
str
(
errors
))
...
@@ -63,7 +69,10 @@ class ClientList(Resource):
...
@@ -63,7 +69,10 @@ class ClientList(Resource):
}
}
def
post
(
self
):
def
post
(
self
):
args
=
request
.
get_json
()
try
:
args
=
request
.
get_json
()
except
BadRequest
:
return
"POSTed body is invalid JSON"
,
400
errors
=
self
.
schema
.
validate
(
args
)
errors
=
self
.
schema
.
validate
(
args
)
if
errors
:
if
errors
:
...
@@ -71,7 +80,7 @@ class ClientList(Resource):
...
@@ -71,7 +80,7 @@ class ClientList(Resource):
client
=
self
.
clients_file
.
find
(
args
[
"client_id"
])
client
=
self
.
clients_file
.
find
(
args
[
"client_id"
])
if
client
:
if
client
:
abort
(
40
3
,
message
=
"Duplicate client id: {}"
.
format
(
client_id
))
abort
(
40
9
,
message
=
"Duplicate client id: {}"
.
format
(
args
[
"
client_id
"
]
))
else
:
else
:
client
=
self
.
clients_file
.
add
(
args
)
client
=
self
.
clients_file
.
add
(
args
)
return
client
,
201
return
client
,
201
This diff is collapsed.
Click to expand it.
endpoints/notify.py
View file @
42c71fa8
...
@@ -2,6 +2,7 @@ import json
...
@@ -2,6 +2,7 @@ import json
from
flask_restful
import
abort
,
request
from
flask_restful
import
abort
,
request
from
marshmallow
import
Schema
,
fields
from
marshmallow
import
Schema
,
fields
from
werkzeug.exceptions
import
BadRequest
from
endpoints.auth_resource
import
AuthResource
from
endpoints.auth_resource
import
AuthResource
from
rmq
import
write_to_queue
from
rmq
import
write_to_queue
...
@@ -20,7 +21,11 @@ class Notify(AuthResource):
...
@@ -20,7 +21,11 @@ class Notify(AuthResource):
self
.
schema
=
NotifySchema
()
self
.
schema
=
NotifySchema
()
def
post
(
self
):
def
post
(
self
):
args
=
request
.
get_json
()
try
:
args
=
request
.
get_json
()
except
BadRequest
:
return
"POSTed body is invalid JSON"
,
400
errors
=
self
.
schema
.
validate
(
args
)
errors
=
self
.
schema
.
validate
(
args
)
if
errors
:
if
errors
:
abort
(
400
,
message
=
str
(
errors
))
abort
(
400
,
message
=
str
(
errors
))
...
...
This diff is collapsed.
Click to expand it.
endpoints/send.py
View file @
42c71fa8
...
@@ -2,6 +2,7 @@ import json
...
@@ -2,6 +2,7 @@ import json
from
flask_restful
import
abort
,
request
from
flask_restful
import
abort
,
request
from
marshmallow
import
Schema
,
fields
from
marshmallow
import
Schema
,
fields
from
werkzeug.exceptions
import
BadRequest
from
endpoints.auth_resource
import
AuthResource
from
endpoints.auth_resource
import
AuthResource
from
rmq
import
write_to_queue
from
rmq
import
write_to_queue
...
@@ -21,7 +22,11 @@ class Send(AuthResource):
...
@@ -21,7 +22,11 @@ class Send(AuthResource):
self
.
schema
=
SendSchema
()
self
.
schema
=
SendSchema
()
def
post
(
self
):
def
post
(
self
):
args
=
request
.
get_json
()
try
:
args
=
request
.
get_json
()
except
BadRequest
:
return
"POSTed body is invalid JSON"
,
400
errors
=
self
.
schema
.
validate
(
args
)
errors
=
self
.
schema
.
validate
(
args
)
if
errors
:
if
errors
:
abort
(
400
,
message
=
str
(
errors
))
abort
(
400
,
message
=
str
(
errors
))
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment