Skip to content
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

pass auth_config through to ContentFetcherTask #222

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,22 @@ official plugin repository.
To use the plugin for development purposes, clone the repository locally,
install poetry, a python dependencies management tool see https://python-poetry.org/docs/#installation
then using the poetry tool, update the poetry lock file and install plugin dependencies by running
```
```sh
poetry update --lock
poetry install --no-dev
```

To install the plugin into the QGIS application use the below command
```
```sh
poetry run python admin.py install
```

#### Testing
To run the unit tests, run the `run-tests.sh` script. This will spin up the QGIS
docker container for several versions of QGIS and execute the unit tests.
```sh
./run-tests.sh
```



41 changes: 21 additions & 20 deletions run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
#!/usr/bin/env bash

QGIS_IMAGE=qgis/qgis

QGIS_IMAGE_V_3_16=release-3_16
QGIS_IMAGE_V_3_20=release-3_20

QGIS_VERSION_TAGS=($QGIS_IMAGE_V_3_16 $QGIS_IMAGE_V_3_20)

export IMAGE=$QGIS_IMAGE

for TAG in "${QGIS_VERSION_TAGS[@]}"
do
echo "Running tests for QGIS $TAG"
export QGIS_VERSION_TAG=$TAG
export WITH_PYTHON_PEP=false
export ON_TRAVIS=false
export MUTE_LOGS=true

# list of QGIS versions to test
QGIS_VERSION_TAGS=( \
release-3_16 \
release-3_20 \
release-3_22 \
release-3_24 \
final-3_26_0 \
final-3_28_0 \
)

# base QGIS docker image
export IMAGE=qgis/qgis

# docker-compose environment variables
export WITH_PYTHON_PEP=false
export ON_TRAVIS=false
export MUTE_LOGS=true

for QGIS_VERSION_TAG in "${QGIS_VERSION_TAGS[@]}"; do
echo "Running tests for QGIS ${QGIS_VERSION_TAG}"
docker pull ${IMAGE}:${QGIS_VERSION_TAG}
docker-compose up -d

sleep 10
docker-compose exec -T qgis-testing-environment sh -c "pip3 install flask"

docker-compose exec -T qgis-testing-environment qgis_testrunner.sh test_suite.test_package
docker-compose down

done
4 changes: 4 additions & 0 deletions src/qgis_stac/api/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def get_items(
api_capability=self.capability,
response_handler=self.handle_items,
error_handler=self.handle_error,
auth_config=self.auth_config,
)

QgsApplication.taskManager().addTask(self.content_task)
Expand All @@ -135,6 +136,7 @@ def get_collections(
resource_type=ResourceType.COLLECTION,
response_handler=self.handle_collections,
error_handler=self.handle_error,
auth_config=self.auth_config,
)

QgsApplication.taskManager().addTask(self.content_task)
Expand All @@ -156,6 +158,7 @@ def get_collection(
resource_type=ResourceType.COLLECTION,
response_handler=self.handle_collection,
error_handler=self.handle_error,
auth_config=self.auth_config,
)

QgsApplication.taskManager().addTask(self.content_task)
Expand All @@ -172,6 +175,7 @@ def get_conformance(
resource_type=ResourceType.CONFORMANCE,
response_handler=self.handle_conformance,
error_handler=self.handle_error,
auth_config=self.auth_config,
)

QgsApplication.taskManager().addTask(self.content_task)
Expand Down
12 changes: 11 additions & 1 deletion src/qgis_stac/api/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from qgis.core import (
QgsApplication,
QgsAuthMethodConfig,
QgsNetworkContentFetcherTask,
QgsTask,
)
Expand Down Expand Up @@ -80,6 +81,7 @@ def __init__(
api_capability: ApiCapability = None,
response_handler: typing.Callable = None,
error_handler: typing.Callable = None,
auth_config = None,
):
super().__init__()
self.url = url
Expand All @@ -88,6 +90,7 @@ def __init__(
self.api_capability = api_capability
self.response_handler = response_handler
self.error_handler = error_handler
self.auth_config = auth_config

def run(self):
"""
Expand All @@ -96,8 +99,15 @@ def run(self):
:returns: Whether the task completed successfully
:rtype: bool
"""
pystac_auth = {}
if self.auth_config:
auth_mgr = QgsApplication.authManager()
auth_cfg = QgsAuthMethodConfig()
auth_mgr.loadAuthenticationConfig(self.auth_config, auth_cfg, True)
if auth_cfg.method() == "APIHeader":
pystac_auth["headers"] = auth_cfg.configMap()
try:
self.client = Client.open(self.url)
self.client = Client.open(self.url, **pystac_auth)
if self.resource_type == \
ResourceType.FEATURE:
if self.search_params:
Expand Down