-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use api endpoint to generate az maps token
- Loading branch information
1 parent
c9656c3
commit f682088
Showing
12 changed files
with
148 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
FROM mcr.microsoft.com/azure-functions/python:4-python3.9 | ||
FROM mcr.microsoft.com/azure-cli:cbl-mariner2.0 | ||
|
||
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \ | ||
AzureFunctionsJobHost__Logging__Console__IsEnabled=true | ||
|
||
RUN tdnf install libicu unzip wget -y | ||
RUN wget https://github.com/Azure/azure-functions-core-tools/releases/download/4.0.5530/Azure.Functions.Cli.linux-x64.4.0.5530.zip | ||
RUN mkdir -p /usr/local/lib/Azure.Functions.Cli | ||
RUN unzip Azure.Functions.Cli.linux-x64.4.0.5530.zip -d /usr/local/lib/Azure.Functions.Cli | ||
RUN chmod +x /usr/local/lib/Azure.Functions.Cli/func | ||
|
||
ENV PATH="/usr/local/lib/Azure.Functions.Cli:${PATH}" | ||
|
||
RUN python3 -m ensurepip --upgrade | ||
COPY requirements.txt / | ||
RUN pip install -r /requirements.txt | ||
RUN pip3 install -r /requirements.txt | ||
|
||
COPY requirements-dev.txt / | ||
RUN pip install -r /requirements-dev.txt | ||
RUN pip3 install -r /requirements-dev.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import json | ||
import logging | ||
from typing import TypedDict | ||
|
||
import azure.functions as func | ||
|
||
from azure.identity import DefaultAzureCredential | ||
from azure.core.exceptions import ClientAuthenticationError | ||
|
||
logger = logging.getLogger("api.maps-token") | ||
# For performance, exclude checking options we know won't be used | ||
credential = DefaultAzureCredential( | ||
exclude_environment_credential=True, | ||
exclude_developer_cli_credential=True, | ||
exclude_powershell_credential=True, | ||
exclude_visual_studio_code_credential=True, | ||
) | ||
|
||
|
||
class TokenResponse(TypedDict): | ||
token: str | ||
expires_on: int | ||
|
||
|
||
def main(req: func.HttpRequest) -> func.HttpResponse: | ||
|
||
logger.debug("Python HTTP trigger function processed a request.") | ||
try: | ||
logger.debug("Getting azure maps token") | ||
token = credential.get_token("https://atlas.microsoft.com/.default") | ||
logger.debug("Token acquired") | ||
|
||
resp: TokenResponse = {"token": token.token, "expires_on": token.expires_on} | ||
|
||
return func.HttpResponse(status_code=200, body=json.dumps(resp)) | ||
except ClientAuthenticationError: | ||
logger.exception(f"Error getting azure maps token") | ||
return func.HttpResponse("Error getting token", status_code=500) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"scriptFile": "__init__.py", | ||
"bindings": [ | ||
{ | ||
"authLevel": "function", | ||
"type": "httpTrigger", | ||
"direction": "in", | ||
"name": "req", | ||
"methods": [ | ||
"get" | ||
] | ||
}, | ||
{ | ||
"type": "http", | ||
"direction": "out", | ||
"name": "$return" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters