Skip to content

Commit 8580240

Browse files
angel-devojgarciai
andauthored
chore: Update several packages versions and add code of conduct (#234)
* chore: Update several packages versions and add code of conduct * fix: Review tests not passing * fix: Fix some tests regarding chain validation * chore: Reformat some bad formed strings --------- Co-authored-by: jgarciai <35931740+jgarciai@users.noreply.github.com>
1 parent 692060f commit 8580240

38 files changed

+639
-824
lines changed

CHANGELOG.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,18 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) a
66

77
## [Unreleased]
88

9+
### Added
10+
11+
- Added Code of Conduct.
12+
913
### Changed
1014

11-
- Restrict insecure TLS versions in Sender and API clients to TLSv1.2 and TLSv1.3
15+
- Restrict insecure TLS versions in Sender and API clients to TLSv1.2 and TLSv1.3.
1216
- Remove disclosing information in messages about keepalive token.
1317
- Fix incorences in documentation about using `url` and `address` interchangeably.
18+
- `certifi` dependency upgraded from `certifi~=2023.7.22` to `certifi~=2023.11.17`
19+
- `cryptography` dependency upgraded from `cryptography~=41.0.5` to `cryptography~=41.0.7`
20+
- `pipdeptree` dependency upgraded from `pipdeptree~=2.13.0` to `pipdeptree~=2.13.1`
1421
- `pyopenssl` dependency upgraded from `pyopenssl~=23.2` to `pyopenssl~=23.3`
1522
- `responses` dependency upgraded from `responses~=0.22.3` to `responses~=0.24`
1623

