Skip to content

Commit eaffda2

Browse files
nithinbNithin Bodanapu
andauthored
Changes to prevent the use of method find_dotenv (#429)
* Changes to prevent the use of method find_dotenv * updated changelog to include the removal of the usage of dotenv.finddotenv * Update to version for extractor-utils * Fix for mypy check failing * Changes suggested in the PR related to the version and the changelog phrasing --------- Co-authored-by: Nithin Bodanapu <nithin.bodanapu@cognite.com>
1 parent 050b6fe commit eaffda2

File tree

5 files changed

+18
-11
lines changed

5 files changed

+18
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ Changes are grouped as follows
1212
- `Fixed` for any bug fixes.
1313
- `Security` in case of vulnerabilities.
1414

15+
## 7.5.13
16+
17+
### Security
18+
19+
* Disabled recursive search for .env file. The change will prevent loading environment variables hosted in directories other than the current working directory. Environment variable management is now more explicit to enhance security, and reduce potential misconfigurations.
20+
1521
## 7.5.12
1622

1723
## Added

cognite/extractorutils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
Cognite extractor utils is a Python package that simplifies the development of new extractors.
1717
"""
1818

19-
__version__ = "7.5.12"
19+
__version__ = "7.5.13"
2020
from .base import Extractor
2121

2222
__all__ = ["Extractor"]

cognite/extractorutils/base.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from types import TracebackType
2323
from typing import Any, Generic, TypeVar
2424

25-
from dotenv import find_dotenv, load_dotenv
25+
from dotenv import load_dotenv
2626

2727
from cognite.client import CogniteClient
2828
from cognite.client.data_classes import ExtractionPipeline, ExtractionPipelineRun
@@ -252,12 +252,11 @@ def __enter__(self) -> "Extractor":
252252

253253
if str(os.getenv("COGNITE_FUNCTION_RUNTIME", False)).lower() != "true":
254254
# Environment Variables
255-
env_file_path = find_dotenv(usecwd=True)
256-
if env_file_path:
257-
load_dotenv(dotenv_path=env_file_path, override=True)
258-
dotenv_message = f"Successfully ingested environment variables from {env_file_path}"
255+
env_file_found = load_dotenv(dotenv_path="./.env", override=True)
256+
if env_file_found:
257+
dotenv_message = "Successfully ingested environment variables from './.env'"
259258
else:
260-
dotenv_message = "No .env file found"
259+
dotenv_message = "No .env file found at {Path.cwd() / '.env'}"
261260
else:
262261
dotenv_message = "No .env file imported when using Cognite Functions"
263262

cognite/extractorutils/configtools/loaders.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def __init__(self, config: dict | None):
6969
self.client: SecretClient | None = None
7070

7171
def _init_client(self) -> None:
72-
from dotenv import find_dotenv, load_dotenv
72+
from dotenv import load_dotenv
7373

7474
if not self.config:
7575
raise InvalidConfigError(
@@ -98,8 +98,10 @@ def _init_client(self) -> None:
9898

9999
_logger.info("Using Azure ClientSecret credentials to access KeyVault")
100100

101-
dotenv_path = find_dotenv(usecwd=True)
102-
load_dotenv(dotenv_path=dotenv_path, override=True)
101+
env_file_found = load_dotenv("./.env", override=True)
102+
103+
if not env_file_found:
104+
_logger.info(f"Local environment file not found at {Path.cwd() / '.env'}")
103105

104106
if all(param in self.config for param in auth_parameters):
105107
tenant_id = os.path.expandvars(self.config.get("tenant-id", None))

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "cognite-extractor-utils"
3-
version = "7.5.12"
3+
version = "7.5.13"
44
description = "Utilities for easier development of extractors for CDF"
55
authors = [
66
{name = "Mathias Lohne", email = "mathias.lohne@cognite.com"}

0 commit comments

Comments
 (0)