Skip to content

Commit

Permalink
fix: no {token} in retrieve headers (#1449)
Browse files Browse the repository at this point in the history
  • Loading branch information
jgaucher-cs committed Dec 17, 2024
1 parent 3741a4e commit 949e27a
Showing 1 changed file with 13 additions and 17 deletions.
30 changes: 13 additions & 17 deletions eodag/plugins/authentication/token.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,19 @@ def validate_config_credentials(self) -> None:
# if both are given, 'retrieve_headers' will be used for token retrieve and 'headers' for authentication.
#
# Format headers if needed with values from the credentials.
# Don't format '{token}', we allow it to be formatted later.
for attr_name in "headers", "retrieve_headers":
if attr_dict := getattr(self.config, attr_name, None):
setattr(
self.config,
attr_name,
{
header: value.format(
**{"token": "{token}", **self.config.credentials}
)
for header, value in attr_dict.items()
},
)

# If headers for authentication are undefined: use an empty dict
if not hasattr(self.config, "headers"):
self.config.headers = {}
# For the authentication headers: use and empty dict if undefined.
# And don't format '{token}' now, it will be done later.
self.config.headers = {
header: value.format(**{"token": "{token}", **self.config.credentials})
for header, value in getattr(self.config, "headers", {}).items()
}
try:
self.config.retrieve_headers = {
header: value.format(**self.config.credentials)
for header, value in self.config.retrieve_headers.items()
}
except AttributeError:
pass

except KeyError as e:
raise MisconfiguredError(
Expand Down

0 comments on commit 949e27a

Please sign in to comment.