CODE_OF_CONDUCT.md

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our Pledge
4+
5+
We as members, contributors, and leaders pledge to make participation in our
6+
community a harassment-free experience for everyone, regardless of age, body
7+
size, visible or invisible disability, ethnicity, sex characteristics, gender
8+
identity and expression, level of experience, education, socio-economic status,
9+
nationality, personal appearance, race, caste, color, religion, or sexual
10+
identity and orientation.
11+
12+
We pledge to act and interact in ways that contribute to an open, welcoming,
13+
diverse, inclusive, and healthy community.
14+
15+
## Our Standards
16+
17+
Examples of behavior that contributes to a positive environment for our
18+
community include:
19+
20+
* Demonstrating empathy and kindness toward other people
21+
* Being respectful of differing opinions, viewpoints, and experiences
22+
* Giving and gracefully accepting constructive feedback
23+
* Accepting responsibility and apologizing to those affected by our mistakes,
24+
and learning from the experience
25+
* Focusing on what is best not just for us as individuals, but for the overall
26+
community
27+
28+
Examples of unacceptable behavior include:
29+
30+
* The use of sexualized language or imagery, and sexual attention or advances of
31+
any kind
32+
* Trolling, insulting or derogatory comments, and personal or political attacks
33+
* Public or private harassment
34+
* Publishing others' private information, such as a physical or email address,
35+
without their explicit permission
36+
* Other conduct which could reasonably be considered inappropriate in a
37+
professional setting
38+
39+
## Enforcement Responsibilities
40+
41+
Community leaders are responsible for clarifying and enforcing our standards of
42+
acceptable behavior and will take appropriate and fair corrective action in
43+
response to any behavior that they deem inappropriate, threatening, offensive,
44+
or harmful.
45+
46+
Community leaders have the right and responsibility to remove, edit, or reject
47+
comments, commits, code, wiki edits, issues, and other contributions that are
48+
not aligned to this Code of Conduct, and will communicate reasons for moderation
49+
decisions when appropriate.
50+
51+
## Scope
52+
53+
This Code of Conduct applies within all community spaces, and also applies when
54+
an individual is officially representing the community in public spaces.
55+
Examples of representing our community include using an official email address,
56+
posting via an official social media account, or acting as an appointed
57+
representative at an online or offline event.
58+
59+
## Enforcement
60+
61+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
62+
reported to the community leaders responsible for enforcement at
63+
[support@devo.com](support@devo.com).
64+
All complaints will be reviewed and investigated promptly and fairly.
65+
66+
All community leaders are obligated to respect the privacy and security of the
67+
reporter of any incident.
68+
69+
## Enforcement Guidelines
70+
71+
Community leaders will follow these Community Impact Guidelines in determining
72+
the consequences for any action they deem in violation of this Code of Conduct:
73+
74+
### 1. Correction
75+
76+
**Community Impact**: Use of inappropriate language or other behavior deemed
77+
unprofessional or unwelcome in the community.
78+
79+
**Consequence**: A private, written warning from community leaders, providing
80+
clarity around the nature of the violation and an explanation of why the
81+
behavior was inappropriate. A public apology may be requested.
82+
83+
### 2. Warning
84+
85+
**Community Impact**: A violation through a single incident or series of
86+
actions.
87+
88+
**Consequence**: A warning with consequences for continued behavior. No
89+
interaction with the people involved, including unsolicited interaction with
90+
those enforcing the Code of Conduct, for a specified period of time. This
91+
includes avoiding interactions in community spaces as well as external channels
92+
like social media. Violating these terms may lead to a temporary or permanent
93+
ban.
94+
95+
### 3. Temporary Ban
96+
97+
**Community Impact**: A serious violation of community standards, including
98+
sustained inappropriate behavior.
99+
100+
**Consequence**: A temporary ban from any sort of interaction or public
101+
communication with the community for a specified period of time. No public or
102+
private interaction with the people involved, including unsolicited interaction
103+
with those enforcing the Code of Conduct, is allowed during this period.
104+
Violating these terms may lead to a permanent ban.
105+
106+
### 4. Permanent Ban
107+
108+
**Community Impact**: Demonstrating a pattern of violation of community
109+
standards, including sustained inappropriate behavior, harassment of an
110+
individual, or aggression toward or disparagement of classes of individuals.
111+
112+
**Consequence**: A permanent ban from any sort of public interaction within the
113+
community.
114+
115+
## Attribution
116+
117+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118+
version 2.1, available at
119+
[https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120+
121+
Community Impact Guidelines were inspired by
122+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123+
124+
For answers to common questions about this code of conduct, see the FAQ at
125+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126+
[https://www.contributor-covenant.org/translations][translations].
127+
128+
[homepage]: https://www.contributor-covenant.org
129+
[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130+
[Mozilla CoC]: https://github.com/mozilla/diversity
131+
[FAQ]: https://www.contributor-covenant.org/faq
132+
[translations]: https://www.contributor-covenant.org/translations

devo/api/client.py

Lines changed: 21 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,7 @@ def __init__(
303303
verify = verify if verify is not None else config.get("verify", True)
304304
retries = retries if retries is not None else config.get("retries", 0)
305305
timeout = timeout if timeout is not None else config.get("timeout", 300)
306-
retry_delay = (
307-
retry_delay if retry_delay is not None else config.get("retry_delay", 5)
308-
)
306+
retry_delay = retry_delay if retry_delay is not None else config.get("retry_delay", 5)
309307
self.config = self._from_dict(config)
310308

311309
self.auth = auth
@@ -351,9 +349,7 @@ def __get_address_parts(self, address):
351349
Split the two parts of the api address
352350
:param address: address of the api
353351
"""
354-
return self.__verify_address_complement(
355-
address.split("//")[-1].split("/", maxsplit=1)
356-
)
352+
return self.__verify_address_complement(address.split("//")[-1].split("/", maxsplit=1))
357353

358354
@staticmethod
359355
def __verify_address_complement(address_list):
@@ -362,9 +358,7 @@ def __verify_address_complement(address_list):
362358
:param address_list: One or two part of the address
363359
"""
364360
return (
365-
address_list
366-
if len(address_list) == 2
367-
else [address_list[0], ADDRESS_QUERY_COMPLEMENT]
361+
address_list if len(address_list) == 2 else [address_list[0], ADDRESS_QUERY_COMPLEMENT]
368362
)
369363

370364
@staticmethod
@@ -464,9 +458,7 @@ def query(
464458
if not dates["to"]:
465459
dates["to"] = "now()"
466460
if self.config.stream:
467-
logging.warning(
468-
ERROR_MSGS["stream_mode_not_supported"] % self.config.response
469-
)
461+
logging.warning(ERROR_MSGS["stream_mode_not_supported"] % self.config.response)
470462
# If is a future query and response type is 'xls' or 'msgpack'
471463
# return warning because is not available.
472464
if self._future_queries_available(self.config.response):
@@ -476,9 +468,7 @@ def query(
476468
toDate = self._toDate_parser(fromDate, default_to(dates["to"]))
477469

478470
if toDate > default_to("now()"):
479-
raise DevoClientException(
480-
ERROR_MSGS["future_queries_not_supported"]
481-
)
471+
raise DevoClientException(ERROR_MSGS["future_queries_not_supported"])
482472

483473
self.config.stream = False
484474

@@ -509,9 +499,7 @@ def _call(self, payload):
509499
# Analyse the response data to check if there are any error
510500
# messages within the response.
511501
self._error_handler(wholeResponse.text)
512-
return self.config.processor(
513-
self._keepalive_content_sanitize(wholeResponse.text)
514-
)
502+
return self.config.processor(self._keepalive_content_sanitize(wholeResponse.text))
515503

516504
def _return_string_stream(self, payload):
517505
"""If it's a stream call, return yield lines
@@ -557,10 +545,7 @@ def _empty_lines_sanitize(line):
557545
return line.strip()
558546

559547
def _keepalive_content_sanitize(self, response):
560-
if (
561-
self.config.keepAliveToken == NO_KEEPALIVE_TOKEN
562-
or self.config.keepAliveToken is None
563-
):
548+
if self.config.keepAliveToken == NO_KEEPALIVE_TOKEN or self.config.keepAliveToken is None:
564549
return response
565550
elif self.config.keepAliveToken == DEFAULT_KEEPALIVE_TOKEN:
566551
if self.config.response.startswith("json"):
@@ -584,10 +569,7 @@ def _keepalive_content_sanitize(self, response):
584569
return response.replace(f"{self.config.keepAliveToken}", "")
585570

586571
def _keepalive_stream_sanitize(self, line):
587-
if (
588-
self.config.keepAliveToken == NO_KEEPALIVE_TOKEN
589-
or self.config.keepAliveToken is None
590-
):
572+
if self.config.keepAliveToken == NO_KEEPALIVE_TOKEN or self.config.keepAliveToken is None:
591573
return line
592574
elif self.config.keepAliveToken == DEFAULT_KEEPALIVE_TOKEN:
593575
if self.config.response.startswith("json"):
@@ -641,9 +623,7 @@ def __request(self, payload):
641623
POST request method extracted for mocking purposes
642624
"""
643625
return requests.post(
644-
"{}://{}".format(
645-
"http" if self.unsecure_http else "https", "/".join(self.address)
646-
),
626+
"{}://{}".format("http" if self.unsecure_http else "https", "/".join(self.address)),
647627
data=payload,
648628
headers=self._get_headers(payload),
649629
verify=self.verify,
@@ -668,9 +648,7 @@ def _get_payload(query, query_id, dates, opts):
668648
date_to = default_to(dates["to"]) if dates["to"] is not None else None
669649

670650
payload = {
671-
"from": int(date_from / 1000)
672-
if isinstance(date_from, (int, float))
673-
else date_from,
651+
"from": int(date_from / 1000) if isinstance(date_from, (int, float)) else date_from,
674652
"to": int(date_to / 1000) if isinstance(date_to, (int, float)) else date_to,
675653
"mode": {"type": opts["response"]},
676654
}
@@ -693,10 +671,7 @@ def _get_payload(query, query_id, dates, opts):
693671
if opts["destination"]:
694672
payload["destination"] = opts["destination"]
695673

696-
if (
697-
opts["keepAliveToken"] is not None
698-
and opts["keepAliveToken"] != NO_KEEPALIVE_TOKEN
699-
):
674+
if opts["keepAliveToken"] is not None and opts["keepAliveToken"] != NO_KEEPALIVE_TOKEN:
700675
if opts["keepAliveToken"] == EMPTY_EVENT_KEEPALIVE_TOKEN:
701676
payload["keepAlive"] = {"type": "empty"}
702677
elif opts["keepAliveToken"] == DEFAULT_KEEPALIVE_TOKEN:
@@ -797,25 +772,19 @@ def stop_job(self, job_id):
797772
"""Stop one job by ID
798773
:param job_id: id of job
799774
:return: bool"""
800-
return self._call_jobs(
801-
"{}{}{}{}".format(self.address[0], ADDRESS_JOB, "stop/", job_id)
802-
)
775+
return self._call_jobs("{}{}{}{}".format(self.address[0], ADDRESS_JOB, "stop/", job_id))
803776

804777
def start_job(self, job_id):
805778
"""Start one job by ID
806779
:param job_id: id of job
807780
:return: bool"""
808-
return self._call_jobs(
809-
"{}{}{}{}".format(self.address[0], ADDRESS_JOB, "start/", job_id)
810-
)
781+
return self._call_jobs("{}{}{}{}".format(self.address[0], ADDRESS_JOB, "start/", job_id))
811782

812783
def remove_job(self, job_id):
813784
"""Remove one job by ID
814785
:param job_id: id of job
815786
:return: bool"""
816-
return self._call_jobs(
817-
"{}{}{}{}".format(self.address[0], ADDRESS_JOB, "remove/", job_id)
818-
)
787+
return self._call_jobs("{}{}{}{}".format(self.address[0], ADDRESS_JOB, "remove/", job_id))
819788

820789
def _call_jobs(self, address):
821790
"""
@@ -837,10 +806,7 @@ def _call_jobs(self, address):
837806
raise DevoClientException(ERROR_MSGS["connection_error"]) from error
838807

839808
if response:
840-
if (
841-
response.status_code != 200
842-
or "error" in response.text[0:15].lower()
843-
):
809+
if response.status_code != 200 or "error" in response.text[0:15].lower():
844810
raise DevoClientRequestException(response)
845811
try:
846812
return json.loads(response.text)
@@ -893,9 +859,7 @@ def _fromDate_parser(fromDate, now=datetime.now()):
893859
elif fromDate == "today":
894860
return adate.timestamp() * 1000
895861
elif fromDate == "endday":
896-
return (
897-
adate + timedelta(hours=23, minutes=59, seconds=59)
898-
).timestamp() * 1000
862+
return (adate + timedelta(hours=23, minutes=59, seconds=59)).timestamp() * 1000
899863
elif fromDate == "endmonth":
900864
return (
901865
adate.replace(day=calendar.monthrange(adate.year, adate.month)[1])
@@ -910,15 +874,9 @@ def _toDate_parser(fromDateMillisec, toDate, now=datetime.now()):
910874
return toDate
911875

912876
now = now.astimezone(pytz.UTC)
913-
fromDate = datetime.fromtimestamp(fromDateMillisec / 1000).replace(
914-
tzinfo=pytz.utc
915-
)
916-
aFromdate = datetime.strptime(str(fromDate.date()), "%Y-%m-%d").replace(
917-
tzinfo=pytz.utc
918-
)
919-
aNowdate = datetime.strptime(str(now.date()), "%Y-%m-%d").replace(
920-
tzinfo=pytz.utc
921-
)
877+
fromDate = datetime.fromtimestamp(fromDateMillisec / 1000).replace(tzinfo=pytz.utc)
878+
aFromdate = datetime.strptime(str(fromDate.date()), "%Y-%m-%d").replace(tzinfo=pytz.utc)
879+
aNowdate = datetime.strptime(str(now.date()), "%Y-%m-%d").replace(tzinfo=pytz.utc)
922880

923881
if re.match("^[1-9]+(d|ad|h|ah|m|am|s|as)", toDate):
924882
date = re.split("(d|ad|h|ah|m|am|s|as)", toDate)
@@ -945,14 +903,10 @@ def _toDate_parser(fromDateMillisec, toDate, now=datetime.now()):
945903
elif toDate == "today":
946904
return aNowdate.timestamp() * 1000
947905
elif toDate == "endday":
948-
return (
949-
aFromdate + timedelta(hours=23, minutes=59, seconds=59)
950-
).timestamp() * 1000
906+
return (aFromdate + timedelta(hours=23, minutes=59, seconds=59)).timestamp() * 1000
951907
elif toDate == "endmonth":
952908
return (
953-
aFromdate.replace(
954-
day=calendar.monthrange(aFromdate.year, aFromdate.month)[1]
955-
)
909+
aFromdate.replace(day=calendar.monthrange(aFromdate.year, aFromdate.month)[1])
956910
+ timedelta(hours=23, minutes=59, seconds=59)
957911
).timestamp() * 1000
958912
elif toDate == "now":

devo/api/processors.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,11 @@ def proc_default():
1212

1313

1414
def proc_bytes_to_str():
15-
return (
16-
lambda data: data.strip()
17-
if isinstance(data, str)
18-
else data.strip().decode("utf-8")
19-
)
15+
return lambda data: data.strip() if isinstance(data, str) else data.strip().decode("utf-8")
2016

2117

2218
def proc_str_to_bytes():
23-
return (
24-
lambda data: data.strip()
25-
if isinstance(data, bytes)
26-
else data.strip().encode("utf-8")
27-
)
19+
return lambda data: data.strip() if isinstance(data, bytes) else data.strip().encode("utf-8")
2820

2921

3022
def proc_json():
@@ -40,9 +32,7 @@ def processor(data):
4032
else None
4133
)
4234
if obj and "e" in obj:
43-
raise RuntimeError(
44-
f"Error {obj['e'][0]} processing query: " f"{obj['e'][1]}"
45-
)
35+
raise RuntimeError(f"Error {obj['e'][0]} processing query: " f"{obj['e'][1]}")
4636
else:
4737
return obj
4838

0 commit comments

Comments
 (0)