frogml-inference 0.0.1__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.
- frogml_inference-0.0.1/LICENSE +194 -0
- frogml_inference-0.0.1/PKG-INFO +38 -0
- frogml_inference-0.0.1/README.md +4 -0
- frogml_inference-0.0.1/frogml_inference/__init__.py +22 -0
- frogml_inference-0.0.1/frogml_inference/authentication/__init__.py +0 -0
- frogml_inference-0.0.1/frogml_inference/authentication/_login_arguments.py +22 -0
- frogml_inference-0.0.1/frogml_inference/authentication/_utils.py +20 -0
- frogml_inference-0.0.1/frogml_inference/authentication/authentication_utils.py +198 -0
- frogml_inference-0.0.1/frogml_inference/authentication/constants.py +12 -0
- frogml_inference-0.0.1/frogml_inference/batch_client/__init__.py +0 -0
- frogml_inference-0.0.1/frogml_inference/batch_client/batch_client.py +762 -0
- frogml_inference-0.0.1/frogml_inference/batch_client/cloud_provider_client.py +130 -0
- frogml_inference-0.0.1/frogml_inference/batch_client/file_serialization.py +94 -0
- frogml_inference-0.0.1/frogml_inference/batch_client/instance_validation.py +36 -0
- frogml_inference-0.0.1/frogml_inference/batch_client/s3.py +40 -0
- frogml_inference-0.0.1/frogml_inference/configuration/__init__.py +4 -0
- frogml_inference-0.0.1/frogml_inference/configuration/account.py +43 -0
- frogml_inference-0.0.1/frogml_inference/configuration/auth.py +124 -0
- frogml_inference-0.0.1/frogml_inference/configuration/auth_config.py +70 -0
- frogml_inference-0.0.1/frogml_inference/configuration/log_config.py +47 -0
- frogml_inference-0.0.1/frogml_inference/configuration/session.py +31 -0
- frogml_inference-0.0.1/frogml_inference/constants.py +24 -0
- frogml_inference-0.0.1/frogml_inference/exceptions.py +48 -0
- frogml_inference-0.0.1/frogml_inference/realtime_client/__init__.py +4 -0
- frogml_inference-0.0.1/frogml_inference/realtime_client/client.py +193 -0
- frogml_inference-0.0.1/frogml_inference/realtime_client/rest_helpers.py +87 -0
- frogml_inference-0.0.1/pyproject.toml +68 -0
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
==============
|
|
3
|
+
|
|
4
|
+
_Version 2.0, January 2004_
|
|
5
|
+
_<<http://www.apache.org/licenses/>>_
|
|
6
|
+
|
|
7
|
+
### Terms and Conditions for use, reproduction, and distribution
|
|
8
|
+
|
|
9
|
+
#### 1. Definitions
|
|
10
|
+
|
|
11
|
+
“License” shall mean the terms and conditions for use, reproduction, and
|
|
12
|
+
distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
“Licensor” shall mean the copyright owner or entity authorized by the copyright
|
|
15
|
+
owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
“Legal Entity” shall mean the union of the acting entity and all other entities
|
|
18
|
+
that control, are controlled by, or are under common control with that entity.
|
|
19
|
+
For the purposes of this definition, “control” means **(i)** the power, direct or
|
|
20
|
+
indirect, to cause the direction or management of such entity, whether by
|
|
21
|
+
contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or **(iii)** beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
“You” (or “Your”) shall mean an individual or Legal Entity exercising
|
|
25
|
+
permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
“Source” form shall mean the preferred form for making modifications, including
|
|
28
|
+
but not limited to software source code, documentation source, and configuration
|
|
29
|
+
files.
|
|
30
|
+
|
|
31
|
+
“Object” form shall mean any form resulting from mechanical transformation or
|
|
32
|
+
translation of a Source form, including but not limited to compiled object code,
|
|
33
|
+
generated documentation, and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
“Work” shall mean the work of authorship, whether in Source or Object form, made
|
|
36
|
+
available under the License, as indicated by a copyright notice that is included
|
|
37
|
+
in or attached to the work (an example is provided in the Appendix below).
|
|
38
|
+
|
|
39
|
+
“Derivative Works” shall mean any work, whether in Source or Object form, that
|
|
40
|
+
is based on (or derived from) the Work and for which the editorial revisions,
|
|
41
|
+
annotations, elaborations, or other modifications represent, as a whole, an
|
|
42
|
+
original work of authorship. For the purposes of this License, Derivative Works
|
|
43
|
+
shall not include works that remain separable from, or merely link (or bind by
|
|
44
|
+
name) to the interfaces of, the Work and Derivative Works thereof.
|
|
45
|
+
|
|
46
|
+
“Contribution” shall mean any work of authorship, including the original version
|
|
47
|
+
of the Work and any modifications or additions to that Work or Derivative Works
|
|
48
|
+
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
|
49
|
+
by the copyright owner or by an individual or Legal Entity authorized to submit
|
|
50
|
+
on behalf of the copyright owner. For the purposes of this definition,
|
|
51
|
+
“submitted” means any form of electronic, verbal, or written communication sent
|
|
52
|
+
to the Licensor or its representatives, including but not limited to
|
|
53
|
+
communication on electronic mailing lists, source code control systems, and
|
|
54
|
+
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
|
55
|
+
the purpose of discussing and improving the Work, but excluding communication
|
|
56
|
+
that is conspicuously marked or otherwise designated in writing by the copyright
|
|
57
|
+
owner as “Not a Contribution.”
|
|
58
|
+
|
|
59
|
+
“Contributor” shall mean Licensor and any individual or Legal Entity on behalf
|
|
60
|
+
of whom a Contribution has been received by Licensor and subsequently
|
|
61
|
+
incorporated within the Work.
|
|
62
|
+
|
|
63
|
+
#### 2. Grant of Copyright License
|
|
64
|
+
|
|
65
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
|
66
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
|
67
|
+
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
|
68
|
+
publicly display, publicly perform, sublicense, and distribute the Work and such
|
|
69
|
+
Derivative Works in Source or Object form.
|
|
70
|
+
|
|
71
|
+
#### 3. Grant of Patent License
|
|
72
|
+
|
|
73
|
+
Subject to the terms and conditions of this License, each Contributor hereby
|
|
74
|
+
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
|
75
|
+
irrevocable (except as stated in this section) patent license to make, have
|
|
76
|
+
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
|
77
|
+
such license applies only to those patent claims licensable by such Contributor
|
|
78
|
+
that are necessarily infringed by their Contribution(s) alone or by combination
|
|
79
|
+
of their Contribution(s) with the Work to which such Contribution(s) was
|
|
80
|
+
submitted. If You institute patent litigation against any entity (including a
|
|
81
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
|
82
|
+
Contribution incorporated within the Work constitutes direct or contributory
|
|
83
|
+
patent infringement, then any patent licenses granted to You under this License
|
|
84
|
+
for that Work shall terminate as of the date such litigation is filed.
|
|
85
|
+
|
|
86
|
+
#### 4. Redistribution
|
|
87
|
+
|
|
88
|
+
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
|
89
|
+
in any medium, with or without modifications, and in Source or Object form,
|
|
90
|
+
provided that You meet the following conditions:
|
|
91
|
+
|
|
92
|
+
* **(a)** You must give any other recipients of the Work or Derivative Works a copy of
|
|
93
|
+
this License; and
|
|
94
|
+
* **(b)** You must cause any modified files to carry prominent notices stating that You
|
|
95
|
+
changed the files; and
|
|
96
|
+
* **(c)** You must retain, in the Source form of any Derivative Works that You distribute,
|
|
97
|
+
all copyright, patent, trademark, and attribution notices from the Source form
|
|
98
|
+
of the Work, excluding those notices that do not pertain to any part of the
|
|
99
|
+
Derivative Works; and
|
|
100
|
+
* **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any
|
|
101
|
+
Derivative Works that You distribute must include a readable copy of the
|
|
102
|
+
attribution notices contained within such NOTICE file, excluding those notices
|
|
103
|
+
that do not pertain to any part of the Derivative Works, in at least one of the
|
|
104
|
+
following places: within a NOTICE text file distributed as part of the
|
|
105
|
+
Derivative Works; within the Source form or documentation, if provided along
|
|
106
|
+
with the Derivative Works; or, within a display generated by the Derivative
|
|
107
|
+
Works, if and wherever such third-party notices normally appear. The contents of
|
|
108
|
+
the NOTICE file are for informational purposes only and do not modify the
|
|
109
|
+
License. You may add Your own attribution notices within Derivative Works that
|
|
110
|
+
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
|
111
|
+
provided that such additional attribution notices cannot be construed as
|
|
112
|
+
modifying the License.
|
|
113
|
+
|
|
114
|
+
You may add Your own copyright statement to Your modifications and may provide
|
|
115
|
+
additional or different license terms and conditions for use, reproduction, or
|
|
116
|
+
distribution of Your modifications, or for any such Derivative Works as a whole,
|
|
117
|
+
provided Your use, reproduction, and distribution of the Work otherwise complies
|
|
118
|
+
with the conditions stated in this License.
|
|
119
|
+
|
|
120
|
+
#### 5. Submission of Contributions
|
|
121
|
+
|
|
122
|
+
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
|
123
|
+
for inclusion in the Work by You to the Licensor shall be under the terms and
|
|
124
|
+
conditions of this License, without any additional terms or conditions.
|
|
125
|
+
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
|
126
|
+
any separate license agreement you may have executed with Licensor regarding
|
|
127
|
+
such Contributions.
|
|
128
|
+
|
|
129
|
+
#### 6. Trademarks
|
|
130
|
+
|
|
131
|
+
This License does not grant permission to use the trade names, trademarks,
|
|
132
|
+
service marks, or product names of the Licensor, except as required for
|
|
133
|
+
reasonable and customary use in describing the origin of the Work and
|
|
134
|
+
reproducing the content of the NOTICE file.
|
|
135
|
+
|
|
136
|
+
#### 7. Disclaimer of Warranty
|
|
137
|
+
|
|
138
|
+
Unless required by applicable law or agreed to in writing, Licensor provides the
|
|
139
|
+
Work (and each Contributor provides its Contributions) on an “AS IS” BASIS,
|
|
140
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
|
141
|
+
including, without limitation, any warranties or conditions of TITLE,
|
|
142
|
+
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
|
143
|
+
solely responsible for determining the appropriateness of using or
|
|
144
|
+
redistributing the Work and assume any risks associated with Your exercise of
|
|
145
|
+
permissions under this License.
|
|
146
|
+
|
|
147
|
+
#### 8. Limitation of Liability
|
|
148
|
+
|
|
149
|
+
In no event and under no legal theory, whether in tort (including negligence),
|
|
150
|
+
contract, or otherwise, unless required by applicable law (such as deliberate
|
|
151
|
+
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
|
152
|
+
liable to You for damages, including any direct, indirect, special, incidental,
|
|
153
|
+
or consequential damages of any character arising as a result of this License or
|
|
154
|
+
out of the use or inability to use the Work (including but not limited to
|
|
155
|
+
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
|
156
|
+
any and all other commercial damages or losses), even if such Contributor has
|
|
157
|
+
been advised of the possibility of such damages.
|
|
158
|
+
|
|
159
|
+
#### 9. Accepting Warranty or Additional Liability
|
|
160
|
+
|
|
161
|
+
While redistributing the Work or Derivative Works thereof, You may choose to
|
|
162
|
+
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
|
163
|
+
other liability obligations and/or rights consistent with this License. However,
|
|
164
|
+
in accepting such obligations, You may act only on Your own behalf and on Your
|
|
165
|
+
sole responsibility, not on behalf of any other Contributor, and only if You
|
|
166
|
+
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
|
167
|
+
incurred by, or claims asserted against, such Contributor by reason of your
|
|
168
|
+
accepting any such warranty or additional liability.
|
|
169
|
+
|
|
170
|
+
_END OF TERMS AND CONDITIONS_
|
|
171
|
+
|
|
172
|
+
### APPENDIX: How to apply the Apache License to your work
|
|
173
|
+
|
|
174
|
+
To apply the Apache License to your work, attach the following boilerplate
|
|
175
|
+
notice, with the fields enclosed by brackets `[]` replaced with your own
|
|
176
|
+
identifying information. (Don't include the brackets!) The text should be
|
|
177
|
+
enclosed in the appropriate comment syntax for the file format. We also
|
|
178
|
+
recommend that a file or class name and description of purpose be included on
|
|
179
|
+
the same “printed page” as the copyright notice for easier identification within
|
|
180
|
+
third-party archives.
|
|
181
|
+
|
|
182
|
+
Copyright [yyyy] [name of copyright owner]
|
|
183
|
+
|
|
184
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
185
|
+
you may not use this file except in compliance with the License.
|
|
186
|
+
You may obtain a copy of the License at
|
|
187
|
+
|
|
188
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
189
|
+
|
|
190
|
+
Unless required by applicable law or agreed to in writing, software
|
|
191
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
192
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
193
|
+
See the License for the specific language governing permissions and
|
|
194
|
+
limitations under the License.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Metadata-Version: 2.3
|
|
2
|
+
Name: frogml-inference
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: FrogML Inference is a Python library for running predictions again Frogml Models.
|
|
5
|
+
License: Apache-2.0
|
|
6
|
+
Keywords: mlops,ml,deployment,serving,model
|
|
7
|
+
Author: JFrog Ltd.
|
|
8
|
+
Author-email: contact@jfrog.com
|
|
9
|
+
Requires-Python: >=3.9,<3.12
|
|
10
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Provides-Extra: batch
|
|
21
|
+
Requires-Dist: boto3 (>=1.24.89,<2.0.0) ; extra == "batch"
|
|
22
|
+
Requires-Dist: frogml (>=1.1.0) ; extra == "batch"
|
|
23
|
+
Requires-Dist: google-cloud-storage (>=2.14.0,<3.0.0)
|
|
24
|
+
Requires-Dist: joblib (>=1.1.0,<2.0.0) ; extra == "batch"
|
|
25
|
+
Requires-Dist: numpy (>=1.21.6) ; python_full_version >= "3.7.1" and python_version < "3.10"
|
|
26
|
+
Requires-Dist: numpy (>=1.24.0) ; python_version >= "3.10"
|
|
27
|
+
Requires-Dist: pandas (<1.4) ; (python_full_version >= "3.7.1" and python_version < "3.8") and (extra == "batch")
|
|
28
|
+
Requires-Dist: pandas (>=1.4.0) ; (python_version >= "3.8" and python_version < "3.12") and (extra == "batch")
|
|
29
|
+
Requires-Dist: pyarrow (>=6.0.0,<11.0.0) ; extra == "batch"
|
|
30
|
+
Requires-Dist: requests (>=2.0.0,<3.0.0)
|
|
31
|
+
Requires-Dist: tenacity (>=8.0.0,<9.0.0) ; extra == "batch"
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# Qwak Inference
|
|
35
|
+
|
|
36
|
+
FrogML is an end-to-end production ML platform designed to allow data scientists to build, deploy, and monitor their models in production with minimal engineering friction.
|
|
37
|
+
FrogML Inference contains tools that allow predicting against the FrogML Platform
|
|
38
|
+
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# Qwak Inference
|
|
2
|
+
|
|
3
|
+
FrogML is an end-to-end production ML platform designed to allow data scientists to build, deploy, and monitor their models in production with minimal engineering friction.
|
|
4
|
+
FrogML Inference contains tools that allow predicting against the FrogML Platform
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from frogml_inference.realtime_client import RealTimeClient
|
|
2
|
+
|
|
3
|
+
clients = ["RealTimeClient"]
|
|
4
|
+
try:
|
|
5
|
+
from frogml import wire_dependencies
|
|
6
|
+
|
|
7
|
+
from frogml_inference.batch_client.batch_client import BatchInferenceClient
|
|
8
|
+
|
|
9
|
+
clients.extend(["BatchInferenceClient"])
|
|
10
|
+
|
|
11
|
+
wire_dependencies()
|
|
12
|
+
except ImportError:
|
|
13
|
+
# We are conditional loading these clients since the skinny does
|
|
14
|
+
# not support them due to the pandas, numpy, joblib, etc. dependencies
|
|
15
|
+
print(
|
|
16
|
+
"Notice that BatchInferenceClient is not available in the skinny package. "
|
|
17
|
+
'In order to use it, please install them as extras: pip install "frogml-inference[batch]".'
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
__all__ = clients
|
|
21
|
+
|
|
22
|
+
__version__ = "0.0.1"
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class LoginArguments:
|
|
5
|
+
is_anonymous: bool = False
|
|
6
|
+
server_id: Optional[str] = None
|
|
7
|
+
username: Optional[str] = None
|
|
8
|
+
password: Optional[str] = None
|
|
9
|
+
access_token: Optional[str] = None
|
|
10
|
+
artifactory_url: Optional[str] = None
|
|
11
|
+
|
|
12
|
+
def __eq__(self, __value):
|
|
13
|
+
if not isinstance(__value, LoginArguments):
|
|
14
|
+
return False
|
|
15
|
+
return (
|
|
16
|
+
self.is_anonymous == __value.is_anonymous
|
|
17
|
+
and self.server_id == __value.server_id
|
|
18
|
+
and self.username == __value.username
|
|
19
|
+
and self.password == __value.password
|
|
20
|
+
and self.access_token == __value.access_token
|
|
21
|
+
and self.artifactory_url == __value.artifactory_url
|
|
22
|
+
)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
from requests.auth import AuthBase
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class BearerAuth(AuthBase):
|
|
5
|
+
def __init__(self, token):
|
|
6
|
+
self.token = token
|
|
7
|
+
|
|
8
|
+
def __call__(self, r):
|
|
9
|
+
r.headers["Authorization"] = f"Bearer {self.token}"
|
|
10
|
+
return r
|
|
11
|
+
|
|
12
|
+
def __eq__(self, other):
|
|
13
|
+
if not isinstance(other, BearerAuth):
|
|
14
|
+
return False
|
|
15
|
+
return self.token == other.token
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class EmptyAuth(AuthBase):
|
|
19
|
+
def __call__(self, r):
|
|
20
|
+
return r
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
from typing import Optional, Tuple
|
|
4
|
+
|
|
5
|
+
from requests.auth import AuthBase, HTTPBasicAuth
|
|
6
|
+
|
|
7
|
+
from frogml_inference.authentication._login_arguments import LoginArguments
|
|
8
|
+
from frogml_inference.authentication._utils import BearerAuth, EmptyAuth
|
|
9
|
+
from frogml_inference.authentication.constants import (
|
|
10
|
+
CONFIG_FILE_PATH,
|
|
11
|
+
FROG_ML_CONFIG_ACCESS_TOKEN,
|
|
12
|
+
FROG_ML_CONFIG_ARTIFACTORY_URL,
|
|
13
|
+
FROG_ML_CONFIG_PASSWORD,
|
|
14
|
+
FROG_ML_CONFIG_USER,
|
|
15
|
+
JF_ACCESS_TOKEN,
|
|
16
|
+
JF_URL,
|
|
17
|
+
)
|
|
18
|
+
from frogml_inference.configuration.auth_config import AuthConfig
|
|
19
|
+
from frogml_inference.configuration.log_config import logger
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def read_frogml_config() -> Optional[dict]:
|
|
23
|
+
try:
|
|
24
|
+
with open(CONFIG_FILE_PATH, "r") as file:
|
|
25
|
+
config_data = json.load(file)
|
|
26
|
+
return config_data
|
|
27
|
+
except FileNotFoundError:
|
|
28
|
+
logger.debug("FrogMl config file was not found.")
|
|
29
|
+
return None
|
|
30
|
+
except json.JSONDecodeError as e:
|
|
31
|
+
logger.debug(f"FrogMl config file is not a valid JSON {e}.")
|
|
32
|
+
return None
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def __check_is_valid_frogml_auth_file(server_config: dict) -> bool:
|
|
36
|
+
has_url: bool = FROG_ML_CONFIG_ARTIFACTORY_URL in server_config
|
|
37
|
+
if not has_url:
|
|
38
|
+
logger.debug(
|
|
39
|
+
"Invalid FrogMl authentication file, expected either artifactory_url in FrogMl authentication file"
|
|
40
|
+
)
|
|
41
|
+
return False
|
|
42
|
+
|
|
43
|
+
has_user: bool = FROG_ML_CONFIG_USER in server_config
|
|
44
|
+
has_password: bool = FROG_ML_CONFIG_PASSWORD in server_config
|
|
45
|
+
is_missing_user_or_password: bool = (has_user and not has_password) or (
|
|
46
|
+
not has_user and has_password
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
if is_missing_user_or_password:
|
|
50
|
+
logger.debug(
|
|
51
|
+
"Invalid FrogMl authentication file, username or password is missing in FrogMl authentication file"
|
|
52
|
+
)
|
|
53
|
+
return False
|
|
54
|
+
|
|
55
|
+
return True
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def __get_login_arguments(server_config: dict) -> LoginArguments:
|
|
59
|
+
login_args = LoginArguments()
|
|
60
|
+
login_args.artifactory_url = server_config.get(FROG_ML_CONFIG_ARTIFACTORY_URL)
|
|
61
|
+
|
|
62
|
+
has_access_token: bool = FROG_ML_CONFIG_ACCESS_TOKEN in server_config
|
|
63
|
+
has_user: bool = FROG_ML_CONFIG_USER in server_config
|
|
64
|
+
has_password: bool = FROG_ML_CONFIG_PASSWORD in server_config
|
|
65
|
+
|
|
66
|
+
if has_access_token:
|
|
67
|
+
login_args.access_token = server_config.get(FROG_ML_CONFIG_ACCESS_TOKEN)
|
|
68
|
+
elif has_user and has_password:
|
|
69
|
+
login_args.username = server_config.get(FROG_ML_CONFIG_USER)
|
|
70
|
+
login_args.password = server_config.get(FROG_ML_CONFIG_PASSWORD)
|
|
71
|
+
|
|
72
|
+
is_anonymous = (
|
|
73
|
+
login_args.username is None
|
|
74
|
+
and login_args.password is None
|
|
75
|
+
and login_args.access_token is None
|
|
76
|
+
)
|
|
77
|
+
if is_anonymous:
|
|
78
|
+
login_args.is_anonymous = True
|
|
79
|
+
|
|
80
|
+
return login_args
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def get_frogml_configuration() -> Optional[LoginArguments]:
|
|
84
|
+
frog_ml_config: Optional[dict] = read_frogml_config()
|
|
85
|
+
is_frogml_config_not_defined: bool = (
|
|
86
|
+
not frog_ml_config
|
|
87
|
+
or frog_ml_config.get("servers") is None
|
|
88
|
+
or len(frog_ml_config["servers"]) <= 0
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
if is_frogml_config_not_defined:
|
|
92
|
+
return None
|
|
93
|
+
|
|
94
|
+
server_config: dict = frog_ml_config["servers"][0]
|
|
95
|
+
is_valid_auth_file: bool = __check_is_valid_frogml_auth_file(server_config)
|
|
96
|
+
|
|
97
|
+
if not is_valid_auth_file:
|
|
98
|
+
return None
|
|
99
|
+
|
|
100
|
+
login_args: LoginArguments = __get_login_arguments(server_config)
|
|
101
|
+
|
|
102
|
+
return login_args
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def get_credentials(auth_config: Optional[AuthConfig] = None) -> Tuple[str, AuthBase]:
|
|
106
|
+
if not __should_use_file_auth(auth_config):
|
|
107
|
+
__validate_credentials(auth_config)
|
|
108
|
+
return __auth_config_to_auth_tuple(auth_config)
|
|
109
|
+
logger.debug(
|
|
110
|
+
"Login configuration not supplied, attempting to find environment variables"
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
if __should_use_environment_variables():
|
|
114
|
+
return get_environment_variables()
|
|
115
|
+
|
|
116
|
+
logger.debug(
|
|
117
|
+
"Environment variables not supplied, attempting to load configuration from file"
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
if os.path.exists(CONFIG_FILE_PATH):
|
|
121
|
+
return __read_credentials_from_file(CONFIG_FILE_PATH)
|
|
122
|
+
raise ValueError(
|
|
123
|
+
f"Configuration were not provided and configuration file not found in {CONFIG_FILE_PATH},"
|
|
124
|
+
f" either pass configuration in the constructor, add env variables or create the configuration file by "
|
|
125
|
+
f"running `frogml login`"
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def __should_use_environment_variables() -> bool:
|
|
130
|
+
return os.getenv("JF_URL") is not None
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def get_environment_variables() -> Tuple[str, AuthBase]:
|
|
134
|
+
auth_config: AuthConfig = AuthConfig(
|
|
135
|
+
artifactory_url=os.getenv(JF_URL),
|
|
136
|
+
access_token=os.getenv(JF_ACCESS_TOKEN),
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
return __auth_config_to_auth_tuple(auth_config)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def __should_use_file_auth(credentials: Optional[AuthConfig] = None) -> bool:
|
|
143
|
+
return credentials is None or (
|
|
144
|
+
credentials.artifactory_url is None
|
|
145
|
+
and credentials.user is None
|
|
146
|
+
and credentials.password is None
|
|
147
|
+
and credentials.access_token is None
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def __validate_credentials(credentials: Optional[AuthConfig]) -> None:
|
|
152
|
+
if credentials is None:
|
|
153
|
+
raise ValueError("Credentials must be provided.")
|
|
154
|
+
if credentials.artifactory_url is None:
|
|
155
|
+
raise ValueError("Credentials must contain artifactory url.")
|
|
156
|
+
return None
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def __read_credentials_from_file(file_path: str) -> Tuple[str, AuthBase]:
|
|
160
|
+
try:
|
|
161
|
+
with open(file_path, "r") as file:
|
|
162
|
+
config_content: dict = json.load(file)
|
|
163
|
+
servers = config_content.get("servers")
|
|
164
|
+
if servers is None or len(servers) == 0:
|
|
165
|
+
raise ValueError(
|
|
166
|
+
"Configuration file was found but it's empty, failing authentication"
|
|
167
|
+
)
|
|
168
|
+
server = servers[0]
|
|
169
|
+
return __auth_config_to_auth_tuple(AuthConfig.from_dict(server))
|
|
170
|
+
except json.JSONDecodeError:
|
|
171
|
+
raise ValueError(f"Error when reading {file_path}, please recreate the file.")
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def __auth_config_to_auth_tuple(
|
|
175
|
+
auth_config: Optional[AuthConfig],
|
|
176
|
+
) -> Tuple[str, AuthBase]:
|
|
177
|
+
if auth_config.artifactory_url is None:
|
|
178
|
+
raise ValueError("No artifactory URL provided")
|
|
179
|
+
|
|
180
|
+
auth: AuthBase = __get_auth_provider(auth_config)
|
|
181
|
+
|
|
182
|
+
return auth_config.artifactory_url, auth
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
def __get_auth_provider(auth_config: Optional[AuthConfig]) -> AuthBase:
|
|
186
|
+
auth: AuthBase = EmptyAuth()
|
|
187
|
+
|
|
188
|
+
if auth_config is None:
|
|
189
|
+
raise ValueError("No authentication configuration provided")
|
|
190
|
+
|
|
191
|
+
if auth_config.access_token is not None:
|
|
192
|
+
auth = BearerAuth(auth_config.access_token)
|
|
193
|
+
elif auth_config.user is not None and auth_config.password is not None:
|
|
194
|
+
auth = HTTPBasicAuth(auth_config.user, auth_config.password)
|
|
195
|
+
elif auth_config.user is not None or auth_config.password is not None:
|
|
196
|
+
raise ValueError("User and password must be provided together")
|
|
197
|
+
|
|
198
|
+
return auth
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from pathlib import Path, PosixPath
|
|
3
|
+
|
|
4
|
+
FROGML_DIR_PATH: PosixPath = Path.home() / ".frogml"
|
|
5
|
+
CONFIG_FILE_PATH: str = os.path.join(FROGML_DIR_PATH, "config.json")
|
|
6
|
+
FROG_ML_CONFIG_USER = "user"
|
|
7
|
+
FROG_ML_CONFIG_ARTIFACTORY_URL = "artifactory_url"
|
|
8
|
+
SERVER_ID = "server_id"
|
|
9
|
+
JF_URL = "JF_URL"
|
|
10
|
+
JF_ACCESS_TOKEN = "JF_ACCESS_TOKEN" # nosec B105
|
|
11
|
+
FROG_ML_CONFIG_PASSWORD = "password" # nosec B105
|
|
12
|
+
FROG_ML_CONFIG_ACCESS_TOKEN = "access_token" # nosec B105
|
|
File without changes
|