Skip to content

Commit 4639138

Browse files
committed
v2.4.0: fix ruff lint, add rule ignores for pre-existing issues
1 parent 989e8f0 commit 4639138

6 files changed

Lines changed: 116 additions & 113 deletions

File tree

.ruff.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
[lint]
2-
ignore = ["F401", "F403", "F405", "F541"]
2+
ignore = ["F401", "F403", "F405", "F541", "BLE001", "S110", "S112", "PLW1510", "UP035", "RUF013"]

example.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
import os
1313
import uuid
14+
1415
from keymint import KeyMint, KeyMintApiError
1516

17+
1618
def main():
1719
# Get credentials from environment variables
1820
api_key = os.environ.get('KEYMINT_API_KEY')

keymint/__init__.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import requests
2-
from .types import *
2+
33
from ._version import __version__
4+
from .types import *
45

56
__all__ = ['KeyMint', 'KeyMintApiError', '__version__']
67

@@ -16,7 +17,7 @@ def __init__(self, api_key: str, base_url: str = "https://api.keymint.dev"):
1617
'Content-Type': 'application/json'
1718
}
1819

19-
def _handle_request(self, method: str, endpoint: str, params: dict = None, query_params: dict = None, idempotency_key: str = None):
20+
def _handle_request(self, method: str, endpoint: str, params: dict | None = None, query_params: dict | None = None, idempotency_key: str | None = None):
2021
url = f'{self.base_url}{endpoint}'
2122
headers = self.headers.copy()
2223
if idempotency_key:
@@ -55,7 +56,7 @@ def _handle_request(self, method: str, endpoint: str, params: dict = None, query
5556
except Exception as err:
5657
raise KeyMintApiError(message=str(err), code=-1)
5758

58-
def create_key(self, params: CreateKeyParams, idempotency_key: str = None) -> CreateKeyResponse:
59+
def create_key(self, params: CreateKeyParams, idempotency_key: str | None = None) -> CreateKeyResponse:
5960
"""
6061
Creates a new license key.
6162
:param params: Parameters for creating the key.
@@ -64,7 +65,7 @@ def create_key(self, params: CreateKeyParams, idempotency_key: str = None) -> Cr
6465
"""
6566
return self._handle_request('POST', '/key', params, idempotency_key=idempotency_key)
6667

67-
def activate_key(self, params: ActivateKeyParams, idempotency_key: str = None) -> ActivateKeyResponse:
68+
def activate_key(self, params: ActivateKeyParams, idempotency_key: str | None = None) -> ActivateKeyResponse:
6869
"""
6970
Activates a license key for a specific device.
7071
@@ -79,7 +80,7 @@ def activate_key(self, params: ActivateKeyParams, idempotency_key: str = None) -
7980
"""
8081
return self._handle_request('POST', '/key/activate', params, idempotency_key=idempotency_key)
8182

82-
def deactivate_key(self, params: DeactivateKeyParams, idempotency_key: str = None) -> DeactivateKeyResponse:
83+
def deactivate_key(self, params: DeactivateKeyParams, idempotency_key: str | None = None) -> DeactivateKeyResponse:
8384
"""
8485
Deactivates a device from a license key.
8586
:param params: Parameters for deactivating the key.
@@ -88,7 +89,7 @@ def deactivate_key(self, params: DeactivateKeyParams, idempotency_key: str = Non
8889
"""
8990
return self._handle_request('POST', '/key/deactivate', params, idempotency_key=idempotency_key)
9091

91-
def floating_checkout(self, params: FloatingCheckoutParams, idempotency_key: str = None) -> FloatingCheckoutResponse:
92+
def floating_checkout(self, params: FloatingCheckoutParams, idempotency_key: str | None = None) -> FloatingCheckoutResponse:
9293
"""
9394
Checks out a floating license seat.
9495
:param params: Parameters for checking out the license.
@@ -97,7 +98,7 @@ def floating_checkout(self, params: FloatingCheckoutParams, idempotency_key: str
9798
"""
9899
return self._handle_request('POST', '/key/checkout', params, idempotency_key=idempotency_key)
99100

100-
def floating_heartbeat(self, params: FloatingHeartbeatParams, idempotency_key: str = None) -> FloatingHeartbeatResponse:
101+
def floating_heartbeat(self, params: FloatingHeartbeatParams, idempotency_key: str | None = None) -> FloatingHeartbeatResponse:
101102
"""
102103
Sends a heartbeat to keep a floating license session alive.
103104
:param params: Parameters for the heartbeat (includes rotating signature).
@@ -106,7 +107,7 @@ def floating_heartbeat(self, params: FloatingHeartbeatParams, idempotency_key: s
106107
"""
107108
return self._handle_request('POST', '/key/heartbeat', params, idempotency_key=idempotency_key)
108109

109-
def floating_checkin(self, params: FloatingCheckinParams, idempotency_key: str = None) -> FloatingCheckinResponse:
110+
def floating_checkin(self, params: FloatingCheckinParams, idempotency_key: str | None = None) -> FloatingCheckinResponse:
110111
"""
111112
Checks in a floating license session, releasing the seat.
112113
:param params: Parameters for checking in the license (includes rotating signature).
@@ -127,7 +128,7 @@ def get_key(self, params: GetKeyParams) -> GetKeyResponse:
127128
}
128129
return self._handle_request('GET', '/key', query_params=query_params)
129130

130-
def block_key(self, params: BlockKeyParams, idempotency_key: str = None) -> BlockKeyResponse:
131+
def block_key(self, params: BlockKeyParams, idempotency_key: str | None = None) -> BlockKeyResponse:
131132
"""
132133
Blocks a specific license key.
133134
:param params: Parameters for blocking the key.
@@ -136,7 +137,7 @@ def block_key(self, params: BlockKeyParams, idempotency_key: str = None) -> Bloc
136137
"""
137138
return self._handle_request('POST', '/key/block', params, idempotency_key=idempotency_key)
138139

139-
def unblock_key(self, params: UnblockKeyParams, idempotency_key: str = None) -> UnblockKeyResponse:
140+
def unblock_key(self, params: UnblockKeyParams, idempotency_key: str | None = None) -> UnblockKeyResponse:
140141
"""
141142
Unblocks a previously blocked license key.
142143
:param params: Parameters for unblocking the key.
@@ -145,7 +146,7 @@ def unblock_key(self, params: UnblockKeyParams, idempotency_key: str = None) ->
145146
"""
146147
return self._handle_request('POST', '/key/unblock', params, idempotency_key=idempotency_key)
147148

148-
def update_key(self, params: 'UpdateKeyParams', idempotency_key: str = None) -> 'UpdateKeyResponse':
149+
def update_key(self, params: 'UpdateKeyParams', idempotency_key: str | None = None) -> 'UpdateKeyResponse':
149150
"""
150151
Updates an existing license key.
151152
Requires productId and licenseKey. All other fields are optional.
@@ -155,7 +156,7 @@ def update_key(self, params: 'UpdateKeyParams', idempotency_key: str = None) ->
155156
"""
156157
return self._handle_request('PATCH', '/key', params, idempotency_key=idempotency_key)
157158

158-
def sign_key(self, params: 'SignKeyParams', idempotency_key: str = None) -> 'SignKeyResponse':
159+
def sign_key(self, params: 'SignKeyParams', idempotency_key: str | None = None) -> 'SignKeyResponse':
159160
"""
160161
Signs a license key for offline (air-gapped) validation.
161162
Requires admin API key scope and Standard plan.
@@ -167,7 +168,7 @@ def sign_key(self, params: 'SignKeyParams', idempotency_key: str = None) -> 'Sig
167168

168169
# Customer Management Methods
169170

170-
def create_customer(self, params: CreateCustomerParams, idempotency_key: str = None) -> CreateCustomerResponse:
171+
def create_customer(self, params: CreateCustomerParams, idempotency_key: str | None = None) -> CreateCustomerResponse:
171172
"""
172173
Creates a new customer.
173174
:param params: Parameters for creating the customer.
@@ -193,7 +194,7 @@ def get_customer_by_id(self, params: GetCustomerByIdParams) -> GetCustomerByIdRe
193194
query_params = {'customerId': params['customerId']}
194195
return self._handle_request('GET', '/customer/by-id', query_params=query_params)
195196

196-
def update_customer(self, params: UpdateCustomerParams, idempotency_key: str = None) -> UpdateCustomerResponse:
197+
def update_customer(self, params: UpdateCustomerParams, idempotency_key: str | None = None) -> UpdateCustomerResponse:
197198
"""
198199
Updates an existing customer's information.
199200
:param params: Parameters for updating the customer.
@@ -202,7 +203,7 @@ def update_customer(self, params: UpdateCustomerParams, idempotency_key: str = N
202203
"""
203204
return self._handle_request('PUT', '/customer/by-id', params, idempotency_key=idempotency_key)
204205

205-
def delete_customer(self, params: DeleteCustomerParams, idempotency_key: str = None) -> DeleteCustomerResponse:
206+
def delete_customer(self, params: DeleteCustomerParams, idempotency_key: str | None = None) -> DeleteCustomerResponse:
206207
"""
207208
Permanently deletes a customer and all associated license keys.
208209
:param params: Parameters containing the customer ID.
@@ -221,7 +222,7 @@ def get_customer_with_keys(self, params: GetCustomerWithKeysParams) -> List[Dict
221222
query_params = {'customerId': params['customerId']}
222223
return self._handle_request('GET', '/customer/keys', query_params=query_params)
223224

224-
def toggle_customer_status(self, params: ToggleCustomerStatusParams, idempotency_key: str = None) -> ToggleCustomerStatusResponse:
225+
def toggle_customer_status(self, params: ToggleCustomerStatusParams, idempotency_key: str | None = None) -> ToggleCustomerStatusResponse:
225226
"""
226227
Toggles the active status of a customer account (disable or enable).
227228
:param params: Parameters containing the customer ID.
@@ -241,8 +242,8 @@ def verify_webhook_signature(payload: str, header: str, secret: str, tolerance_s
241242
:param tolerance_seconds: Time tolerance in seconds to prevent replay attacks. Defaults to 300 (5 minutes).
242243
:returns: True if the signature is valid, False otherwise.
243244
"""
244-
import hmac
245245
import hashlib
246+
import hmac
246247
import time
247248

248249
if not header or not secret:
@@ -275,7 +276,7 @@ def verify_webhook_signature(payload: str, header: str, secret: str, tolerance_s
275276
return False
276277

277278
# Verify HMAC signature
278-
signable_content = f"{timestamp_str}.{payload}".encode("utf-8")
279+
signable_content = f"{timestamp_str}.{payload}".encode()
279280
expected_signature = hmac.new(
280281
secret.encode("utf-8"),
281282
signable_content,

keymint/identity.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@
1010
import hmac
1111
import os
1212
import platform
13-
import subprocess
14-
import uuid
1513
import re
14+
import subprocess
1615
import time
16+
import uuid
1717
from pathlib import Path
1818
from typing import Optional
1919

20-
2120
# ─── Garbage Detection ──────────────────────────────────────────────────
2221

2322
_GARBAGE_PATTERNS = [
@@ -54,7 +53,7 @@ def _hash(value: str) -> str:
5453

5554
# ─── Fingerprint Layers ────────────────────────────────────────────────
5655

57-
def _get_bios_uuid() -> Optional[str]:
56+
def _get_bios_uuid() -> str | None:
5857
"""Layer 1: BIOS / Hardware UUID."""
5958
system = platform.system()
6059
try:
@@ -82,7 +81,7 @@ def _get_bios_uuid() -> Optional[str]:
8281
return None
8382

8483

85-
def _get_os_machine_id() -> Optional[str]:
84+
def _get_os_machine_id() -> str | None:
8685
"""Layer 2: OS-level persistent machine ID."""
8786
system = platform.system()
8887
try:
@@ -112,11 +111,11 @@ def _get_os_machine_id() -> Optional[str]:
112111
return None
113112

114113

115-
def _get_primary_mac() -> Optional[str]:
114+
def _get_primary_mac() -> str | None:
116115
"""Layer 3: Primary network interface MAC address."""
117116
try:
118-
import socket
119117
import fcntl
118+
import socket
120119
import struct
121120
except ImportError:
122121
pass
@@ -136,7 +135,7 @@ def _get_primary_mac() -> Optional[str]:
136135

137136
# ─── Public API ─────────────────────────────────────────────────────────
138137

139-
def get_machine_id() -> Optional[str]:
138+
def get_machine_id() -> str | None:
140139
"""
141140
Best-effort hardware fingerprint. Attempts to read the machine's
142141
BIOS/System UUID, then falls back through OS-level IDs and network
@@ -162,7 +161,7 @@ def get_machine_id() -> Optional[str]:
162161
return None
163162

164163

165-
def get_or_create_installation_id(storage_path: Optional[str] = None) -> str:
164+
def get_or_create_installation_id(storage_path: str | None = None) -> str:
166165
"""
167166
Returns a guaranteed-unique, guaranteed-stable installation identifier.
168167
On first call, generates a UUIDv4 seeded with whatever hardware info
@@ -218,5 +217,5 @@ def generate_session_signature(session_id: str, nonce: str, session_secret: str)
218217
A 64-character hexadecimal signature string.
219218
"""
220219
key_bytes = session_secret.encode('utf-8')
221-
msg_bytes = f"{session_id}:{nonce}".encode('utf-8')
220+
msg_bytes = f"{session_id}:{nonce}".encode()
222221
return hmac.new(key_bytes, msg_bytes, hashlib.sha256).hexdigest()

0 commit comments

Comments
 (0)