Skip to content

Commit

Permalink
Correctly handle multiple '=' in LocalFileSystem secrets. (#21694)
Browse files Browse the repository at this point in the history
(cherry picked from commit 919b75b)
  • Loading branch information
kadai0308 authored and ephraimbuddy committed Mar 22, 2022
1 parent 1ec6a46 commit f1fa614
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 3 additions & 4 deletions airflow/secrets/local_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ def _parse_env_file(file_path: str) -> Tuple[Dict[str, List[str]], List[FileSynt
# Ignore comments
continue

var_parts: List[str] = line.split("=", 2)
if len(var_parts) != 2:
key, sep, value = line.partition("=")
if not sep:
errors.append(
FileSyntaxError(
line_no=line_no,
Expand All @@ -85,8 +85,7 @@ def _parse_env_file(file_path: str) -> Tuple[Dict[str, List[str]], List[FileSynt
)
continue

key, value = var_parts
if not key:
if not value:
errors.append(
FileSyntaxError(
line_no=line_no,
Expand Down
17 changes: 17 additions & 0 deletions tests/secrets/test_local_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,23 @@ def test_env_file_should_load_connection(self, file_content, expected_connection

assert expected_connection_uris == connection_uris_by_conn_id

@parameterized.expand(
(
(
"CONN_ID=mysql://host_1?param1=val1&param2=val2",
{"CONN_ID": "mysql://host_1?param1=val1&param2=val2"},
),
)
)
def test_parsing_with_params(self, content, expected_connection_uris):
with mock_local_file(content):
connections_by_conn_id = local_filesystem.load_connections_dict("a.env")
connection_uris_by_conn_id = {
conn_id: connection.get_uri() for conn_id, connection in connections_by_conn_id.items()
}

assert expected_connection_uris == connection_uris_by_conn_id

@parameterized.expand(
(
("AA", 'Invalid line format. The line should contain at least one equal sign ("=")'),
Expand Down

0 comments on commit f1fa614

Please sign in to comment.