srx-lib-azure 0.1.4__py3-none-any.whl → 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of srx-lib-azure might be problematic. Click here for more details.

srx_lib_azure/blob.py CHANGED
@@ -10,18 +10,32 @@ from loguru import logger
10
10
 
11
11
 
12
12
  class AzureBlobService:
13
- """Minimal Azure Blob helper with SAS URL generation."""
14
-
15
- def __init__(self) -> None:
16
- self.container_name = os.getenv("AZURE_BLOB_CONTAINER", "uploads")
17
- self.connection_string = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
18
- self.account_key = os.getenv("AZURE_STORAGE_ACCOUNT_KEY")
19
- self.sas_token = os.getenv("AZURE_SAS_TOKEN")
20
- self.base_blob_url = os.getenv("AZURE_BLOB_URL")
21
-
22
- if not self.connection_string:
13
+ """Minimal Azure Blob helper with SAS URL generation.
14
+
15
+ All configuration can be passed explicitly via constructor. If omitted, falls back
16
+ to environment variables. By default, it does not warn at startup when not
17
+ configured; operations will error if required values are missing.
18
+ """
19
+
20
+ def __init__(
21
+ self,
22
+ *,
23
+ connection_string: Optional[str] = None,
24
+ account_key: Optional[str] = None,
25
+ container_name: Optional[str] = None,
26
+ base_blob_url: Optional[str] = None,
27
+ sas_token: Optional[str] = None,
28
+ warn_if_unconfigured: bool = False,
29
+ ) -> None:
30
+ self.container_name = container_name or os.getenv("AZURE_BLOB_CONTAINER", "uploads")
31
+ self.connection_string = connection_string or os.getenv("AZURE_STORAGE_CONNECTION_STRING")
32
+ self.account_key = account_key or os.getenv("AZURE_STORAGE_ACCOUNT_KEY")
33
+ self.sas_token = sas_token or os.getenv("AZURE_SAS_TOKEN")
34
+ self.base_blob_url = base_blob_url or os.getenv("AZURE_BLOB_URL")
35
+
36
+ if warn_if_unconfigured and not self.connection_string:
23
37
  logger.warning(
24
- "Azure Storage connection string not configured; blob operations will fail."
38
+ "Azure Storage connection string not configured; blob operations may fail."
25
39
  )
26
40
 
27
41
  def _get_blob_service(self) -> BlobServiceClient:
srx_lib_azure/email.py CHANGED
@@ -1,22 +1,48 @@
1
1
  import os
2
- from azure.communication.email.aio import EmailClient
3
-
4
2
  import logging
3
+ from typing import Dict, Any
4
+
5
+ try:
6
+ from azure.communication.email.aio import EmailClient
7
+ except Exception: # pragma: no cover - optional dependency at import time
8
+ EmailClient = None # type: ignore
5
9
 
6
10
  logger = logging.getLogger(__name__)
7
11
 
8
12
 
9
13
  class EmailService:
10
- """Thin wrapper over Azure Communication Services EmailClient."""
14
+ """Thin wrapper over Azure Communication Services EmailClient.
11
15
 
12
- def __init__(self):
13
- self.connection_string = os.getenv("ACS_CONNECTION_STRING")
14
- self.sender_address = os.getenv("EMAIL_SENDER")
15
- if not self.connection_string or not self.sender_address:
16
- raise ValueError("Missing ACS_CONNECTION_STRING or EMAIL_SENDER in environment variables")
17
- self.email_client = EmailClient.from_connection_string(self.connection_string)
16
+ Does not raise on missing configuration to keep the library optional.
17
+ If not configured, send calls are skipped with a warning and a 'skipped' status.
18
+ """
18
19
 
