qmenta-core 4.1.dev708__tar.gz → 4.1.dev709__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.

Potentially problematic release.


This version of qmenta-core might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: qmenta-core
3
- Version: 4.1.dev708
3
+ Version: 4.1.dev709
4
4
  Summary: QMENTA core library to communicate with the QMENTA platform.
5
5
  License: Proprietary
6
6
  Author: QMENTA
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "qmenta-core"
3
- version = "4.1.dev708"
3
+ version = "4.1.dev709"
4
4
  description = "QMENTA core library to communicate with the QMENTA platform."
5
5
  license = "Proprietary"
6
6
  authors = ["QMENTA <dev@qmenta.com>"]
@@ -1,4 +1,5 @@
1
1
  import argparse
2
+ from enum import Enum, unique
2
3
  import os
3
4
  import requests
4
5
  from getpass import getpass
@@ -32,6 +33,15 @@ class Needs2FAError(ActionFailedError):
32
33
  pass
33
34
 
34
35
 
36
+ @unique
37
+ class PlatformURL(Enum):
38
+ platform = 'platform.qmenta.com'
39
+ staging = 'staging.qmenta.com'
40
+ test = 'test.qmenta.com'
41
+ local_ip = "127.0.0.1:8080"
42
+ localhost = "localhost:8080"
43
+
44
+
35
45
  class Auth:
36
46
  """
37
47
  Class for authenticating to the platform.
@@ -41,11 +51,13 @@ class Auth:
41
51
  Attributes
42
52
  ----------
43
53
  base_url : str
44
- The base URL of the platform. Example: 'https://platform.qmenta.com'
54
+ The URL of the platform to connect to.
55
+ Default value: 'https://platform.qmenta.com'
45
56
  token : str
46
57
  The authentication token, returned by the platform when logging in.
47
58
  """
48
59
  def __init__(self, base_url: str, token: str) -> None:
60
+ validate_url(base_url)
49
61
  self.base_url = base_url
50
62
  self.token = token
51
63
  self._session: Optional[requests.Session] = None
@@ -101,7 +113,7 @@ class Auth:
101
113
  def login(cls, username: str, password: str,
102
114
  code_2fa: Optional[str] = None,
103
115
  ask_for_2fa_input: bool = False,
104
- base_url: str = 'https://platform.qmenta.com') -> 'Auth':
116
+ base_url: str = PlatformURL.platform.value) -> 'Auth':
105
117
  """
106
118
  Authenticate to the platform using username and password.
107
119
 
@@ -232,6 +244,8 @@ def write_dot_env_file(token: str, url: str,
232
244
  OSError
233
245
  When the output file could not be written
234
246
  """
247
+ validate_url(url)
248
+
235
249
  filepath = filename or Auth.qmenta_auth_env_file()
236
250
  os.makedirs(os.path.dirname(os.path.abspath(filepath)), exist_ok=True)
237
251
 
@@ -251,6 +265,7 @@ def validate_url(url: str) -> None:
251
265
  ValueError
252
266
  When the URL is not valid
253
267
  """
268
+
254
269
  parsed_url = urlparse(url)
255
270
 
256
271
  if parsed_url.scheme == 'http':
@@ -271,6 +286,13 @@ def validate_url(url: str) -> None:
271
286
  'Example: https://platform.qmenta.com'
272
287
  )
273
288
 
289
+ url_values = [p_url.value for p_url in PlatformURL]
290
+ if parsed_url.netloc not in url_values:
291
+ raise ValueError(
292
+ "base_url must be one of '{}', ".format("', '".join(url_values))
293
+ + f"not '{parsed_url.netloc}'."
294
+ )
295
+
274
296
 
275
297
  def main() -> None:
276
298
  parser = argparse.ArgumentParser(
@@ -29,8 +29,8 @@ class ChooseDataError(ActionFailedError):
29
29
  """
30
30
 
31
31
  def __init__(
32
- self, warning: str, data_to_choose: Dict[str, List[str]]
33
- , analysis_id: int
32
+ self, warning: str, data_to_choose: Dict[str, List[str]],
33
+ analysis_id: int
34
34
  ) -> None:
35
35
  self.warning: str = warning
36
36
  self.data_to_choose: dict = data_to_choose