Skip to content

Commit e4371ce

Browse files
committed
Clarifications and fixes
1 parent 841fd25 commit e4371ce

4 files changed

Lines changed: 17 additions & 11 deletions

File tree

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ try:
233233

234234
You can use the `MetricsResponseHandler` object to process your OpenPAYGO Metrics request from start to finish. It accepts the following initial inputs:
235235
- `metrics_payload` (required): The OpenPAYGO Metrics payload, as a string containing the JSON payload.
236-
- `secret_key` (optional): The secret key provided as a string containing 32 hexadecimal characters (e.g. `dac86b1a29ab82edc5fbbc41ec9530f6`)
236+
- `secret_key` (optional): The secret key provided as a string containing 32 hexadecimal characters (e.g. `dac86b1a29ab82edc5fbbc41ec9530f6`). If the secret key is not set later using `set_device_parameters()`, then you will not be able to verify the auth of the request (it will throw an error if you try) and the response will not be signed.
237+
- `skip_auth`
237238
- `data_format` (optional): The data format, provided as dictionnary matching the data format object specifications.
238239
- `last_request_count` (optional): The request count of the last valid request (used for avoiding request replay)
239240
- `last_request_timestamp` (optional): The timestamp of the last valid request (used for avoiding request replay)
@@ -313,6 +314,10 @@ def device_data():
313314

314315
## Changelog
315316

317+
### 2023-10-12 - v0.5.2
318+
- Clarification in the doc of the behaviour when `secret_key` is missing
319+
- Implemented coherent behaviour when `secret_key` is missing
320+
316321
### 2023-10-12 - v0.5.1
317322
- Fixes typo in function name
318323

openpaygo/metrics_response.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def set_device_parameters(self, secret_key=None, data_format=None, last_request_
4646
def is_auth_valid(self):
4747
auth_string = self.request_dict.get('auth', None)
4848
if not auth_string:
49-
return True
49+
return False
5050
elif not self.secret_key:
5151
raise ValueError('Secret key is required to check the auth.')
5252
self.auth_method = auth_string[:2]
@@ -129,13 +129,14 @@ def get_answer_payload(self):
129129
def get_answer_dict(self):
130130
# If there is not data format, we just return the full response
131131
condensed_answer = copy.deepcopy(self.response_dict)
132-
condensed_answer['auth'] = OpenPAYGOMetricsShared.generate_response_signature_from_data(
133-
serial_number=self.request_dict.get('serial_number'),
134-
request_count=self.request_dict.get('request_count'),
135-
data=condensed_answer,
136-
timestamp=self.request_dict.get('timestamp'),
137-
secret_key=self.secret_key
138-
)
132+
if self.secret_key:
133+
condensed_answer['auth'] = OpenPAYGOMetricsShared.generate_response_signature_from_data(
134+
serial_number=self.request_dict.get('serial_number'),
135+
request_count=self.request_dict.get('request_count'),
136+
data=condensed_answer,
137+
timestamp=self.request_dict.get('timestamp'),
138+
secret_key=self.secret_key
139+
)
139140
return OpenPAYGOMetricsShared.convert_dict_keys_to_condensed(condensed_answer)
140141

141142
def _get_simple_data(self):

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = openpaygo
3-
version = 0.5.1
3+
version = 0.5.2
44
url = https://github.com/EnAccess/OpenPAYGO-python/
55
description-file=README.md
66
license_files=LICENSE

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
setup(
55
name="openpaygo",
66
packages=find_packages(),
7-
version='0.5.1',
7+
version='0.5.2',
88
license='MIT',
99
author="Solaris Offgrid",
1010
url='https://github.com/EnAccess/OpenPAYGO-python/',

0 commit comments

Comments
 (0)