19
- async def send_notification(self, recipient: str, subject: str, body: str, html: bool = False):
20
+ def __init__(
21
+ self,
22
+ *,
23
+ connection_string: str | None = None,
24
+ sender_address: str | None = None,
25
+ warn_if_unconfigured: bool = False,
26
+ ):
27
+ self.connection_string = connection_string or os.getenv("ACS_CONNECTION_STRING")
28
+ self.sender_address = sender_address or os.getenv("EMAIL_SENDER")
29
+ if not self.connection_string or not self.sender_address or EmailClient is None:
30
+ self.email_client = None
31
+ if warn_if_unconfigured:
32
+ logger.warning(
33
+ "EmailService not configured (missing ACS_CONNECTION_STRING/EMAIL_SENDER or azure SDK). Calls will be skipped."
34
+ )
35
+ else:
36
+ try:
37
+ self.email_client = EmailClient.from_connection_string(self.connection_string)
38
+ except Exception as e:
39
+ self.email_client = None
40
+ logger.warning("EmailService initialization failed: %s", e)
41
+
42
+ async def send_notification(self, recipient: str, subject: str, body: str, html: bool = False) -> Dict[str, Any]:
43
+ if not self.email_client or not self.sender_address:
44
+ logger.warning("Email skipped: service not configured")
45
+ return {"status": "skipped", "message": "Email service not configured"}
20
46
  message = {
21
47
  "content": {"subject": subject},
22
48
  "recipients": {"to": [{"address": recipient}]},
@@ -38,4 +64,3 @@ class EmailService:
38
64
  except Exception as e:
39
65
  logger.error("Email send exception: %s", e)
40
66
  return {"status": "error", "message": str(e)}
41
-
srx_lib_azure/table.py CHANGED
@@ -19,7 +19,11 @@ def _now_iso() -> str:
19
19
 
20
20
  @dataclass
21
21
  class AzureTableService:
22
- connection_string: Optional[str] = os.getenv("AZURE_STORAGE_CONNECTION_STRING")
22
+ connection_string: Optional[str] = None
23
+
24
+ def __init__(self, connection_string: Optional[str] = None) -> None:
25
+ # Constructor injection preferred; fallback to env only if not provided
26
+ self.connection_string = connection_string or os.getenv("AZURE_STORAGE_CONNECTION_STRING")
23
27
 
24
28
  def _get_client(self) -> "TableServiceClient":
25
29
  if not self.connection_string:
@@ -76,4 +80,3 @@ class AzureTableService:
76
80
  table = client.get_table_client(table_name)
77
81
  for entity in table.query_entities(filter=filter_query):
78
82
  yield dict(entity)
79
-
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: srx-lib-azure
3
- Version: 0.1.4
3
+ Version: 0.1.6
4
4
  Summary: Azure helpers for SRX services: Blob, Email, Table
5
5
  Author-email: SRX <dev@srx.id>
6
6
  Requires-Python: >=3.12
@@ -0,0 +1,7 @@
1
+ srx_lib_azure/__init__.py,sha256=K0UCmkKw7HWJMshp6Xv3SxD4y26r7bdcPtb_2aRc2rs,174
2
+ srx_lib_azure/blob.py,sha256=3g5r3cOOdTAN283PBEU__p5gLYQ97LE_KEeNc2mVnLg,8889
3
+ srx_lib_azure/email.py,sha256=2J5zlgJMhx7pMINwN4kW23PmdwL1JyU9xFsSl5gAAM4,2831
4
+ srx_lib_azure/table.py,sha256=6on0DpquH6cHVfHQeu6ZKQOPdZAkS8eG-c-9x3q3aPg,3234
5
+ srx_lib_azure-0.1.6.dist-info/METADATA,sha256=0EiRCp221PZqjIZJa0QYky9rCgbUcyrodZPbiFv6UWY,1600
6
+ srx_lib_azure-0.1.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
+ srx_lib_azure-0.1.6.dist-info/RECORD,,
@@ -1,7 +0,0 @@
1
- srx_lib_azure/__init__.py,sha256=K0UCmkKw7HWJMshp6Xv3SxD4y26r7bdcPtb_2aRc2rs,174
2
- srx_lib_azure/blob.py,sha256=uCsRUCQN4GHtlyLBtDUvy0_mZaFTxWKdCA407cRIU8I,8245
3
- srx_lib_azure/email.py,sha256=H8KCnYFuQ2dKzpWx3BsKv9tVCV-pEmm7vXUJkOnpVh4,1719
4
- srx_lib_azure/table.py,sha256=_5DCsk1SLqCc27F7469hxnRASS3XeffqK_MsJE1cD7Y,3022
5
- srx_lib_azure-0.1.4.dist-info/METADATA,sha256=P_eY6gpsYaolhdOp3eraiqlTq5ePnsr22K5VzDjcJYk,1600
6
- srx_lib_azure-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
7
- srx_lib_azure-0.1.4.dist-info/RECORD,,