Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
cake-bot
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Oleksandr Barabash
cake-bot
Commits
5632cf1a
Commit
5632cf1a
authored
Dec 05, 2022
by
Oleksandr Barabash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor fixes
parent
987384ef
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
14 deletions
+17
-14
app.py
app.py
+13
-10
en.yml
assets/strings/en.yml
+2
-2
functions.py
utils/functions.py
+2
-2
No files found.
app.py
View file @
5632cf1a
...
...
@@ -137,9 +137,10 @@ async def v1_post_notification(request: Request) -> Response:
request_body
=
await
request
.
text
()
schema
=
Notification
.
get_schema
(
unknown
=
EXCLUDE
)
notification
=
schema
.
load
(
json_loads
(
request_body
,
{}))
.
to_db
()
message_id
=
await
BOT
.
send_notification
(
notification
)
response_body
=
json
.
dumps
({
"data"
:
{
"messageId"
:
message_id
}})
return
Response
(
body
=
response_body
,
status
=
HTTPStatus
.
OK
)
notification_id
=
await
BOT
.
send_notification
(
notification
)
data
=
dict
(
notificationId
=
notification_id
)
body
=
dict
(
status
=
dict
(
message
=
"OK"
,
code
=
200
),
data
=
data
)
return
Response
(
body
=
json
.
dumps
(
body
),
status
=
HTTPStatus
.
OK
)
except
ConversationNotFound
:
return
Response
(
status
=
HTTPStatus
.
NOT_FOUND
,
reason
=
"Conversation not found"
)
...
...
@@ -171,7 +172,7 @@ async def v1_messages(request: Request) -> Response:
return
Response
(
status
=
HTTPStatus
.
OK
)
async
def
v1_health_check
(
_request
:
Request
)
->
Response
:
async
def
v1_
get_
health_check
(
_request
:
Request
)
->
Response
:
""" Health check """
try
:
# _container = await COSMOS_CLIENT.get_conversations_container()
...
...
@@ -186,7 +187,7 @@ async def v1_health_check(_request: Request) -> Response:
raise
async
def
get_app_zip
(
_request
:
Request
)
->
FileResponse
:
async
def
v1_
get_app_zip
(
_request
:
Request
)
->
FileResponse
:
""" Get zip file """
from
config
import
APP_VERSION
filename
=
f
"app_{APP_VERSION}.zip"
...
...
@@ -211,7 +212,7 @@ async def error_middleware(request, handler):
body
=
json
.
dumps
({
"error"
:
message
}))
async
def
v1_auth
(
request
:
Request
)
->
Response
:
async
def
v1_
post_
auth
(
request
:
Request
)
->
Response
:
""" Admin Auth """
if
"application/json"
in
request
.
headers
[
"Content-Type"
]:
body
=
await
request
.
json
()
...
...
@@ -222,7 +223,9 @@ async def v1_auth(request: Request) -> Response:
if
admin_user
.
login
and
admin_user
.
password
:
result
=
await
TOKEN_HELPER
.
do_auth
(
admin_user
)
if
result
is
not
None
:
return
Response
(
status
=
HTTPStatus
.
OK
,
body
=
json_dumps
(
result
))
body
=
dict
(
status
=
dict
(
message
=
"OK"
,
code
=
200
),
data
=
result
)
return
Response
(
status
=
HTTPStatus
.
OK
,
body
=
json_dumps
(
body
))
except
ValidationError
:
pass
return
Response
(
status
=
HTTPStatus
.
FORBIDDEN
)
...
...
@@ -265,9 +268,9 @@ async def app_factory(bot):
v1_get_notification
)
app
.
router
.
add_get
(
"/api/v1/initiations/{notification_id}"
,
v1_get_initiations
)
app
.
router
.
add_get
(
"/api/v1/health-check"
,
v1_health_check
)
app
.
router
.
add_get
(
"/{}"
.
format
(
TeamsAppConfig
.
zip_name
),
get_app_zip
)
app
.
router
.
add_post
(
"/api/v1/auth"
,
v1_auth
)
app
.
router
.
add_get
(
"/api/v1/health-check"
,
v1_
get_
health_check
)
app
.
router
.
add_get
(
"/{}"
.
format
(
TeamsAppConfig
.
zip_name
),
v1_
get_app_zip
)
app
.
router
.
add_post
(
"/api/v1/auth"
,
v1_
post_
auth
)
bot
.
add_web_app
(
app
)
bot
.
add_cosmos_client
(
COSMOS_CLIENT
)
...
...
assets/strings/en.yml
View file @
5632cf1a
...
...
@@ -24,8 +24,8 @@ en:
portal_button_text
:
Open secured portal
response_help
:
|
Conversation ID: %{conversation_id}
.
<br/>
Tenant ID: %{tenant_id}
.
<br/><br/>
Conversation ID: %{conversation_id}
<br/>
<br/>
Tenant ID: %{tenant_id}<br/><br/>
Supported commands:<br/>
%{cmd_help} - this command.<br/>
%{cmd_portal} - request secured portal window.
...
...
utils/functions.py
View file @
5632cf1a
...
...
@@ -94,7 +94,7 @@ def quote_b64decode_str_safe(data: str, encoding="utf-8",
try
:
return
urllib
.
parse
.
unquote
(
data_quoted
)
except
TypeError
:
Log
.
e
(
TAG
,
"quote_b64decode_str_safe: error"
,
exc_info
=
sys
.
exc_info
()
)
Log
.
d
(
TAG
,
"quote_b64decode_str_safe: error, returning default"
)
return
default
...
...
@@ -104,7 +104,7 @@ def quote_b64encode_str_safe(data: str, encoding="utf-8",
try
:
data_quoted
=
urllib
.
parse
.
quote
(
data
)
# str even if input is bytes
except
TypeError
:
Log
.
e
(
TAG
,
"quote_b64encode_str_safe: error"
,
exc_info
=
sys
.
exc_info
()
)
Log
.
d
(
TAG
,
"quote_b64encode_str_safe: error, returning default"
)
return
default
return
b64encode_str_safe
(
data_quoted
,
encoding
,
default
)
...
...
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