ga-api-client 0.3.6__tar.gz → 0.4.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 (20) hide show
  1. {ga_api_client-0.3.6/ga_api_client.egg-info → ga_api_client-0.4.0}/PKG-INFO +1 -1
  2. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/ga_api/ga_api_client.py +30 -9
  3. {ga_api_client-0.3.6 → ga_api_client-0.4.0/ga_api_client.egg-info}/PKG-INFO +1 -1
  4. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/setup.cfg +1 -1
  5. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/LICENSE +0 -0
  6. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/README.md +0 -0
  7. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/ga_api/__init__.py +0 -0
  8. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/ga_api/average.py +0 -0
  9. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/ga_api/capture.py +0 -0
  10. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/ga_api/field_tree.py +0 -0
  11. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/ga_api/hyper_log_log.py +0 -0
  12. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/ga_api/rate.py +0 -0
  13. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/ga_api/std.py +0 -0
  14. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/ga_api/tdigest.py +0 -0
  15. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/ga_api_client.egg-info/SOURCES.txt +0 -0
  16. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/ga_api_client.egg-info/dependency_links.txt +0 -0
  17. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/ga_api_client.egg-info/requires.txt +0 -0
  18. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/ga_api_client.egg-info/top_level.txt +0 -0
  19. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/pyproject.toml +0 -0
  20. {ga_api_client-0.3.6 → ga_api_client-0.4.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ga-api-client
3
- Version: 0.3.6
3
+ Version: 0.4.0
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: License :: OSI Approved :: MIT License
6
6
  Classifier: Operating System :: OS Independent
@@ -84,9 +84,11 @@ class UnexpectedStatus(Exception):
84
84
  super().__init__(self.message)
85
85
 
86
86
  ACCESS_TOKEN_TIMEOUT = 86400 / 2
87
-
87
+ SUPPORT_STRATEGIES = ['custom', 'local', 'remote', 'controller']
88
88
  class Client:
89
- def __init__(self, url, user, tenant, password, ssl=True, burst=1, retry=0, conn_timeout=30, read_timeout=300):
89
+ def __init__(self, url, user, tenant, password, ssl=True, burst=1, retry=0, conn_timeout=30, read_timeout=300, strategy="custom", controller=None):
90
+ self.strategy = strategy
91
+ self.controller = controller
90
92
  self.url = url # base url
91
93
  self.user = user # user name
92
94
  self.tenant = tenant # tenant name
@@ -97,14 +99,20 @@ class Client:
97
99
  self._headers = {
98
100
  'Content-Type': 'application/json'
99
101
  }
102
+ if self.strategy not in SUPPORT_STRATEGIES:
103
+ raise Exception(f"unsupported strategy {self.strategy}, supported strategies are {SUPPORT_STRATEGIES}")
104
+ if self.strategy == 'controller' and self.controller is None:
105
+ raise Exception(f"controller strategy requires \"controller\" argument")
106
+
100
107
  self._last_auth = 0 # timestamp of last authenticate in seconds since Eopch
101
108
  self._session = aiohttp.ClientSession(trust_env=True)
102
109
  # self._session = aiohttp.ClientSession(trust_env=True, connector=aiohttp.TCPConnector(force_close=True))
103
110
  self.timeout = aiohttp.ClientTimeout(total=None, connect=None, sock_connect=conn_timeout, sock_read=read_timeout)
104
111
 
112
+
105
113
  async def _authenticate(self):
106
114
  authData = {
107
- 'strategy': 'custom', # tells this is API request
115
+ 'strategy': 'custom',
108
116
  'account': f'{self.user}@{self.tenant}', # user account '<user>@<tenant>'
109
117
  'password': self.password # user password
110
118
  }
@@ -143,6 +151,19 @@ class Client:
143
151
  'answer': answer_s
144
152
  }
145
153
  # do authenticate
154
+ if 'allowLogin' in bringup:
155
+ if (self.strategy == 'custom' or self.strategy == 'local') and bringup['allowLogin']['local'] is False:
156
+ raise Exception('local login is not allowed')
157
+ elif self.strategy == 'remote' and bringup['allowLogin']['remote'] is False:
158
+ raise Exception('remote login is not allowed')
159
+ elif self.strategy == 'controller':
160
+ if bringup['allowLogin']['controller'] is False:
161
+ raise Exception('controller login is not allowed')
162
+ elif len([x for x in bringup['allowLogin']['controller'] if x['_id'] == self.controller]) == 0:
163
+ raise Exception(f'controller is not found, available controllers are:{bringup["allowLogin"]["controller"]}')
164
+ authData['controller'] = self.controller
165
+ authData['strategy'] = self.strategy
166
+
146
167
  url = self.url+'/authentication'
