Skip to content

Commit

Permalink
pass auth_config through to ContentFetcherTask
Browse files Browse the repository at this point in the history
makes it possible to pass API headers to pystac_client
  • Loading branch information
hrodmn committed Oct 28, 2022
1 parent 77cdc78 commit 2bffea6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
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

0 comments on commit 2bffea6

Please sign in to comment.