splitio-commons 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. splitio_commons-1.0.0/LICENSE.txt +169 -0
  2. splitio_commons-1.0.0/NOTICE.txt +5 -0
  3. splitio_commons-1.0.0/PKG-INFO +41 -0
  4. splitio_commons-1.0.0/README.md +16 -0
  5. splitio_commons-1.0.0/setup.cfg +32 -0
  6. splitio_commons-1.0.0/setup.py +66 -0
  7. splitio_commons-1.0.0/splitio_commons/__init__.py +0 -0
  8. splitio_commons-1.0.0/splitio_commons/api/__init__.py +46 -0
  9. splitio_commons-1.0.0/splitio_commons/api/auth.py +111 -0
  10. splitio_commons-1.0.0/splitio_commons/api/client.py +358 -0
  11. splitio_commons-1.0.0/splitio_commons/api/commons.py +156 -0
  12. splitio_commons-1.0.0/splitio_commons/api/definitions.py +152 -0
  13. splitio_commons-1.0.0/splitio_commons/api/events.py +129 -0
  14. splitio_commons-1.0.0/splitio_commons/api/impressions.py +228 -0
  15. splitio_commons-1.0.0/splitio_commons/api/segments.py +144 -0
  16. splitio_commons-1.0.0/splitio_commons/api/telemetry.py +187 -0
  17. splitio_commons-1.0.0/splitio_commons/api/util.py +53 -0
  18. splitio_commons-1.0.0/splitio_commons/engine/__init__.py +0 -0
  19. splitio_commons-1.0.0/splitio_commons/engine/cache/__init__.py +0 -0
  20. splitio_commons-1.0.0/splitio_commons/engine/cache/lru.py +121 -0
  21. splitio_commons-1.0.0/splitio_commons/engine/evaluator.py +259 -0
  22. splitio_commons-1.0.0/splitio_commons/engine/filters.py +85 -0
  23. splitio_commons-1.0.0/splitio_commons/engine/hashfns/__init__.py +45 -0
  24. splitio_commons-1.0.0/splitio_commons/engine/hashfns/legacy.py +28 -0
  25. splitio_commons-1.0.0/splitio_commons/engine/hashfns/murmur3py.py +201 -0
  26. splitio_commons-1.0.0/splitio_commons/engine/impressions/__init__.py +0 -0
  27. splitio_commons-1.0.0/splitio_commons/engine/impressions/adapters.py +397 -0
  28. splitio_commons-1.0.0/splitio_commons/engine/impressions/impressions.py +55 -0
  29. splitio_commons-1.0.0/splitio_commons/engine/impressions/manager.py +155 -0
  30. splitio_commons-1.0.0/splitio_commons/engine/impressions/strategies.py +105 -0
  31. splitio_commons-1.0.0/splitio_commons/engine/impressions/unique_keys_tracker.py +168 -0
  32. splitio_commons-1.0.0/splitio_commons/engine/splitters.py +67 -0
  33. splitio_commons-1.0.0/splitio_commons/engine/telemetry.py +687 -0
  34. splitio_commons-1.0.0/splitio_commons/events/__init__.py +25 -0
  35. splitio_commons-1.0.0/splitio_commons/events/events_delivery.py +28 -0
  36. splitio_commons-1.0.0/splitio_commons/events/events_manager.py +288 -0
  37. splitio_commons-1.0.0/splitio_commons/events/events_manager_config.py +113 -0
  38. splitio_commons-1.0.0/splitio_commons/events/events_metadata.py +35 -0
  39. splitio_commons-1.0.0/splitio_commons/events/events_task.py +146 -0
  40. splitio_commons-1.0.0/splitio_commons/models/__init__.py +71 -0
  41. splitio_commons-1.0.0/splitio_commons/models/configs.py +122 -0
  42. splitio_commons-1.0.0/splitio_commons/models/datatypes.py +66 -0
  43. splitio_commons-1.0.0/splitio_commons/models/definitions.py +280 -0
  44. splitio_commons-1.0.0/splitio_commons/models/events.py +41 -0
  45. splitio_commons-1.0.0/splitio_commons/models/fallback_config.py +100 -0
  46. splitio_commons-1.0.0/splitio_commons/models/fallback_treatment.py +34 -0
  47. splitio_commons-1.0.0/splitio_commons/models/grammar/__init__.py +0 -0
  48. splitio_commons-1.0.0/splitio_commons/models/grammar/condition.py +136 -0
  49. splitio_commons-1.0.0/splitio_commons/models/grammar/matchers/__init__.py +82 -0
  50. splitio_commons-1.0.0/splitio_commons/models/grammar/matchers/base.py +122 -0
  51. splitio_commons-1.0.0/splitio_commons/models/grammar/matchers/keys.py +86 -0
  52. splitio_commons-1.0.0/splitio_commons/models/grammar/matchers/misc.py +99 -0
  53. splitio_commons-1.0.0/splitio_commons/models/grammar/matchers/numeric.py +256 -0
  54. splitio_commons-1.0.0/splitio_commons/models/grammar/matchers/prerequisites.py +38 -0
  55. splitio_commons-1.0.0/splitio_commons/models/grammar/matchers/rule_based_segment.py +72 -0
  56. splitio_commons-1.0.0/splitio_commons/models/grammar/matchers/semver.py +260 -0
  57. splitio_commons-1.0.0/splitio_commons/models/grammar/matchers/sets.py +208 -0
  58. splitio_commons-1.0.0/splitio_commons/models/grammar/matchers/string.py +274 -0
  59. splitio_commons-1.0.0/splitio_commons/models/grammar/matchers/utils/__init__.py +0 -0
  60. splitio_commons-1.0.0/splitio_commons/models/grammar/matchers/utils/utils.py +168 -0
  61. splitio_commons-1.0.0/splitio_commons/models/grammar/partitions.py +55 -0
  62. splitio_commons-1.0.0/splitio_commons/models/impressions.py +69 -0
  63. splitio_commons-1.0.0/splitio_commons/models/key.py +20 -0
  64. splitio_commons-1.0.0/splitio_commons/models/notification.py +227 -0
  65. splitio_commons-1.0.0/splitio_commons/models/rule_based_segments.py +194 -0
  66. splitio_commons-1.0.0/splitio_commons/models/segments.py +86 -0
  67. splitio_commons-1.0.0/splitio_commons/models/splits.py +120 -0
  68. splitio_commons-1.0.0/splitio_commons/models/telemetry.py +1955 -0
  69. splitio_commons-1.0.0/splitio_commons/models/token.py +92 -0
  70. splitio_commons-1.0.0/splitio_commons/optional/__init__.py +0 -0
  71. splitio_commons-1.0.0/splitio_commons/optional/loaders.py +30 -0
  72. splitio_commons-1.0.0/splitio_commons/push/__init__.py +13 -0
  73. splitio_commons-1.0.0/splitio_commons/push/manager.py +461 -0
  74. splitio_commons-1.0.0/splitio_commons/push/parser.py +638 -0
  75. splitio_commons-1.0.0/splitio_commons/push/processor.py +152 -0
  76. splitio_commons-1.0.0/splitio_commons/push/splitsse.py +255 -0
  77. splitio_commons-1.0.0/splitio_commons/push/sse.py +233 -0
  78. splitio_commons-1.0.0/splitio_commons/push/status_tracker.py +359 -0
  79. splitio_commons-1.0.0/splitio_commons/push/workers.py +174 -0
  80. splitio_commons-1.0.0/splitio_commons/recorder/__init__.py +0 -0
  81. splitio_commons-1.0.0/splitio_commons/recorder/recorder.py +430 -0
  82. splitio_commons-1.0.0/splitio_commons/storage/__init__.py +424 -0
  83. splitio_commons-1.0.0/splitio_commons/storage/adapters/__init__.py +0 -0
  84. splitio_commons-1.0.0/splitio_commons/storage/adapters/cache_trait.py +257 -0
  85. splitio_commons-1.0.0/splitio_commons/storage/adapters/redis.py +974 -0
  86. splitio_commons-1.0.0/splitio_commons/storage/adapters/util.py +94 -0
  87. splitio_commons-1.0.0/splitio_commons/storage/inmemmory.py +2256 -0
  88. splitio_commons-1.0.0/splitio_commons/storage/pluggable.py +1834 -0
  89. splitio_commons-1.0.0/splitio_commons/storage/redis.py +1799 -0
  90. splitio_commons-1.0.0/splitio_commons/sync/__init__.py +0 -0
  91. splitio_commons-1.0.0/splitio_commons/sync/auth.py +216 -0
  92. splitio_commons-1.0.0/splitio_commons/sync/definition.py +375 -0
  93. splitio_commons-1.0.0/splitio_commons/sync/event.py +129 -0
  94. splitio_commons-1.0.0/splitio_commons/sync/impression.py +191 -0
  95. splitio_commons-1.0.0/splitio_commons/sync/manager.py +323 -0
  96. splitio_commons-1.0.0/splitio_commons/sync/segment.py +646 -0
  97. splitio_commons-1.0.0/splitio_commons/sync/synchronizer.py +1215 -0
  98. splitio_commons-1.0.0/splitio_commons/sync/telemetry.py +172 -0
  99. splitio_commons-1.0.0/splitio_commons/sync/unique_keys.py +144 -0
  100. splitio_commons-1.0.0/splitio_commons/sync/util.py +68 -0
  101. splitio_commons-1.0.0/splitio_commons/tasks/__init__.py +31 -0
  102. splitio_commons-1.0.0/splitio_commons/tasks/events_sync.py +76 -0
  103. splitio_commons-1.0.0/splitio_commons/tasks/impressions_sync.py +141 -0
  104. splitio_commons-1.0.0/splitio_commons/tasks/segment_sync.py +65 -0
  105. splitio_commons-1.0.0/splitio_commons/tasks/telemetry_sync.py +74 -0
  106. splitio_commons-1.0.0/splitio_commons/tasks/unique_keys_sync.py +137 -0
  107. splitio_commons-1.0.0/splitio_commons/tasks/util/__init__.py +0 -0
  108. splitio_commons-1.0.0/splitio_commons/tasks/util/asynctask.py +320 -0
  109. splitio_commons-1.0.0/splitio_commons/tasks/util/workerpool.py +229 -0
  110. splitio_commons-1.0.0/splitio_commons/util/__init__.py +0 -0
  111. splitio_commons-1.0.0/splitio_commons/util/backoff.py +36 -0
  112. splitio_commons-1.0.0/splitio_commons/util/decorators.py +15 -0
  113. splitio_commons-1.0.0/splitio_commons/util/input_validator.py +746 -0
  114. splitio_commons-1.0.0/splitio_commons/util/storage_helper.py +201 -0
  115. splitio_commons-1.0.0/splitio_commons/util/threadutil.py +51 -0
  116. splitio_commons-1.0.0/splitio_commons/util/time.py +33 -0
  117. splitio_commons-1.0.0/splitio_commons/version.py +1 -0
  118. splitio_commons-1.0.0/splitio_commons.egg-info/PKG-INFO +41 -0
  119. splitio_commons-1.0.0/splitio_commons.egg-info/SOURCES.txt +121 -0
  120. splitio_commons-1.0.0/splitio_commons.egg-info/dependency_links.txt +1 -0
  121. splitio_commons-1.0.0/splitio_commons.egg-info/requires.txt +39 -0
  122. splitio_commons-1.0.0/splitio_commons.egg-info/top_level.txt +1 -0
