Skip to content

Commit 4a5075b

Browse files
[Fixes #13009] Implement Basic Auth support for Remote Services
1 parent e7a543f commit 4a5075b

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

geonode/harvesting/harvesters/wms.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,18 +203,17 @@ def get_capabilities(self) -> requests.Response:
203203
# checking if the services is under basic auth
204204
# getting the service
205205
from geonode.services.models import Service
206+
206207
# check if the connected service has username and password
207208
has_basic_auth = Service.objects.filter(
208-
harvester__pk=self.harvester_id,
209-
username__isnull=False,
210-
password__isnull=False
209+
harvester__pk=self.harvester_id, username__isnull=False, password__isnull=False
211210
)
212211
basic_auth = None
213212
if has_basic_auth.exists():
214213
# if the username and password are set, we can prepare the basic auth for the request
215214
service = has_basic_auth.first()
216215
basic_auth = HTTPBasicAuth(service.username, service.get_password())
217-
216+
218217
get_capabilities_response = self.http_session.get(
219218
self.get_ogc_wms_url(wms_url, version=_version), params=params, auth=basic_auth
220219
)

geonode/thumbs/thumbnails.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def create_thumbnail(
158158
styles=styles,
159159
width=width,
160160
height=height,
161-
instance=instance
161+
instance=instance,
162162
)
163163
)
164164
except Exception as e:

geonode/thumbs/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ def get_map(
144144
height: int = 200,
145145
max_retries: int = 3,
146146
retry_delay: int = 1,
147-
instance=None
147+
instance=None,
148148
):
149149
"""
150150
Function fetching an image from OGC server.
@@ -201,12 +201,15 @@ def get_map(
201201
else:
202202
headers["Authorization"] = f"Bearer {additional_kwargs['access_token']}"
203203

204-
if instance and instance.subtype == 'remote' and instance.remote_typename:
204+
if instance and instance.subtype == "remote" and instance.remote_typename:
205205
from geonode.services.models import Service
206+
206207
service = Service.objects.filter(name=instance.remote_typename, username__isnull=False, password__isnull=False)
207208
if service.exists():
208209
service = service.first()
209-
encoded_credentials = base64.b64encode(f"{service.username}:{service.get_password()}".encode("UTF-8")).decode("ascii")
210+
encoded_credentials = base64.b64encode(
211+
f"{service.username}:{service.get_password()}".encode("UTF-8")
212+
).decode("ascii")
210213
headers["Authorization"] = f"Basic {encoded_credentials}"
211214

212215
image = None

0 commit comments

Comments
 (0)