Skip to content

Commit

Permalink
+ pre-commit and linting updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bsummers-tc committed Oct 24, 2024
1 parent 574dfb1 commit d79463f
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 13 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-ast
Expand All @@ -27,19 +27,19 @@ repos:
- id: requirements-txt-fixer
- id: trailing-whitespace
- repo: https://github.com/pycqa/bandit
rev: 1.7.4
rev: 1.7.10
hooks:
- id: bandit
exclude: |
(?x)(
^tests/
)
- repo: https://github.com/psf/black
rev: 23.1.0
rev: 24.10.0
hooks:
- id: black
- repo: https://github.com/codespell-project/codespell
rev: v2.2.2
rev: v2.3.0
hooks:
- id: codespell
- repo: https://github.com/pre-commit/mirrors-isort
Expand All @@ -62,7 +62,7 @@ repos:
^tests/
)
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
rev: v3.19.0
hooks:
- id: pyupgrade
args:
Expand Down
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""TcEx Framework Module"""

from .requests_tc import RequestsTc
from .tc_session import TcSession

Expand Down
1 change: 1 addition & 0 deletions auth/hmac_auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""TcEx Framework Module"""

# standard library
import hmac
import time
Expand Down
3 changes: 2 additions & 1 deletion auth/tc_auth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""TcEx Framework Module"""

# standard library
import time
from collections.abc import Callable
Expand Down Expand Up @@ -27,7 +28,7 @@ def __init__(
else: # pragma: no cover
raise RuntimeError('No valid ThreatConnect API credentials provided.')

def __call__(self, r):
def __call__(self, r): # type: ignore
"""Add the authorization headers to the request."""
timestamp = int(time.time())
if self.auth_type == 'hmac':
Expand Down
8 changes: 4 additions & 4 deletions auth/token_auth.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""TcEx Framework Module"""

# standard library
import time
from collections.abc import Callable

# third-party
from requests import Request # TYPE-CHECKING
from requests import auth
from requests import PreparedRequest, auth

from ...input.field_type.sensitive import Sensitive

Expand Down Expand Up @@ -33,11 +33,11 @@ def _token_header(self):
# Return formatted token
return f'TC-Token {_token}'

def __call__(self, r: Request) -> Request:
def __call__(self, r: PreparedRequest) -> PreparedRequest:
"""Add the authorization headers to the request."""
timestamp = int(time.time())

# Add required headers to auth.
r.headers['Authorization'] = self._token_header()
r.headers['Timestamp'] = timestamp
r.headers['Timestamp'] = str(timestamp)
return r
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ disable = [
"too-many-arguments",
"too-many-branches",
"too-many-instance-attributes",
"too-many-positional-arguments",
"too-many-public-methods",
]
extension-pkg-whitelist = "pydantic"
Expand Down
3 changes: 2 additions & 1 deletion requests_tc.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""TcEx Framework Module"""

# standard library
import logging
from functools import cached_property
Expand Down Expand Up @@ -75,7 +76,7 @@ def get_session(
log_curl=log_curl,
proxies=proxies or self.proxies,
proxies_enabled=proxies_enabled,
user_agent=registry.app.user_agent,
user_agent=registry.app.user_agent, # type: ignore
verify=verify,
)

Expand Down
5 changes: 3 additions & 2 deletions tc_session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""TcEx Framework Module"""

# standard library
import logging

Expand Down Expand Up @@ -31,7 +32,7 @@ def __init__(
log_curl: bool | None = False,
proxies: dict[str, str] | None = None,
proxies_enabled: bool | None = False,
user_agent: dict | None = None,
user_agent: dict[str, str] | None = None,
verify: bool | str | None = True,
):
"""Initialize the Class properties."""
Expand Down Expand Up @@ -77,7 +78,7 @@ def _log_curl(self, response: Response):
except Exception: # nosec
pass # logging curl command is best effort

def request(self, method, url, **kwargs): # pylint: disable=arguments-differ
def request(self, method, url, **kwargs): # pylint: disable=arguments-differ # type: ignore
"""Override request method disabling verify on token renewal if disabled on session."""
response = super().request(method, self.url(url), **kwargs)

Expand Down

0 comments on commit d79463f

Please sign in to comment.