Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ build/docs/mkdocs.yml
.vscode
.DS_Store
venv
.coverage
.coverage
htmlcov
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ lint: ## Run code linting

.PHONY: scan
scan: ## Run security checks
bandit -r . -ll -x site-packages
bandit -r . -ll -x ./test/,site-packages

.PHONY: clean
clean: ## Clean up python cache files
Expand Down
11 changes: 8 additions & 3 deletions ibind/base/subscription_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@

_LOGGER = project_logger(__file__)

# Default subscription configuration
DEFAULT_SUBSCRIPTION_RETRIES = 5
DEFAULT_SUBSCRIPTION_TIMEOUT = 2.0
DEFAULT_OPERATIONAL_LOCK_TIMEOUT = 60
Comment on lines +12 to +15

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we parameterise them, then let's add these to var.py



class SubscriptionProcessor(ABC): # pragma: no cover
"""
Expand Down Expand Up @@ -47,15 +52,15 @@ class SubscriptionController:
def __init__(
self,
subscription_processor: SubscriptionProcessor,
subscription_retries: int = 5,
subscription_timeout: float = 2,
subscription_retries: int = DEFAULT_SUBSCRIPTION_RETRIES,
subscription_timeout: float = DEFAULT_SUBSCRIPTION_TIMEOUT,
):
self._subscription_processor = subscription_processor
self._subscription_retries = subscription_retries
self._subscription_timeout = subscription_timeout

self._subscriptions: Dict[str, dict] = {}
self._operational_lock = TimeoutLock(60)
self._operational_lock = TimeoutLock(DEFAULT_OPERATIONAL_LOCK_TIMEOUT)

def _send_payload(self: 'WsClient', payload) -> bool:
try:
Expand Down
4 changes: 2 additions & 2 deletions ibind/oauth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class OAuthConfig(ABC):
"""

@abstractmethod
def version(self):
def version(self): # pragma: no cover
"""
Returns the OAuth version.

Expand All @@ -28,7 +28,7 @@ def version(self):
"""
raise NotImplementedError()

def verify_config(self):
def verify_config(self): # pragma: no cover
return

init_oauth: bool = var.IBIND_INIT_OAUTH
Expand Down
5 changes: 1 addition & 4 deletions ibind/oauth/oauth1a.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
from typing import Optional, TYPE_CHECKING
from urllib import parse

# TODO: Remove bandit ignore once we have a new Crypto implementation
# Check repo wiki for more details on Security consideration
from Crypto.Cipher import PKCS1_v1_5 as PKCS1_v1_5_Cipher # nosec
from Crypto.Hash import SHA256, HMAC, SHA1 # nosec
from Crypto.PublicKey import RSA # nosec
Expand All @@ -20,7 +18,6 @@
if TYPE_CHECKING: # pragma: no cover
from ibind import IbkrClient


_STRING_ENCODING = 'utf-8'
_INT_BASE = 16
_KEY_VALUE_SEPARATOR = '='
Expand Down Expand Up @@ -229,7 +226,7 @@ def generate_request_timestamp() -> str:
return str(int(time.time()))


def read_private_key(private_key_fp: str) -> RSA.RsaKey:
def read_private_key(private_key_fp: str) -> RSA.RsaKey: # pragma: no cover
"""
Reads the private key from the file path provided. The key is used to sign the request and decrypt the access token secret.
"""
Expand Down
4 changes: 2 additions & 2 deletions ibind/support/logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ def __init__(self, *args, date_format='%Y-%m-%d', **kwargs):
self.stream = None
super().__init__(*args, **kwargs)

def get_timestamp(self):
def get_timestamp(self): # pragma: no cover
now = datetime.datetime.now(datetime.timezone.utc)
return now.strftime(self.date_format)

def get_filename(self, timestamp):
def get_filename(self, timestamp): # pragma: no cover
return f'{self.baseFilename}__{timestamp}.txt'

def _open(self):
Expand Down
1 change: 0 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@ ruff>=0.9.4,<0.10.0
bandit>=1.8.2,<2.0.0
pytest>=7.0.0,<9.0.0
pytest-cov>=4.0.0,<6.0.0

Binary file modified requirements-oauth.txt
Binary file not shown.
Empty file added test/unit/base/__init__.py
Empty file.
Loading
Loading