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
6c133675
Commit
6c133675
authored
Sep 09, 2022
by
Oleksandr Barabash
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hotfixes
parent
bf693ab9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
7 deletions
+21
-7
app.py
app.py
+9
-4
azure_key_vault_client.py
utils/azure_key_vault_client.py
+12
-3
No files found.
app.py
View file @
6c133675
...
...
@@ -161,20 +161,25 @@ async def v1_health_check(_request: Request) -> Response:
container
=
None
try
:
container
=
await
COSMOS_CLIENT
.
get_conversations_container
()
key
=
await
KEY_VAULT_CLIENT
.
get_random_key
()
data
=
await
KEY_VAULT_CLIENT
.
get_secret
(
"adminLogin"
)
return
Response
(
body
=
json
.
dumps
(
dict
(
data
=
data
)),
status
=
HTTPStatus
.
OK
,
content_type
=
"application/json"
)
except
Exception
as
e
:
Log
.
e
(
TAG
,
"v1_health_check::error"
,
e
)
if
key
is
None
:
return
Response
(
status
=
HTTPStatus
.
INTERNAL_SERVER_ERROR
,
body
=
json
.
dumps
({
"error"
:
"Can't connect to KeyVault"
})
body
=
json
.
dumps
({
"error"
:
"Can't connect to KeyVault"
}),
content_type
=
"application/json"
)
if
container
is
None
:
return
Response
(
status
=
HTTPStatus
.
INTERNAL_SERVER_ERROR
,
body
=
json
.
dumps
({
"error"
:
"Can't connect to CosmosDB"
})
body
=
json
.
dumps
({
"error"
:
"Can't connect to CosmosDB"
}),
content_type
=
"application/json"
)
return
Response
(
status
=
HTTPStatus
.
OK
)
return
Response
(
status
=
HTTPStatus
.
OK
,
content_type
=
"application/json"
)
@web.middleware
...
...
utils/azure_key_vault_client.py
View file @
6c133675
...
...
@@ -27,12 +27,21 @@ class AzureKeyVaultClient:
self
.
credential
=
ManagedIdentityCredential
(
client_id
=
client_id
)
self
.
key_client
=
KeyClient
(
vault_url
=
self
.
key_vault_uri
,
credential
=
self
.
credential
)
self
.
secret_client
=
SecretClient
(
vault_url
=
self
.
key_vault_uri
,
credential
=
self
.
credential
)
async
def
execute_blocking
(
self
,
bl
,
*
args
):
""" Execute blocking code """
return
await
asyncio
.
get_event_loop
()
.
run_in_executor
(
self
.
executor
,
bl
,
*
args
)
return
await
self
.
io_loop
.
run_in_executor
(
self
.
executor
,
bl
,
*
args
)
def
set_secret
(
self
,
name
:
str
,
value
:
str
)
->
Awaitable
[
"KeyVaultSecret"
]:
""" Async set secret """
return
self
.
execute_blocking
(
self
.
secret_client
.
set_secret
,
name
,
value
)
def
get_secret
(
self
,
name
:
str
)
->
Awaitable
[
"KeyVaultSecret"
]:
""" Async get secret """
return
self
.
execute_blocking
(
self
.
secret_client
.
get_secret
,
name
)
def
get_key
(
self
,
name
:
str
)
->
Awaitable
[
"KeyVaultKey"
]:
""" Async get key """
...
...
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