-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade Azure Blob Storage SDK to v12 #2573
Open
pamelafox
wants to merge
33
commits into
pallets-eco:master
Choose a base branch
from
pamelafox:azureupgrade
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
bf69e03
Upgrade Azure to v12
pamelafox e106bc8
Update changelog
pamelafox 073b7e7
New lines
pamelafox e50a3b8
Remove comment
pamelafox 11b1c7d
Why is test failing
pamelafox 30a6304
Rename dev containers
pamelafox 8c87d91
Fix dev container config
pamelafox ff6f3dc
More remote print debugging
pamelafox f78c728
Update Azurite emulator for tests
pamelafox 95dd260
update minimum reqs for azure-storage-blob
pamelafox a8af6dc
Apply pre-commit
pamelafox 70508d5
Change how import error is handled
pamelafox a7a8e5f
Update the min reqs for 3.9
pamelafox da835a8
Revert unneeded tox change
pamelafox cde5d70
Lower numpy version
pamelafox c526059
Update tests, readme, dev container
pamelafox 96c6048
Update devcontainer
pamelafox d7167eb
Make devcontainer work for all services
pamelafox 4d39865
Add ports to devcontainer
pamelafox c700069
Add link to the admin
pamelafox 8dc71bc
Run pre-commit
pamelafox f22343e
Change constructor to receive client, change download to send_file in…
pamelafox 18d1c33
Update changelog
pamelafox 71e6889
Remove type annotations to match S3 client
pamelafox 59c752a
Merge branch 'master' into azureupgrade
pamelafox 4e611de
Add to latest version
pamelafox b989875
Show timestamp for directories
pamelafox 129a245
File issues
pamelafox 52311f5
Use requires_sync=False for compatibility with connection strings
pamelafox 4f86809
Fix ruff issues
pamelafox 9801c0a
Force precommit to run
pamelafox 1955b03
Sort imports
pamelafox c66dfe3
Merge branch 'master' into azureupgrade
pamelafox File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// For format details, see https://aka.ms/devcontainer.json | ||
{ | ||
"name": "flask-admin (Python 3.12)", | ||
"image": "mcr.microsoft.com/devcontainers/python:3.12-bullseye", | ||
|
||
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. | ||
"remoteUser": "vscode" | ||
} |
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,6 @@ | ||
ARG IMAGE=bullseye | ||
FROM mcr.microsoft.com/devcontainers/${IMAGE} | ||
|
||
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
&& apt-get -y install --no-install-recommends postgresql-client \ | ||
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* |
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,17 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. | ||
{ | ||
"name": "flask-admin tests (Postgres + Azurite + Mongo)", | ||
"dockerComposeFile": "docker-compose.yaml", | ||
"service": "app", | ||
"workspaceFolder": "/workspace", | ||
"forwardPorts": [10000, 10001, 5432, 27017], | ||
"portsAttributes": { | ||
"10000": {"label": "Azurite Blob Storage Emulator", "onAutoForward": "silent"}, | ||
"10001": {"label": "Azurite Blob Storage Emulator HTTPS", "onAutoForward": "silent"}, | ||
"5432": {"label": "PostgreSQL port", "onAutoForward": "silent"}, | ||
"27017": {"label": "MongoDB port", "onAutoForward": "silent"}, | ||
}, | ||
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. | ||
"remoteUser": "vscode", | ||
"postAttachCommand": "psql -U postgres -h localhost -c 'CREATE EXTENSION IF NOT EXISTS hstore;' flask_admin_test && pip install -e \".[all]\" && pip install --use-pep517 -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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
version: '3' | ||
|
||
services: | ||
app: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
args: | ||
IMAGE: python:3.12 | ||
|
||
volumes: | ||
- ../..:/workspace:cached | ||
|
||
# Overrides default command so things don't shut down after the process ends. | ||
command: sleep infinity | ||
environment: | ||
AZURE_STORAGE_CONNECTION_STRING: DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1; | ||
|
||
postgres: | ||
image: postgis/postgis:16-3.4 | ||
restart: unless-stopped | ||
environment: | ||
POSTGRES_PASSWORD: postgres | ||
POSTGRES_DB: flask_admin_test | ||
volumes: | ||
- postgres-data:/var/lib/postgresql/data | ||
network_mode: service:app | ||
|
||
azurite: | ||
container_name: azurite | ||
image: mcr.microsoft.com/azure-storage/azurite:latest | ||
restart: unless-stopped | ||
volumes: | ||
- azurite-data:/data | ||
network_mode: service:app | ||
|
||
mongo: | ||
image: mongo:5.0.14-focal | ||
restart: unless-stopped | ||
network_mode: service:app | ||
|
||
volumes: | ||
postgres-data: | ||
azurite-data: |
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
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,29 @@ | ||
# Azure Blob Storage Example | ||
|
||
Flask-Admin example for an Azure Blob Storage account. | ||
|
||
To run this example: | ||
|
||
1. Clone the repository and navigate to this example:: | ||
|
||
git clone https://github.com/pallets-eco/flask-admin.git | ||
cd flask-admin/examples/azure-blob-storage | ||
|
||
2. Create and activate a virtual environment:: | ||
|
||
python -m venv venv | ||
source venv/bin/activate | ||
|
||
3. Install requirements:: | ||
|
||
pip install -r requirements.txt | ||
|
||
4. Either run the Azurite Blob Storage emulator or create an actual Azure Blob Storage account. Set this environment variable: | ||
|
||
export AZURE_STORAGE_CONNECTION_STRING="DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;BlobEndpoint=http://127.0.0.1:10000/devstoreaccount1;" | ||
|
||
The value below is the default for the Azurite emulator. | ||
|
||
4. Run the application:: | ||
|
||
python app.py |
Empty file.
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,40 @@ | ||
import logging | ||
import os | ||
|
||
from azure.identity import DefaultAzureCredential | ||
from azure.storage.blob import BlobServiceClient | ||
from flask import Flask | ||
from flask_admin import Admin | ||
from flask_admin.contrib.fileadmin.azure import AzureFileAdmin | ||
from flask_babel import Babel | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
app = Flask(__name__) | ||
app.config["SECRET_KEY"] = "secret" | ||
|
||
|
||
@app.route("/") | ||
def index(): | ||
return '<a href="/admin/">Click me to get to Admin!</a>' | ||
|
||
|
||
admin = Admin(app) | ||
babel = Babel(app) | ||
|
||
|
||
if conn_str := os.getenv("AZURE_STORAGE_CONNECTION_STRING"): | ||
logging.info("Connecting to Azure Blob storage with connection string.") | ||
client = BlobServiceClient.from_connection_string(conn_str) | ||
elif account_name := os.getenv("AZURE_STORAGE_ACCOUNT_URL"): | ||
# https://learn.microsoft.com/azure/storage/blobs/storage-blob-python-get-started?tabs=azure-ad#authorize-access-and-connect-to-blob-storage | ||
logging.info("Connecting to Azure Blob storage with keyless auth") | ||
client = BlobServiceClient(account_name, credential=DefaultAzureCredential()) | ||
|
||
file_admin = AzureFileAdmin( | ||
blob_service_client=client, | ||
container_name="fileadmin-tests", | ||
) | ||
admin.add_view(file_admin) | ||
|
||
if __name__ == "__main__": | ||
app.run(debug=True) | ||
Comment on lines
+38
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks again for adding the example - useful 👍 |
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,2 @@ | ||
../..[azure-blob-storage] | ||
azure-identity |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit