python-eigen-ingenuity-nocli 0.5.7b4__py3-none-any.whl → 0.5.8__py3-none-any.whl

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.
@@ -23,7 +23,7 @@ from eigeningenuity.events import get_eventlog
23
23
  from eigeningenuity.assetmodel import get_assetmodel
24
24
  from eigeningenuity.smartdash import get_smartdash
25
25
  from eigeningenuity.sql import get_sql
26
- from eigeningenuity.settings import set_azure_client_id, set_azure_tenant_id, disable_azure_auth, disable_auth_token_cache, clear_auth_token_cache, set_api_token
26
+ from eigeningenuity.settings import set_azure_tenant_id, set_azure_client_id, set_azure_client_secret, disable_azure_auth, disable_auth_token_cache, clear_auth_token_cache, set_api_token, set_auth_scope
27
27
 
28
- __all__ = ["get_historian", "get_historian_multi", "get_assetmodel", "get_elastic", "get_sql", "get_eventlog", "get_smartdash", "list_historians", "EigenServer", "set_azure_client_id", "set_azure_tenant_id", "disable_azure_auth", "disable_auth_token_cache", "clear_auth_token_cache", "set_api_token"]
28
+ __all__ = ["get_historian", "get_historian_multi", "get_assetmodel", "get_elastic", "get_sql", "get_eventlog", "get_smartdash", "list_historians", "EigenServer", "set_azure_tenant_id", "set_azure_client_id", "set_azure_client_secret", "disable_azure_auth", "disable_auth_token_cache", "clear_auth_token_cache", "set_api_token", "set_auth_scope"]
29
29
  __version__ = pkg_resources.require("python-eigen-ingenuity")[0].version
eigeningenuity/auth.py CHANGED
@@ -19,6 +19,7 @@ def decrypt(data,key):
19
19
  def _authenticate_azure_user(baseurl):
20
20
  global url
21
21
  url = baseurl
22
+
22
23
  if settings._token_cache_enabled_:
23
24
  global cache
24
25
  try:
@@ -43,54 +44,77 @@ def _authenticate_azure_user(baseurl):
43
44
 
44
45
  tenant_id = settings._azure_tenant_id_
45
46
  client_id = settings._azure_client_id_
47
+ client_secret = settings._azure_client_secret_
46
48
  authority = f'https://login.microsoftonline.com/{tenant_id}'
47
- scope=[f"{baseurl}/user_impersonation"]
48
-
49
- app = msal.PublicClientApplication(
50
- client_id=client_id,
51
- authority=authority,
52
- token_cache=cache
53
- )
54
-
55
- result=None
56
49
 
57
- # We now check the cache to see
58
- # whether we already have some accounts that the end user already used to sign in before.
59
- accounts = app.get_accounts()
60
- if accounts:
61
- account = 0
62
- # If so, you could then somehow display these accounts and let end user choose
63
- if len(accounts) >= 2:
64
- print("Found Multiple Users in Cache")
65
- while True:
66
- for idx,a in enumerate(accounts):
67
- print(f'{idx}: {a["username"]}')
68
- try:
69
- account = int(input("Enter the number of the account you want to use:\n"))
70
- if account not in list(range(len(accounts))):
50
+ if client_secret: # USE CLIENT_CREDENTIALS FLOW
51
+ scope=[f"{baseurl}/.default"]
52
+ # Create a confidential client application
53
+ app = msal.ConfidentialClientApplication(
54
+ client_id,
55
+ authority=authority,
56
+ client_credential=client_secret
57
+ )
58
+
59
+ # Acquire a token
60
+ result = app.acquire_token_for_client(scopes=scope)
61
+
62
+ if "access_token" in result:
63
+ access_token = (result["access_token"])
64
+ else:
65
+ print("Error acquiring token:")
66
+ print(result.get("error"))
67
+ print(result.get("error_description"))
68
+ print(result.get("correlation_id")) # You might want to save this in case of reporting a bug
69
+
70
+ else: # USE INTERACTIVE FLOW
71
+
72
+ scope=[f"{baseurl}/{settings._auth_scope_}"]
73
+
74
+ app = msal.PublicClientApplication(
75
+ client_id=client_id,
76
+ authority=authority,
77
+ token_cache=cache
78
+ )
79
+
80
+ # We now check the cache to see
81
+ # whether we already have some accounts that the end user already used to sign in before.
82
+ accounts = app.get_accounts()
83
+ if accounts:
84
+ account = 0
85
+ # If so, you could then somehow display these accounts and let end user choose
86
+ if len(accounts) >= 2:
87
+ print("Found Multiple Users in Cache")
88
+ while True:
89
+ for idx,a in enumerate(accounts):
90
+ print(f'{idx}: {a["username"]}')
91
+ try:
92
+ account = int(input("Enter the number of the account you want to use:\n"))
93
+ if account not in list(range(len(accounts))):
94
+ print("That is not a valid option!")
95
+ else:
96
+ break
97
+ except:
71
98
  print("That is not a valid option!")
72
- else:
73
- break
74
- except:
75
- print("That is not a valid option!")
76
99
 
77
- # Assuming the end user chose this one
78
- chosen = accounts[account]
79
- # Now let's try to find a token in cache for this account
80
- result = app.acquire_token_silent(scope, account=chosen)
100
+ # Assuming the end user chose this one
101
+ chosen = accounts[account]
102
+ # Now let's try to find a token in cache for this account
103
+ result = app.acquire_token_silent(scope, account=chosen)
81
104
 
82
105
 
83
- if not result:
84
- # So no suitable token exists in cache. Let's get a new one from Azure AD.
85
- settings.clear_auth_token_cache()
86
- result = app.acquire_token_interactive(scope,auth_uri_callback=_backup_auth_azure_user)
106
+ if not result:
107
+ # So no suitable token exists in cache. Let's get a new one from Azure AD.
108
+ settings.clear_auth_token_cache()
109
+ result = app.acquire_token_interactive(scope,auth_uri_callback=_backup_auth_azure_user)
87
110
 
88
- if "access_token" in result:
89
- access_token = (result["access_token"]) # Yay!
90
- else:
91
- print(result.get("error"))
92
- print(result.get("error_description"))
93
- print(result.get("correlation_id")) # You may need this when reporting a bug
111
+ if "access_token" in result:
112
+ access_token = (result["access_token"]) # Yay!
113
+ else:
114
+ print("Error acquiring token:")
115
+ print(result.get("error"))
116
+ print(result.get("error_description"))
117
+ print(result.get("correlation_id")) # You may need this when reporting a bug
94
118
 
95
119
  # Make requests to the Java API using the obtained access token
96
120
  return {
@@ -127,7 +151,7 @@ def _backup_auth_azure_user(_uri):
127
151
 
128
152
 
129
153
  authority = f'https://login.microsoftonline.com/{settings._azure_tenant_id_}'
130
- scope=[f"{baseurl}/user_impersonation"]
154
+ scope=[f"{baseurl}/{settings._auth_scope_}"]
131
155
  client_id = settings._azure_client_id_
132
156
 
133
157
 
@@ -17,11 +17,7 @@ eigeningenuity.core) or a full URL to a JSON Bridge Historian instance.
17
17
  print(asctime(time.gmtime(dp['timestamp'])), dp['value'])
18
18
  """
19
19
 
20
- import json
21
- import math
22
- import logging
23
- import csv
24
- import requests
20
+ import requests, warnings
25
21
  from urllib.parse import quote as urlquote
26
22
  from typing import Union
27
23
  from datetime import datetime
@@ -32,10 +28,6 @@ from eigeningenuity.core import get_default_server, EigenServer
32
28
  from eigeningenuity.util import force_list, time_to_epoch_millis, EigenException, \
33
29
  multi_response_to_df, merge_tags_from_response, update_keys, _do_historian_multi_request, format_output
34
30
 
35
- from urllib3.exceptions import InsecureRequestWarning
36
- requests.packages.urllib3.disable_warnings(category=InsecureRequestWarning)
37
-
38
-
39
31
  class HistorianMulti (object):
40
32
  """A Historian which talks the Eigen Historian Json Bridge protocol.
41
33
  """
@@ -460,7 +452,7 @@ def createPoint(value:Union[int,float],timestamp:Union[int,str,datetime],status:
460
452
  raise EigenException("Bad Status Parameter, must be 'OK' or 'BAD'")
461
453
  return {"value": value, "timestamp": timestamp, "status": status}
462
454
 
463
- def get_historian_multi(eigenserver: EigenServer = None, default_historian = None) -> HistorianMulti:
455
+ def get_historian_multi(eigenserver = None, default_historian = None) -> HistorianMulti:
464
456
  """Instantiate a historian object for the given instance.
465
457
 
466
458
  Args:
@@ -5,7 +5,9 @@ _token_cache_enabled_ = True
5
5
  _azure_auth_enabled_ = True
6
6
  _azure_tenant_id_ = os.getenv("EIGEN_INGENUITY_TENANT_ID", "74efa022-e6d6-42ad-bc15-edc76c525bde")
7
7
  _azure_client_id_ = os.getenv("EIGEN_INGENUITY_CLIENT_ID", "c2b9aa13-e178-4dde-bc2c-b6cc4c8391d2")
8
+ _azure_client_secret_ = os.getenv("EIGEN_INGENUITY_CLIENT_SECRET", None)
8
9
  _api_token_value_ = os.getenv("EIGEN_INGENUITY_API_TOKEN", False)
10
+ _auth_scope_ = os.getenv("EIGEN_INGNEUITY_AUTH_SCOPE","user_impersonation")
9
11
 
10
12
 
11
13
  def clear_auth_token_cache():
@@ -65,7 +67,7 @@ def set_azure_client_id(id):
65
67
  Set the Client ID of the App registration for the eigenserver. This value required for Azure authentication, but the use of the EIGEN_INGENUITY_TENANT_ID environmental variable can be used as an alternative way of setting it.
66
68
 
67
69
  Args:
68
- id: The ID of your tenant in Azure. This can be found at portal.azure.com. (Default points to our DEMO Instance)
70
+ id: The ID of your service principal in Azure. This can be found at portal.azure.com. (Default points to our DEMO Instance)
69
71
 
70
72
  Returns:
71
73
  None
@@ -73,6 +75,19 @@ def set_azure_client_id(id):
73
75
  global _azure_client_id_
74
76
  _azure_client_id_ = id
75
77
 
78
+ def set_azure_client_secret(secret):
79
+ """
80
+ Set the Client ID of the App registration for the eigenserver. This value required for Azure authentication via CLIENT_CREDENTIALS flow, but not for the USER_CREDENTIALS flow, but the use of the EIGEN_INGENUITY_CLIENT_SECRET environmental variable can be used as an alternative way of setting it.
81
+
82
+ Args:
83
+ secret: The value of the client secret of your service principal in Azure. This can be found at portal.azure.com. (Default points to our DEMO Instance)
84
+
85
+ Returns:
86
+ None
87
+ """
88
+ global _azure_client_secret_
89
+ _azure_client_secret_ = secret
90
+
76
91
  def set_api_token(token):
77
92
  """
78
93
  Set the API token for the eigenserver. This value is required to access our secured endpoints, but the use of the EIGEN_INGENUITY_API_TOKEN environmental variable can be used as an alternative way of setting it.
@@ -85,3 +100,17 @@ def set_api_token(token):
85
100
  """
86
101
  global _api_token_value_
87
102
  _api_token_value_ = token
103
+
104
+ def set_auth_scope(scope):
105
+ """
106
+ Set the Scope to be requested from the Azure App registration. This is only required if your IT has implemented a non-standard scope.
107
+ This value must match the one configured in the eigen dashboards app registration in your Azure, if you are unsure of what is should be, ask yoeu system administrator. The use of the EIGEN_INGENUITY_AUTH_SCOPE environmental variable can be used as an alternative way of setting it.
108
+
109
+ Args:
110
+ scope: The value of the required scope. Defaults to 'user_impersonation'.
111
+
112
+ Returns:
113
+ None
114
+ """
115
+ global _auth_scope_
116
+ _auth_scope_ = scope
eigeningenuity/util.py CHANGED
@@ -1,5 +1,4 @@
1
-
2
- import sys, os, json, time, requests, csv, logging
1
+ import sys, os, json, time, requests, csv, logging, warnings
3
2
  from datetime import datetime
4
3
  from dateparser import parse
5
4
  import pandas as pd
@@ -11,6 +10,13 @@ from requests.exceptions import ConnectionError
11
10
  from eigeningenuity.auth import _authenticate_azure_user
12
11
  import eigeningenuity.settings as settings
13
12
 
13
+ from urllib3.exceptions import InsecureRequestWarning
14
+
15
+ # Suppress only the single InsecureRequestWarning from urllib3
16
+ warnings.simplefilter('ignore', InsecureRequestWarning)
17
+ # Suppress only the single InsecureRequestWarning from urllib3
18
+ requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
19
+
14
20
  def _do_eigen_json_request(requesturl,auth,**params):
15
21
 
16
22
  headers = {}
@@ -516,11 +522,16 @@ def _reformat_multi_response(original_dict):
516
522
  reformatted_dict = {}
517
523
 
518
524
  for key, value in original_dict.items():
519
- # Extract the list of data points from either 'dataPoints' or 'dataPoint' key
520
- data_points = value.get('dataPoints') or value.get('dataPoint')
521
- # Assign the data points list directly to the top-level key
522
- reformatted_dict[key] = data_points
523
-
525
+ if type(value) == list:
526
+ reformatted_dict = value
527
+ elif key == "dataPoint" or key == "dataPoints":
528
+ reformatted_dict = value
529
+ else:
530
+ # Extract the list of data points from either 'dataPoints' or 'dataPoint' key
531
+ data_points = value.get('dataPoints') or value.get('dataPoint') or value
532
+ # Assign the data points list directly to the top-level key
533
+ reformatted_dict[key] = data_points
534
+
524
535
  return reformatted_dict
525
536
 
526
537
  def format_output(output,response,tags,timestamps=False):
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: python-eigen-ingenuity-nocli
3
- Version: 0.5.7b4
3
+ Version: 0.5.8
4
4
  Summary: A python library used to query data from the Eigen Ingenuity system
5
5
  Home-page: https://www.eigen.co/
6
6
  Author: Murray Callander
@@ -1,14 +1,14 @@
1
- eigeningenuity/__init__.py,sha256=IeIiIeD8tNObLjTQjsnEMaTFip9IVkR80F3pMLDMhtY,1470
1
+ eigeningenuity/__init__.py,sha256=aNMBZbpxL6s1vxtxU0IxOpQ2V0C4er2Z9d66r7ExN8k,1556
2
2
  eigeningenuity/assetmodel.py,sha256=gpimrnPOhrUCRPmi223eeZ9d5jlYP5JkMQQNJElZuX4,16785
3
- eigeningenuity/auth.py,sha256=SPD5HXycsG5SBb2yf1pR5vee6gwG_UkWLkzmP02sWlY,6565
3
+ eigeningenuity/auth.py,sha256=RjmtLBS6m4YhDZJa7RgB4RYWJDhE4zd-9tKeOz0iNug,7578
4
4
  eigeningenuity/elastic.py,sha256=WG4nlsJXNs_-m76jtj46UfgvLgWLvn6d6QW2dk7LBI4,6648
5
5
  eigeningenuity/events.py,sha256=wUc1TkT7047gduNuNfzkSO5tK13ErJdeI2K5cPXhNCY,3336
6
6
  eigeningenuity/historian.py,sha256=sWHOCYPPRV9nbIkLsSiJeJLpuX3CtrAFlU2l1CLn0B4,36337
7
- eigeningenuity/historianmulti.py,sha256=8_N6meXvTudnDdiHCc_Blgu1kvA5jApZgJlbVZJ93BE,20772
8
- eigeningenuity/settings.py,sha256=ImYplpNINf1dYaUdarZaxvwf3zHSjE1CG7bOEUqnLT0,2794
7
+ eigeningenuity/historianmulti.py,sha256=EoXxuCT5lNqoENC9mK1aHDnN_KDQK554ka_x73t4Jb8,20587
8
+ eigeningenuity/settings.py,sha256=sCY7AONBrc0IWSa3D37Scu_JapQoEBfJbRbY7BdDoBM,4212
9
9
  eigeningenuity/smartdash.py,sha256=spzoRXO4tu7cDAd4cwbyxo9RBnYvjbJoXQq8zbXkMEw,3009
10
10
  eigeningenuity/sql.py,sha256=y-IMu1fdZjMGFcg7ue7Ubhr0-BDTiUW01x8I7tSR700,5059
11
- eigeningenuity/util.py,sha256=AEbi-aOyyqkszSLRX7QBEXA2t7gyJKy14BKR8fu3PtE,18074
11
+ eigeningenuity/util.py,sha256=G29hwukPvaq66RYpDThCY9mEB3jili6i5BaxV4-Rmwc,18593
12
12
  eigeningenuity/core/__init__.py,sha256=wIFyRpfPzwi5_ALu0icdE3lxlMZgUrZ7y4o69XpVusw,8685
13
13
  modelbuilder/__init__.py,sha256=HSsHItu5BbGQiHYTG00QPMNDbC3RkRUaaN50YpksIUA,171
14
14
  modelbuilder/src/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -39,7 +39,7 @@ modelbuilder/src/queries/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
39
39
  modelbuilder/src/queries/cypherbuilder.py,sha256=_CIb2eQSa1N23m3ebzoCF-W9DPvKoRHAIF9wyt1EuV4,10715
40
40
  modelbuilder/src/queries/query.py,sha256=fEkGv49yxeL0Sz5bMmC3-Dt0_9qoZBz37hsTY8pQVIA,2568
41
41
  modelbuilder/src/queries/typedefs.py,sha256=JebIVlrLHylhisziGgG2YOJcTapT2tyVc3PsqeHw0RU,10437
42
- python_eigen_ingenuity_nocli-0.5.7b4.dist-info/METADATA,sha256=H8s_GOnFU4g5Y5IhR_APpVPRLGsA-5WcMqvJbg2TzmE,1205
43
- python_eigen_ingenuity_nocli-0.5.7b4.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
44
- python_eigen_ingenuity_nocli-0.5.7b4.dist-info/top_level.txt,sha256=lFiZ43CY_1bmdtRidIXbA6rrY2d92Rs-9tH8pcgI-XU,28
45
- python_eigen_ingenuity_nocli-0.5.7b4.dist-info/RECORD,,
42
+ python_eigen_ingenuity_nocli-0.5.8.dist-info/METADATA,sha256=3TGHhIQvKUWzLWlAEVyI9M9FlzbWmd7AtlW0F8auW0M,1203
43
+ python_eigen_ingenuity_nocli-0.5.8.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
44
+ python_eigen_ingenuity_nocli-0.5.8.dist-info/top_level.txt,sha256=lFiZ43CY_1bmdtRidIXbA6rrY2d92Rs-9tH8pcgI-XU,28
45
+ python_eigen_ingenuity_nocli-0.5.8.dist-info/RECORD,,