@@ -0,0 +1,169 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
5
+ 1. Definitions.
6
+ "License" shall mean the terms and conditions for use, reproduction,
7
+ and distribution as defined by Sections 1 through 9 of this document.
8
+ "Licensor" shall mean the copyright owner or entity authorized by
9
+ the copyright owner that is granting the License.
10
+ "Legal Entity" shall mean the union of the acting entity and all
11
+ other entities that control, are controlled by, or are under common
12
+ control with that entity. For the purposes of this definition,
13
+ "control" means (i) the power, direct or indirect, to cause the
14
+ direction or management of such entity, whether by contract or
15
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
16
+ outstanding shares, or (iii) beneficial ownership of such entity.
17
+ "You" (or "Your") shall mean an individual or Legal Entity
18
+ exercising permissions granted by this License.
19
+ "Source" form shall mean the preferred form for making modifications,
20
+ including but not limited to software source code, documentation
21
+ source, and configuration files.
22
+ "Object" form shall mean any form resulting from mechanical
23
+ transformation or translation of a Source form, including but
24
+ not limited to compiled object code, generated documentation,
25
+ and conversions to other media types.
26
+ "Work" shall mean the work of authorship, whether in Source or
27
+ Object form, made available under the License, as indicated by a
28
+ copyright notice that is included in or attached to the work
29
+ (an example is provided in the Appendix below).
30
+ "Derivative Works" shall mean any work, whether in Source or Object
31
+ form, that is based on (or derived from) the Work and for which the
32
+ editorial revisions, annotations, elaborations, or other modifications
33
+ represent, as a whole, an original work of authorship. For the purposes
34
+ of this License, Derivative Works shall not include works that remain
35
+ separable from, or merely link (or bind by name) to the interfaces of,
36
+ the Work and Derivative Works thereof.
37
+ "Contribution" shall mean any work of authorship, including
38
+ the original version of the Work and any modifications or additions
39
+ to that Work or Derivative Works thereof, that is intentionally
40
+ submitted to Licensor for inclusion in the Work by the copyright owner
41
+ or by an individual or Legal Entity authorized to submit on behalf of
42
+ the copyright owner. For the purposes of this definition, "submitted"
43
+ means any form of electronic, verbal, or written communication sent
44
+ to the Licensor or its representatives, including but not limited to
45
+ communication on electronic mailing lists, source code control systems,
46
+ and issue tracking systems that are managed by, or on behalf of, the
47
+ Licensor for the purpose of discussing and improving the Work, but
48
+ excluding communication that is conspicuously marked or otherwise
49
+ designated in writing by the copyright owner as "Not a Contribution."
50
+ "Contributor" shall mean Licensor and any individual or Legal Entity
51
+ on behalf of whom a Contribution has been received by Licensor and
52
+ subsequently incorporated within the Work.
53
+ 2. Grant of Copyright License. Subject to the terms and conditions of
54
+ this License, each Contributor hereby grants to You a perpetual,
55
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
56
+ copyright license to reproduce, prepare Derivative Works of,
57
+ publicly display, publicly perform, sublicense, and distribute the
58
+ Work and such Derivative Works in Source or Object form.
59
+ 3. Grant of Patent License. Subject to the terms and conditions of
60
+ this License, each Contributor hereby grants to You a perpetual,
61
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
62
+ (except as stated in this section) patent license to make, have made,
63
+ use, offer to sell, sell, import, and otherwise transfer the Work,
64
+ where such license applies only to those patent claims licensable
65
+ by such Contributor that are necessarily infringed by their
66
+ Contribution(s) alone or by combination of their Contribution(s)
67
+ with the Work to which such Contribution(s) was submitted. If You
68
+ institute patent litigation against any entity (including a
69
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
70
+ or a Contribution incorporated within the Work constitutes direct
71
+ or contributory patent infringement, then any patent licenses
72
+ granted to You under this License for that Work shall terminate
73
+ as of the date such litigation is filed.
74
+ 4. Redistribution. You may reproduce and distribute copies of the
75
+ Work or Derivative Works thereof in any medium, with or without
76
+ modifications, and in Source or Object form, provided that You
77
+ meet the following conditions:
78
+ (a) You must give any other recipients of the Work or
79
+ Derivative Works a copy of this License; and
80
+ (b) You must cause any modified files to carry prominent notices
81
+ stating that You changed the files; and
82
+ (c) You must retain, in the Source form of any Derivative Works
83
+ that You distribute, all copyright, patent, trademark, and
84
+ attribution notices from the Source form of the Work,
85
+ excluding those notices that do not pertain to any part of
86
+ the Derivative Works; and
87
+ (d) If the Work includes a "NOTICE" text file as part of its
88
+ distribution, then any Derivative Works that You distribute must
89
+ include a readable copy of the attribution notices contained
90
+ within such NOTICE file, excluding those notices that do not
91
+ pertain to any part of the Derivative Works, in at least one
92
+ of the following places: within a NOTICE text file distributed
93
+ as part of the Derivative Works; within the Source form or
94
+ documentation, if provided along with the Derivative Works; or,
95
+ within a display generated by the Derivative Works, if and
96
+ wherever such third-party notices normally appear. The contents
97
+ of the NOTICE file are for informational purposes only and
98
+ do not modify the License. You may add Your own attribution
99
+ notices within Derivative Works that You distribute, alongside
100
+ or as an addendum to the NOTICE text from the Work, provided
101
+ that such additional attribution notices cannot be construed
102
+ as modifying the License.
103
+ You may add Your own copyright statement to Your modifications and
104
+ may provide additional or different license terms and conditions
105
+ for use, reproduction, or distribution of Your modifications, or
106
+ for any such Derivative Works as a whole, provided Your use,
107
+ reproduction, and distribution of the Work otherwise complies with
108
+ the conditions stated in this License.
109
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
110
+ any Contribution intentionally submitted for inclusion in the Work
111
+ by You to the Licensor shall be under the terms and conditions of
112
+ this License, without any additional terms or conditions.
113
+ Notwithstanding the above, nothing herein shall supersede or modify
114
+ the terms of any separate license agreement you may have executed
115
+ with Licensor regarding such Contributions.
116
+ 6. Trademarks. This License does not grant permission to use the trade
117
+ names, trademarks, service marks, or product names of the Licensor,
118
+ except as required for reasonable and customary use in describing the
119
+ origin of the Work and reproducing the content of the NOTICE file.
120
+ 7. Disclaimer of Warranty. Unless required by applicable law or
121
+ agreed to in writing, Licensor provides the Work (and each
122
+ Contributor provides its Contributions) on an "AS IS" BASIS,
123
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
124
+ implied, including, without limitation, any warranties or conditions
125
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
126
+ PARTICULAR PURPOSE. You are solely responsible for determining the
127
+ appropriateness of using or redistributing the Work and assume any
128
+ risks associated with Your exercise of permissions under this License.
129
+ 8. Limitation of Liability. In no event and under no legal theory,
130
+ whether in tort (including negligence), contract, or otherwise,
131
+ unless required by applicable law (such as deliberate and grossly
132
+ negligent acts) or agreed to in writing, shall any Contributor be
133
+ liable to You for damages, including any direct, indirect, special,
134
+ incidental, or consequential damages of any character arising as a
135
+ result of this License or out of the use or inability to use the
136
+ Work (including but not limited to damages for loss of goodwill,
137
+ work stoppage, computer failure or malfunction, or any and all
138
+ other commercial damages or losses), even if such Contributor
139
+ has been advised of the possibility of such damages.
140
+ 9. Accepting Warranty or Additional Liability. While redistributing
141
+ the Work or Derivative Works thereof, You may choose to offer,
142
+ and charge a fee for, acceptance of support, warranty, indemnity,
143
+ or other liability obligations and/or rights consistent with this
144
+ License. However, in accepting such obligations, You may act only
145
+ on Your own behalf and on Your sole responsibility, not on behalf
146
+ of any other Contributor, and only if You agree to indemnify,
147
+ defend, and hold each Contributor harmless for any liability
148
+ incurred by, or claims asserted against, such Contributor by reason
149
+ of your accepting any such warranty or additional liability.
150
+ END OF TERMS AND CONDITIONS
151
+ APPENDIX: How to apply the Apache License to your work.
152
+ To apply the Apache License to your work, attach the following
153
+ boilerplate notice, with the fields enclosed by brackets "[]"
154
+ replaced with your own identifying information. (Don't include
155
+ the brackets!) The text should be enclosed in the appropriate
156
+ comment syntax for the file format. We also recommend that a
157
+ file or class name and description of purpose be included on the
158
+ same "printed page" as the copyright notice for easier
159
+ identification within third-party archives.
160
+ Copyright 2026 Harness Inc
161
+ Licensed under the Apache License, Version 2.0 (the "License");
162
+ you may not use this file except in compliance with the License.
163
+ You may obtain a copy of the License at
164
+ http://www.apache.org/licenses/LICENSE-2.0
165
+ Unless required by applicable law or agreed to in writing, software
166
+ distributed under the License is distributed on an "AS IS" BASIS,
167
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
168
+ See the License for the specific language governing permissions and
169
+ limitations under the License.
@@ -0,0 +1,5 @@
1
+ Harness Feature Management Python Commons Copyright 2024-2026 Harness Inc.
2
+
3
+ This product includes software developed at Harness Inc. (https://harness.io/).
4
+
5
+ This product includes software originally developed by Split Software, Inc. (https://www.split.io/). Copyright 2015-2024 Split Software, Inc.
@@ -0,0 +1,41 @@
1
+ Metadata-Version: 2.1
2
+ Name: splitio_commons
3
+ Version: 1.0.0
4
+ Summary: Splitio Python Commons
5
+ Home-page: https://github.com/splitio/python-commons
6
+ Download-URL: https://github.com/splitio/python-commons/tarball/1.0.0
7
+ Author: Bilal Al-Shahwany
8
+ Author-email: bilal.al-shahwany@harness.io
9
+ License: Apache License 2.0
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: Programming Language :: Python
13
+ Classifier: Programming Language :: Python :: 2
14
+ Classifier: Programming Language :: Python :: 3
15
+ Classifier: Topic :: Software Development :: Libraries
16
+ Description-Content-Type: text/markdown
17
+ Provides-Extra: test
18
+ Provides-Extra: redis
19
+ Provides-Extra: uwsgi
20
+ Provides-Extra: cpphash
21
+ Provides-Extra: asyncio
22
+ Provides-Extra: kerberos
23
+ License-File: LICENSE.txt
24
+ License-File: NOTICE.txt
25
+
26
+ # Python Commons
27
+
28
+ ## Overview
29
+ This Library is designed to work with Harness FME Python SDK, the platform for controlled rollouts, which serves features to your users via a Split definition to manage your complete customer experience.
30
+
31
+ ## Compatibility
32
+ This Library is compatible with **Python 3.7 and higher**.
33
+
34
+ ## Getting started
35
+
36
+ ## Submitting issues
37
+
38
+ ## Contributing
39
+
40
+ ## License
41
+ Licensed under the Apache License, Version 2.0. See: [Apache License](http://www.apache.org/licenses/).
@@ -0,0 +1,16 @@
1
+ # Python Commons
2
+
3
+ ## Overview
4
+ This Library is designed to work with Harness FME Python SDK, the platform for controlled rollouts, which serves features to your users via a Split definition to manage your complete customer experience.
5
+
6
+ ## Compatibility
7
+ This Library is compatible with **Python 3.7 and higher**.
8
+
9
+ ## Getting started
10
+
11
+ ## Submitting issues
12
+
13
+ ## Contributing
14
+
15
+ ## License
16
+ Licensed under the Apache License, Version 2.0. See: [Apache License](http://www.apache.org/licenses/).
@@ -0,0 +1,32 @@
1
+ [wheel]
2
+ universal = 1
3
+
4
+ [metadata]
5
+ name = splitio_commons
6
+ description = This SDK is designed to work with Split, the platform for controlled rollouts, which serves features to your users via a Split definition to manage your complete customer experience.
7
+ long_description = file: README.md
8
+ long_description_content_type = text/markdown
9
+
10
+ [flake8]
11
+ max-line-length = 100
12
+ exclude = tests/*
13
+
14
+ [aliases]
15
+ test = pytest
16
+
17
+ [tool:pytest]
18
+ addopts = --verbose --cov=splitio_commons --cov-report xml
19
+ python_classes = *Tests
20
+
21
+ [build_sphinx]
22
+ source-dir = doc/source
23
+ build-dir = doc/build
24
+ all_files = 1
25
+
26
+ [upload_sphinx]
27
+ upload-dir = doc/build/html
28
+
29
+ [egg_info]
30
+ tag_build =
31
+ tag_date = 0
32
+
@@ -0,0 +1,66 @@
1
+ """Setup module."""
2
+ # !/usr/bin/env python
3
+
4
+ from os import path
5
+ from setuptools import setup, find_packages
6
+ import subprocess
7
+ import sys
8
+
9
+ TESTS_REQUIRES = [
10
+ 'flake8',
11
+ 'pytest==7.0.1',
12
+ 'pytest-mock==3.11.1',
13
+ 'coverage==7.0.0',
14
+ 'pytest-cov==4.1.0',
15
+ 'importlib-metadata==6.7',
16
+ 'tomli==1.2.3',
17
+ 'iniconfig==1.1.1',
18
+ 'attrs==22.1.0',
19
+ 'pytest-asyncio==0.21.0',
20
+ 'aiohttp>=3.8.4',
21
+ 'aiofiles>=23.1.0',
22
+ 'requests-kerberos>=0.15.0',
23
+ 'urllib3==2.0.7'
24
+ ]
25
+
26
+ INSTALL_REQUIRES = [
27
+ 'requests',
28
+ 'pyyaml',
29
+ 'docopt>=0.6.2',
30
+ 'enum34;python_version<"3.4"',
31
+ 'bloom-filter2>=2.0.0'
32
+ ]
33
+
34
+ with open(path.join(path.abspath(path.dirname(__file__)), 'splitio_commons', 'version.py')) as f:
35
+ exec(f.read()) # pylint: disable=exec-used
36
+
37
+ setup(
38
+ name='splitio_commons',
39
+ version=__version__, # pylint: disable=undefined-variable
40
+ description='Splitio Python Commons',
41
+ author='Bilal Al-Shahwany',
42
+ author_email='bilal.al-shahwany@harness.io',
43
+ url='https://github.com/splitio/python-commons',
44
+ download_url=('https://github.com/splitio/python-commons/tarball/' + __version__), # pylint: disable=undefined-variable
45
+ license='Apache License 2.0',
46
+ install_requires=INSTALL_REQUIRES,
47
+ tests_require=TESTS_REQUIRES,
48
+ extras_require={
49
+ 'test': TESTS_REQUIRES,
50
+ 'redis': ['redis>=2.10.5,<7.0.0'],
51
+ 'uwsgi': ['uwsgi>=2.0.0'],
52
+ 'cpphash': ['mmh3cffi==0.2.1'],
53
+ 'asyncio': ['aiohttp>=3.8.4', 'aiofiles>=23.1.0'],
54
+ 'kerberos': ['requests-kerberos>=0.15.0']
55
+ },
56
+ setup_requires=['pytest-runner', 'pluggy==1.0.0;python_version<"3.8"'],
57
+ classifiers=[
58
+ 'Environment :: Console',
59
+ 'Intended Audience :: Developers',
60
+ 'Programming Language :: Python',
61
+ 'Programming Language :: Python :: 2',
62
+ 'Programming Language :: Python :: 3',
63
+ 'Topic :: Software Development :: Libraries'
64
+ ],
65
+ packages=find_packages(exclude=('tests', 'tests.*'))
66
+ )
File without changes
@@ -0,0 +1,46 @@
1
+ """Split API module."""
2
+
3
+
4
+ class APIException(Exception):
5
+ """Exception to raise when an API call fails."""
6
+
7
+ def __init__(self, custom_message, status_code=None):
8
+ """Constructor."""
9
+ Exception.__init__(self, custom_message)
10
+ self._status_code = status_code if status_code else -1
11
+
12
+ @property
13
+ def status_code(self):
14
+ """Return HTTP status code."""
15
+ return self._status_code
16
+
17
+ class APIUriException(APIException):
18
+ """Exception to raise when an API call fails due to 414 http error."""
19
+
20
+ def __init__(self, custom_message, status_code=None):
21
+ """Constructor."""
22
+ APIException.__init__(self, custom_message, status_code)
23
+
24
+ def headers_from_metadata(sdk_metadata, client_key=None):
25
+ """
26
+ Generate a dict with headers required by data-recording API endpoints.
27
+ :param sdk_metadata: SDK Metadata object, generated at sdk initialization time.
28
+ :type sdk_metadata: splitio_commons.client.util.SdkMetadata
29
+ :param client_key: client key.
30
+ :type client_key: str
31
+ :return: A dictionary with headers.
32
+ :rtype: dict
33
+ """
34
+
35
+ metadata = {
36
+ 'SplitSDKVersion': sdk_metadata.sdk_version,
37
+ 'SplitSDKMachineIP': sdk_metadata.instance_ip,
38
+ 'SplitSDKMachineName': sdk_metadata.instance_name
39
+ } if sdk_metadata.instance_ip != 'NA' and sdk_metadata.instance_ip != 'unknown' else {
40
+ 'SplitSDKVersion': sdk_metadata.sdk_version,
41
+ }
42
+
43
+ if client_key is not None:
44
+ metadata['SplitSDKClientKey'] = client_key
45
+
46
+ return metadata
@@ -0,0 +1,111 @@
1
+ """Auth API module."""
2
+
3
+ import logging
4
+ import json
5
+
6
+ from splitio_commons.api import APIException, headers_from_metadata
7
+ from splitio_commons.api.commons import headers_from_metadata, record_telemetry
8
+ from splitio_commons.util.time import get_current_epoch_time_ms
9
+ from splitio_commons.api.client import HttpClientException
10
+ from splitio_commons.models.token import from_raw
11
+ from splitio_commons.models.telemetry import HTTPExceptionsAndLatencies
12
+
13
+ _LOGGER = logging.getLogger(__name__)
14
+
15
+
16
+ class AuthAPI(object): # pylint: disable=too-few-public-methods
17
+ """Class that uses an httpClient to communicate with the SDK Auth Service API."""
18
+
19
+ def __init__(self, client, sdk_key, sdk_metadata, telemetry_runtime_producer, spec_version):
20
+ """
21
+ Class constructor.
22
+
23
+ :param client: HTTP Client responsble for issuing calls to the backend.
24
+ :type client: HttpClient
25
+ :param sdk_key: User sdk key.
26
+ :type sdk_key: string
27
+ :param sdk_metadata: SDK version & machine name & IP.
28
+ :type sdk_metadata: splitio_commons.client.util.SdkMetadata
29
+ """
30
+ self._client = client
31
+ self._sdk_key = sdk_key
32
+ self._metadata = headers_from_metadata(sdk_metadata)
33
+ self._telemetry_runtime_producer = telemetry_runtime_producer
34
+ self._client.set_telemetry_data(HTTPExceptionsAndLatencies.TOKEN, self._telemetry_runtime_producer)
35
+ self._spec_version = spec_version
36
+
37
+ def authenticate(self):
38
+ """
39
+ Perform authentication.
40
+
41
+ :return: Json representation of an authentication.
42
+ :rtype: splitio_commons.models.token.Token
43
+ """
44
+ try:
45
+ response = self._client.get(
46
+ 'auth',
47
+ 'v2/auth?s=' + self._spec_version if self._spec_version != None else 'v2/auth',
48
+ self._sdk_key,
49
+ extra_headers=self._metadata,
50
+ )
51
+ if 200 <= response.status_code < 300:
52
+ payload = json.loads(response.body)
53
+ return from_raw(payload)
54
+
55
+ else:
56
+ if (response.status_code >= 400 and response.status_code < 500):
57
+ self._telemetry_runtime_producer.record_auth_rejections()
58
+ raise APIException(response.body, response.status_code)
59
+ except HttpClientException as exc:
60
+ _LOGGER.error('Exception raised while authenticating')
61
+ _LOGGER.debug('Exception information: ', exc_info=True)
62
+ raise APIException('Could not perform authentication.') from exc
63
+
64
+ class AuthAPIAsync(object): # pylint: disable=too-few-public-methods
65
+ """Async Class that uses an httpClient to communicate with the SDK Auth Service API."""
66
+
67
+ def __init__(self, client, sdk_key, sdk_metadata, telemetry_runtime_producer, spec_version):
68
+ """
69
+ Class constructor.
70
+
71
+ :param client: HTTP Client responsble for issuing calls to the backend.
72
+ :type client: HttpClient
73
+ :param sdk_key: User sdk key.
74
+ :type sdk_key: string
75
+ :param sdk_metadata: SDK version & machine name & IP.
76
+ :type sdk_metadata: splitio_commons.client.util.SdkMetadata
77
+ """
78
+ self._client = client
79
+ self._sdk_key = sdk_key
80
+ self._metadata = headers_from_metadata(sdk_metadata)
81
+ self._telemetry_runtime_producer = telemetry_runtime_producer
82
+ self._client.set_telemetry_data(HTTPExceptionsAndLatencies.TOKEN, self._telemetry_runtime_producer)
83
+ self._spec_version = spec_version
84
+
85
+ async def authenticate(self):
86
+ """
87
+ Perform authentication.
88
+
89
+ :return: Json representation of an authentication.
90
+ :rtype: splitio_commons.models.token.Token
91
+ """
92
+ try:
93
+ response = await self._client.get(
94
+ 'auth',
95
+ 'v2/auth?s=' + self._spec_version if self._spec_version != None else 'v2/auth',
96
+ self._sdk_key,
97
+ extra_headers=self._metadata,
98
+ )
99
+ if 200 <= response.status_code < 300:
100
+ payload = json.loads(response.body)
101
+ _LOGGER.debug(payload)
102
+ return from_raw(payload)
103
+
104
+ else:
105
+ if (response.status_code >= 400 and response.status_code < 500):
106
+ await self._telemetry_runtime_producer.record_auth_rejections()
107
+ raise APIException(response.body, response.status_code)
108
+ except HttpClientException as exc:
109
+ _LOGGER.error('Exception raised while authenticating')
110
+ _LOGGER.debug('Exception information: ', exc_info=True)
111
+ raise APIException('Could not perform authentication.') from exc