Skip to content

Commit

Permalink
Merge pull request #216 from octoenergy/feature/url_encode_secrets
Browse files Browse the repository at this point in the history
Improve error message for secret parse error
  • Loading branch information
JohnH-KTL authored Jan 5, 2024
2 parents d4d67c7 + b059fe4 commit e6e2a09
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.3.1] - 2024-01-04
### Changed
- Error message when a Tentaclio secret cannot be passed to give more information to user.

## [1.3.0] - 2023-10-25
### Added
- Add support for interpolating environment variables to tentaclio secrets file.
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from setuptools.command.install import install


VERSION = "1.3.0"
VERSION = "1.3.1"

REPO_ROOT = pathlib.Path(__file__).parent

Expand Down
4 changes: 1 addition & 3 deletions src/tentaclio/credentials/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ class TentaclioFileError(Exception):

def __init__(self, message: str):
"""Intialise a new TentaclioFileError."""
message = self.ERROR_TEMPLATE.format(
message=message, tentaclio_file=self.TENTACLIO_FILE
)
message = self.ERROR_TEMPLATE.format(message=message, tentaclio_file=self.TENTACLIO_FILE)
super().__init__(message)


Expand Down
13 changes: 12 additions & 1 deletion src/tentaclio/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,18 @@ def _parse_url(self) -> None:
if self._url is None:
raise URLError("None url")

parsed_url = parse.urlparse(self._url)
try:
parsed_url = parse.urlparse(self._url)
except ValueError as e:
if str(e) == "Invalid IPv6 URL":
message = (
"Please ensure the provided Tentaclio secret URL is in valid format."
" If your password element contains special characters,"
" please ensure it is URL encoded. You can do this using"
"the Python urllib.parse.quote_plus() function."
)
raise ValueError("Invalid IPv6 URL : " + message)
raise e

self._scheme = parsed_url.scheme
self._username = parsed_url.username
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/credentials/test_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def test_credentials_bad_url(creds_yaml_bad_url):
],
)
def test_credentials_env_variable(url, expected, creds_yaml_env_variables, monkeypatch):
monkeypatch.setenv('USER', 'user')
monkeypatch.setenv('USER_DB', 'user_db')
monkeypatch.setenv('PASSWORD', 'password')
monkeypatch.setenv('PASSWORD_DB', 'password_db')
monkeypatch.setenv("USER", "user")
monkeypatch.setenv("USER_DB", "user_db")
monkeypatch.setenv("PASSWORD", "password")
monkeypatch.setenv("PASSWORD_DB", "password_db")

data = io.StringIO(creds_yaml_env_variables)
injector = reader.add_credentials_from_reader(injection.CredentialsInjector(), data)
Expand Down

0 comments on commit e6e2a09

Please sign in to comment.