147
168
  async with self._session.post(url, json=authData, headers=self._headers, ssl=self.ssl) as resp:
148
169
  if resp.status != 201:
@@ -217,7 +238,7 @@ class Client:
217
238
  raise e
218
239
 
219
240
  class System(Client):
220
- def __init__(self, url, user=None, password=None, ssl=True, retry=0, conn_timeout=30, read_timeout=300):
241
+ def __init__(self, url, user=None, password=None, ssl=True, retry=0, conn_timeout=30, read_timeout=300, strategy="custom", controller=None):
221
242
  """Construct object to send system requests.
222
243
 
223
244
  Args:
@@ -231,7 +252,7 @@ class System(Client):
231
252
  user = input('User:')
232
253
  if password is None:
233
254
  password = getpass.getpass('Password:')
234
- super().__init__(url, user, 'system', password, ssl=ssl, retry=retry, conn_timeout=conn_timeout, read_timeout=read_timeout)
255
+ super().__init__(url, user, 'system', password, ssl=ssl, retry=retry, conn_timeout=conn_timeout, read_timeout=read_timeout, strategy=strategy, controller=controller)
235
256
 
236
257
  async def close(self):
237
258
  """Close the underlying connections gracefully. If the event loop is stopped before
@@ -366,14 +387,14 @@ def desc_dataframe(desc_list):
366
387
  return pd.DataFrame.from_dict(desc_dict, orient='index')
367
388
 
368
389
  class Tenant(Client):
369
- def __init__(self, url, user=None, tenant=None, password=None, ssl=True, burst=1, retry=0, conn_timeout=30, read_timeout=300):
390
+ def __init__(self, url, user=None, tenant=None, password=None, ssl=True, burst=1, retry=0, conn_timeout=30, read_timeout=300, strategy="custom", controller=None):
370
391
  if user is None:
371
392
  user = input('User:')
372
393
  if tenant is None:
373
394
  tenant = input('Tenant:')
374
395
  if password is None:
375
396
  password = getpass.getpass('Password:')
376
- super().__init__(url, user, tenant, password, ssl=ssl, burst=burst, retry=retry, conn_timeout=conn_timeout, read_timeout=read_timeout)
397
+ super().__init__(url, user, tenant, password, ssl=ssl, burst=burst, retry=retry, conn_timeout=conn_timeout, read_timeout=read_timeout, strategy=strategy, controller=controller)
377
398
 
378
399
  async def close(self):
379
400
  """Close the underlying connections gracefully. If the event loop is stopped before
@@ -1081,7 +1102,7 @@ class Controller:
1081
1102
  rlt = await self._tenant.get_mgr_config(req)
1082
1103
  return self.desc_resource_group(rlt)
1083
1104
  class Repository:
1084
- def __init__(self, url, user=None, tenant=None, password=None, ssl=True, burst=1, retry=0, conn_timeout=30, read_timeout=300):
1105
+ def __init__(self, url, user=None, tenant=None, password=None, ssl=True, burst=1, retry=0, conn_timeout=30, read_timeout=300, strategy=None, controller=None):
1085
1106
  """Construct repository object to send tenant requests to API server
1086
1107
 
1087
1108
  Args:
@@ -1093,7 +1114,7 @@ class Repository:
1093
1114
  burst: Maximum concurrent requests to the API server.
1094
1115
  retry: Number of retry at fail of sending request.
1095
1116
  """
1096
- self._tenant = Tenant(url, user, tenant, password, ssl=ssl, burst=burst, retry=retry, conn_timeout=conn_timeout, read_timeout=read_timeout)
1117
+ self._tenant = Tenant(url, user, tenant, password, ssl=ssl, burst=burst, retry=retry, conn_timeout=conn_timeout, read_timeout=read_timeout, strategy=strategy, controller=controller)
1097
1118
 
1098
1119
  async def close(self):
1099
1120
  """Close the underlying connections gracefully. If the event loop is stopped before
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ga-api-client
3
- Version: 0.3.6
3
+ Version: 0.4.0
4
4
  Classifier: Programming Language :: Python :: 3
5
5
  Classifier: License :: OSI Approved :: MIT License
6
6
  Classifier: Operating System :: OS Independent
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = ga-api-client
3
- version = 0.3.6
3
+ version = 0.4.0
4
4
  long_description = file: README.md
5
5
  long_description_content_type = text/markdown
6
6
  classifiers =
File without changes
File without changes
File without changes