dotstat_io 1.0.0__tar.gz → 1.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.

Potentially problematic release.


This version of dotstat_io might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dotstat_io
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: Utility to download or upload data from/to .Stat Suite using ADFS authentication to connect to it
5
5
  License: MIT
6
6
  Author: Gyorgy Gyomai
@@ -18,10 +18,6 @@ class AuthenticationMode(IntEnum):
18
18
  # super class to manage authentication
19
19
  class Authentication(ABC):
20
20
 
21
- # protected constants
22
- _ERROR_OCCURRED = "An error occurred: "
23
- _SUCCESS = "Successful authentication"
24
-
25
21
  # protected variables
26
22
  _access_token = None
27
23
  _refresh_token = None
@@ -96,6 +92,10 @@ class Authentication(ABC):
96
92
 
97
93
  # sub class to manage ADFS authentication using OIDC flows
98
94
  class AdfsAuthentication(Authentication):
95
+ # private constants
96
+ __ERROR_OCCURRED = "An error occurred: "
97
+ __SUCCESSFUL_AUTHENTICATION = "Successful authentication"
98
+
99
99
  #
100
100
  def _initialize_token(self):
101
101
  self._access_token = None
@@ -193,20 +193,20 @@ class AdfsAuthentication(Authentication):
193
193
  self._refresh_token = response_interactive.get("refresh_token")
194
194
  self._creation_time = time.time()
195
195
  self._expiration_time = time.time() + int(response_interactive.get("expires_in")) - 60 # one minute margin
196
- self.init_status = self._SUCCESS
196
+ self.init_status = self.__SUCCESSFUL_AUTHENTICATION
197
197
  else:
198
- self.init_status = f'{self._ERROR_OCCURRED}{response_interactive.get("error")} Error description: {response_interactive.get("error_description")}'
198
+ self.init_status = f'{self.__ERROR_OCCURRED}{response_interactive.get("error")} Error description: {response_interactive.get("error_description")}'
199
199
  else:
200
200
  if "access_token" in response_silent:
201
201
  self._access_token = response_silent.get("access_token")
202
202
  self._refresh_token = response_silent.get("refresh_token")
203
203
  self._creation_time = time.time()
204
204
  self._expiration_time = time.time() + int(response_silent.get("expires_in")) - 60 # one minute margin
205
- self.init_status = self._SUCCESS
205
+ self.init_status = self.__SUCCESSFUL_AUTHENTICATION
206
206
  else:
207
- self.init_status = f'{self._ERROR_OCCURRED}{response_silent.get("error")} Error description: {response_silent.get("error_description")}'
207
+ self.init_status = f'{self.__ERROR_OCCURRED}{response_silent.get("error")} Error description: {response_silent.get("error_description")}'
208
208
  except Exception as err:
209
- self.init_status = f'{self._ERROR_OCCURRED}{err}\n'
209
+ self.init_status = f'{self.__ERROR_OCCURRED}{err}\n'
210
210
 
211
211
  # Authentication non-interactively using any account - aka Client Credentials flow
212
212
  def __acquire_token_noninteractive_with_secret(self):
@@ -216,12 +216,12 @@ class AdfsAuthentication(Authentication):
216
216
  self._access_token = response.get("access_token")
217
217
  self._creation_time = time.time()
218
218
  self._expiration_time = time.time() + int(response.get("expires_in")) - 60 # one minute margin
219
- self.init_status = self._SUCCESS
219
+ self.init_status = self.__SUCCESSFUL_AUTHENTICATION
220
220
  else:
221
- self.init_status = f'{self._ERROR_OCCURRED}{response.get("error")} Error description: {response.get("error_description")}'
221
+ self.init_status = f'{self.__ERROR_OCCURRED}{response.get("error")} Error description: {response.get("error_description")}'
222
222
 
223
223
  except Exception as err:
224
- self.init_status = f'{self._ERROR_OCCURRED}{err}\n'
224
+ self.init_status = f'{self.__ERROR_OCCURRED}{err}\n'
225
225
 
226
226
  # Authentication non-interactively using service account - aka Windows Client Authentication
227
227
  def __acquire_token_noninteractive_with_adfs(self):
@@ -250,26 +250,35 @@ class AdfsAuthentication(Authentication):
250
250
  self._access_token = results_json['access_token']
251
251
  self._creation_time = time.time()
252
252
  self._expiration_time = time.time() + int(results_json['expires_in']) - 60 # one minute margin
253
- self.init_status = self._SUCCESS
253
+ self.init_status = self.__SUCCESSFUL_AUTHENTICATION
254
254
  else:
255
- message = f'{self._ERROR_OCCURRED} Error code: {response.status_code}'
255
+ message = f'{self.__ERROR_OCCURRED} Error code: {response.status_code}'
256
256
  if len(str(response.reason)) > 0:
257
257
  message += os.linesep + 'Reason: ' + str(response.reason) + os.linesep
258
258
  if len(response.text) > 0:
259
- message += f'{self._ERROR_OCCURRED}{results_json.get("error")} Error description: {results_json.get("error_description")}\n'
259
+ message += f'{self.__ERROR_OCCURRED}{results_json.get("error")} Error description: {results_json.get("error_description")}\n'
260
260
 
261
261
  self.init_status = message
262
262
  except ValueError as err:
263
- if len(response.text) > 0:
264
- self.init_status = self._ERROR_OCCURRED + os.linesep + str(response.text)
265
- else:
266
- self.init_status = self._ERROR_OCCURRED + os.linesep + str(err)
263
+ self.init_status = self.__ERROR_OCCURRED + os.linesep
264
+ if len(str(response.status_code)) > 0:
265
+ self.init_status += 'Error code: ' + str(response.status_code) + os.linesep
266
+ if len(str(response.reason)) > 0:
267
+ self.init_status += 'Reason: ' + str(response.reason) + os.linesep
268
+ if len(response.text) > 0:
269
+ self.init_status += str(response.text)
270
+ else:
271
+ self.init_status += str(err)
267
272
  except Exception as err:
268
- self.init_status = f'{self._ERROR_OCCURRED} {err}\n'
273
+ self.init_status = f'{self.__ERROR_OCCURRED} {err}\n'
269
274
 
270
275
 
271
276
  # sub class to manage Keycloak authentication
272
- class KeycloakAuthentication(Authentication):
277
+ class KeycloakAuthentication(Authentication):
278
+ # private constants
279
+ __ERROR_OCCURRED = "An error occurred: "
280
+ __SUCCESSFUL_AUTHENTICATION = "Successful authentication"
281
+
273
282
  #
274
283
  def _initialize_token(self):
275
284
  self._access_token = None
@@ -320,7 +329,7 @@ class KeycloakAuthentication(Authentication):
320
329
 
321
330
  response = requests.post(self._token_url, proxies=self._proxies, headers=headers, data=payload)
322
331
  if response.status_code not in {200, 201}:
323
- self.init_status = f'{self._ERROR_OCCURRED}{response}'
332
+ self.init_status = f'{self.__ERROR_OCCURRED}{response}'
324
333
  else:
325
334
  # If the response object cannot be converted to json, return an error
326
335
  results_json = None
@@ -330,11 +339,16 @@ class KeycloakAuthentication(Authentication):
330
339
  self._refresh_token = results_json['refresh_token']
331
340
  self._creation_time = time.time()
332
341
  self._expiration_time = time.time() + int(results_json['expires_in']) - 60 # one minute margin
333
- self.init_status = self._SUCCESS
342
+ self.init_status = self.__SUCCESSFUL_AUTHENTICATION
334
343
  except ValueError as err:
335
- if len(response.text) > 0:
336
- self.init_status = self._ERROR_OCCURRED + os.linesep + str(response.text)
337
- else:
338
- self.init_status = self._ERROR_OCCURRED + os.linesep + str(err)
344
+ self.init_status = self.__ERROR_OCCURRED + os.linesep
345
+ if len(str(response.status_code)) > 0:
346
+ self.init_status += 'Error code: ' + str(response.status_code) + os.linesep
347
+ if len(str(response.reason)) > 0:
348
+ self.init_status += 'Reason: ' + str(response.reason) + os.linesep
349
+ if len(response.text) > 0:
350
+ self.init_status += str(response.text)
351
+ else:
352
+ self.init_status += str(err)
339
353
  except Exception as err:
340
- self.init_status = f'{self._ERROR_OCCURRED}{err}\n'
354
+ self.init_status = f'{self.__ERROR_OCCURRED}{err}\n'
@@ -249,10 +249,15 @@ class Client():
249
249
  if len(line) > 0:
250
250
  self.__log.info(' ' + line)
251
251
  except ValueError as err:
252
+ returned_result = self.__ERROR_OCCURRED + os.linesep
253
+ if len(str(response.status_code)) > 0:
254
+ returned_result += 'Error code: ' + str(response.status_code) + os.linesep
255
+ if len(str(response.reason)) > 0:
256
+ returned_result += 'Reason: ' + str(response.reason) + os.linesep
252
257
  if len(response.text) > 0:
253
- self.init_status = self._ERROR + os.linesep + str(response.text)
258
+ returned_result += str(response.text)
254
259
  else:
255
- self.init_status = self._ERROR + os.linesep + str(err)
260
+ returned_result += str(err)
256
261
  finally:
257
262
  return returned_result
258
263
 
@@ -383,10 +388,15 @@ class Client():
383
388
  if len(response.text) > 0:
384
389
  returned_result = returned_result + os.linesep + 'Text: ' + response.text
385
390
  except ValueError as err:
391
+ returned_result = self.__ERROR_OCCURRED + os.linesep
392
+ if len(str(response.status_code)) > 0:
393
+ returned_result += 'Error code: ' + str(response.status_code) + os.linesep
394
+ if len(str(response.reason)) > 0:
395
+ returned_result += 'Reason: ' + str(response.reason) + os.linesep
386
396
  if len(response.text) > 0:
387
- self.init_status = self._ERROR + os.linesep + str(response.text)
397
+ returned_result += str(response.text)
388
398
  else:
389
- self.init_status = self._ERROR + os.linesep + str(err)
399
+ returned_result += str(err)
390
400
  finally:
391
401
  return returned_result
392
402
 
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "dotstat_io"
3
- version = "1.0.0"
3
+ version = "1.0.1"
4
4
  description = "Utility to download or upload data from/to .Stat Suite using ADFS authentication to connect to it"
5
5
  license = "MIT"
6
6
  authors = ["Gyorgy Gyomai <gyorgy.gyomai@oecd.org>", "Abdel Aliaoui <abdel.aliaoui@oecd.org>"]
File without changes