easy-utils-dev 2.136__py3-none-any.whl → 2.138__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.
- easy_utils_dev/debugger.py +1 -1
- easy_utils_dev/ept.py +654 -555
- easy_utils_dev/wsnoclib.py +60 -14
- {easy_utils_dev-2.136.dist-info → easy_utils_dev-2.138.dist-info}/METADATA +1 -1
- {easy_utils_dev-2.136.dist-info → easy_utils_dev-2.138.dist-info}/RECORD +7 -7
- {easy_utils_dev-2.136.dist-info → easy_utils_dev-2.138.dist-info}/WHEEL +0 -0
- {easy_utils_dev-2.136.dist-info → easy_utils_dev-2.138.dist-info}/top_level.txt +0 -0
easy_utils_dev/wsnoclib.py
CHANGED
|
@@ -14,6 +14,7 @@ from .FastQueue import FastQueue
|
|
|
14
14
|
import tempfile , os
|
|
15
15
|
from kafka import KafkaConsumer
|
|
16
16
|
from easy_utils_dev.utils import kill_thread
|
|
17
|
+
import atexit
|
|
17
18
|
|
|
18
19
|
|
|
19
20
|
|
|
@@ -35,6 +36,8 @@ class KafkaConfig :
|
|
|
35
36
|
self.base_url = None
|
|
36
37
|
self.kafka_thread=None
|
|
37
38
|
|
|
39
|
+
|
|
40
|
+
|
|
38
41
|
class WSNOCLIB :
|
|
39
42
|
def __init__(
|
|
40
43
|
self,
|
|
@@ -46,7 +49,8 @@ class WSNOCLIB :
|
|
|
46
49
|
debug_homepath='./debug/',
|
|
47
50
|
request_max_count=30,
|
|
48
51
|
tmp_dir = tempfile.gettempdir() ,
|
|
49
|
-
kafka = KafkaConfig()
|
|
52
|
+
kafka = KafkaConfig(),
|
|
53
|
+
register_atexit=True
|
|
50
54
|
):
|
|
51
55
|
self.logger = DEBUGGER(f'{debug_name}-{ip}',level=debug_level,homePath=debug_homepath)
|
|
52
56
|
self.disabledWarnings = self.disableUrlWarnings()
|
|
@@ -55,6 +59,8 @@ class WSNOCLIB :
|
|
|
55
59
|
self.username = username
|
|
56
60
|
self.password = password
|
|
57
61
|
self.external_nsp = False
|
|
62
|
+
self.api_count = 0
|
|
63
|
+
self.api_count_limit = 999999999999
|
|
58
64
|
self.temp_dir = os.path.join(tmp_dir , 'wsnoclib' )
|
|
59
65
|
self.baseUrl = self.createBaseUrl()
|
|
60
66
|
self.session = requests.Session()
|
|
@@ -69,8 +75,12 @@ class WSNOCLIB :
|
|
|
69
75
|
self.nes=[]
|
|
70
76
|
self.loggedOut = False
|
|
71
77
|
self.alarms_store=[]
|
|
78
|
+
self.refresh_inprogress = False
|
|
72
79
|
self.kafka = kafka
|
|
73
80
|
self.refresh_thread = None
|
|
81
|
+
self.session = WSNOCSession(self)
|
|
82
|
+
if register_atexit :
|
|
83
|
+
atexit.register(self.goodbye)
|
|
74
84
|
|
|
75
85
|
def getLogger(self) :
|
|
76
86
|
return self.logger
|
|
@@ -157,15 +167,11 @@ class WSNOCLIB :
|
|
|
157
167
|
def logout(self,logout=True) :
|
|
158
168
|
self.logger.info(f"Logging out from {self.address} ...")
|
|
159
169
|
body = f"token={self.access_token}&token_type_hint=token"
|
|
160
|
-
self.logger.debug(f"logout body={body}")
|
|
161
170
|
header = {"Content-Type": "application/x-www-form-urlencoded"}
|
|
162
|
-
self.logger.debug(f"logout header={header} address={self.address}")
|
|
163
171
|
URL = f"https://{self.address}/rest-gateway/rest/api/v1/auth/revocation"
|
|
164
|
-
self.
|
|
165
|
-
r = requests.post(
|
|
172
|
+
r = self.session.post(
|
|
166
173
|
url = URL ,
|
|
167
174
|
auth=BAuth(self.username, self.password),
|
|
168
|
-
verify=False,
|
|
169
175
|
data=body,
|
|
170
176
|
headers=header
|
|
171
177
|
)
|
|
@@ -177,29 +183,31 @@ class WSNOCLIB :
|
|
|
177
183
|
kill_thread(self.kafka.kafka_thread)
|
|
178
184
|
except :
|
|
179
185
|
pass
|
|
180
|
-
self.logger.info(f"Logging out from '{self.address}' response.code={r.status_code}")
|
|
181
|
-
self.logger.debug(f"Logout response is {r.text}")
|
|
182
|
-
if r.status_code != 200 :
|
|
183
|
-
self.logger.debug(f'fail message is {r.text}')
|
|
184
|
-
self.logger.error(f"Failed logging out from {self.address}")
|
|
185
|
-
self.numberOfRequests = 0
|
|
186
186
|
if logout :
|
|
187
187
|
self.loggedOut = True
|
|
188
|
-
self.logger.debug("logout function completed. return TRUE exit status")
|
|
189
188
|
try :
|
|
190
189
|
r.close()
|
|
191
190
|
except :
|
|
192
191
|
pass
|
|
193
192
|
return True
|
|
194
193
|
|
|
194
|
+
def goodbye(self):
|
|
195
|
+
try :
|
|
196
|
+
self.logout(True)
|
|
197
|
+
except :
|
|
198
|
+
pass
|
|
199
|
+
|
|
195
200
|
def runAutoRefreshThread(self) :
|
|
196
201
|
self.logger.info(f'Waiting for auto refresh in {self.tokenRefreshPeriod}sec...')
|
|
197
202
|
sleep(self.tokenRefreshPeriod)
|
|
198
203
|
self.logger.info(f"Waiting period completed. Starting Revoking/Login process ...")
|
|
204
|
+
self.refresh_inprogress = True
|
|
199
205
|
self.logout(logout=False)
|
|
200
|
-
sleep(
|
|
206
|
+
sleep(30)
|
|
201
207
|
self.logger.info(f"Logout process completed. Starting Reconnecting ...")
|
|
202
208
|
self.connect(self.auto_refresh_token)
|
|
209
|
+
self.refresh_inprogress = False
|
|
210
|
+
self.event.dispatchEvent('onTokenRefresh', self.token)
|
|
203
211
|
|
|
204
212
|
def kafka_connect( self ,
|
|
205
213
|
user ,
|
|
@@ -660,6 +668,44 @@ class WSNOCLIB :
|
|
|
660
668
|
URL = "/oms1350/data/common/sessionInfo"
|
|
661
669
|
return self.get(URL)
|
|
662
670
|
|
|
671
|
+
|
|
672
|
+
class WSNOCSession(requests.Session):
|
|
673
|
+
from easy_utils_dev.wsnoclib import WSNOCLIB
|
|
674
|
+
def __init__(self, wsnoc : WSNOCLIB):
|
|
675
|
+
super().__init__()
|
|
676
|
+
self.headers.update({"Content-Type": "application/json"}) # base defaults
|
|
677
|
+
self._wsnoc = wsnoc
|
|
678
|
+
self.verify = False
|
|
679
|
+
|
|
680
|
+
def rebuild_auth(self, prepared_request, response):
|
|
681
|
+
return
|
|
682
|
+
|
|
683
|
+
def hold_for_token_refresh(self) :
|
|
684
|
+
while self._wsnoc.refresh_inprogress :
|
|
685
|
+
sleep(.1)
|
|
686
|
+
|
|
687
|
+
def request(self, method, url , retries=0 , **kwargs):
|
|
688
|
+
self._wsnoc.logger.debug(f'[{method}] : {url}')
|
|
689
|
+
self.hold_for_token_refresh()
|
|
690
|
+
self._wsnoc.api_count += 1
|
|
691
|
+
token = self._wsnoc.getLatestToken().get('bearer_token')
|
|
692
|
+
request_headers = kwargs.get('headers' , {})
|
|
693
|
+
if not request_headers.get('Authorization') :
|
|
694
|
+
request_headers['Authorization'] = token
|
|
695
|
+
kwargs['headers'] = request_headers
|
|
696
|
+
request = super().request(method, url, **kwargs )
|
|
697
|
+
for i in range(retries) :
|
|
698
|
+
if request.ok :
|
|
699
|
+
break
|
|
700
|
+
if not request.ok :
|
|
701
|
+
sleep(1)
|
|
702
|
+
self.hold_for_token_refresh()
|
|
703
|
+
request = super().request(method, url, **kwargs )
|
|
704
|
+
self._wsnoc.logger.debug(f'[Try-{i}] [{method}] : {url}- {request.status_code}')
|
|
705
|
+
self._wsnoc.logger.info(f'[{method}] : {url}- {request.status_code}')
|
|
706
|
+
return request
|
|
707
|
+
|
|
708
|
+
|
|
663
709
|
if __name__ == '__main__' :
|
|
664
710
|
# noc = WSNOCLIB('10.20.30.55' , 'admin' , 'Nokia@2024')
|
|
665
711
|
# noc.connect(auto_refresh_token=True)
|
|
@@ -8,10 +8,10 @@ easy_utils_dev/brevosmtp.py,sha256=A5n13MnVQnDuSjYQ91-MLftmqfg3VQ-36Zqw9OtoTB4,3
|
|
|
8
8
|
easy_utils_dev/check_license.py,sha256=C8vKXwaduoF3FSuDJ-J_j5jStNNyUdS-mOdLNfsCjmc,4825
|
|
9
9
|
easy_utils_dev/cplib.py,sha256=TPCFNQh4jYSGsm_CrMdivmD3G5B1rprco2O4B0BSnzo,19570
|
|
10
10
|
easy_utils_dev/custom_env.py,sha256=vxrjikpSNJlKfoBE-ef88UExlpXucUe-HcwHMn3gfB0,1510
|
|
11
|
-
easy_utils_dev/debugger.py,sha256=
|
|
11
|
+
easy_utils_dev/debugger.py,sha256=Oz4WcT59FbHouTpprslocljDvevFdmP9hc_zNRVmSdE,18318
|
|
12
12
|
easy_utils_dev/easy_oracle.py,sha256=Jyc3HSl6eyLayjS8NoE4GOaf8otQlonR5_qOg2h1DjE,2157
|
|
13
13
|
easy_utils_dev/encryptor.py,sha256=f5Zjn0DGtXCyhldpVnBtfcTb4h4Wp0eQPHusEYwIags,1512
|
|
14
|
-
easy_utils_dev/ept.py,sha256=
|
|
14
|
+
easy_utils_dev/ept.py,sha256=X-Z0_XCNfKK1TxQZquPMBqo3ZuxnK4TvWAYPnBUMlPI,25363
|
|
15
15
|
easy_utils_dev/exceptions.py,sha256=6eTYBa8AIXC0wI6zgkqsLreSXyPf459G-ToO7ziQuK4,1669
|
|
16
16
|
easy_utils_dev/filescompressor.py,sha256=iKAtLfkEXOuvvqF56jH0D9KAAeZ7iaa_sRaJnyYkxiE,2875
|
|
17
17
|
easy_utils_dev/generate_license.py,sha256=fr_eoSjKCmDmAEBc6FWFXZxGQOHx9XO6hEK8dcyVUlA,3319
|
|
@@ -27,11 +27,11 @@ easy_utils_dev/temp_memory.py,sha256=gfC-izYw8Sg1DD5iOdL8R5-fdB5RK0qkXZie9WmFjPA
|
|
|
27
27
|
easy_utils_dev/uiserver.py,sha256=d9jImwgSURMH4MIU4Zkro2b20cAbuV8rO_If42FVyZ4,6826
|
|
28
28
|
easy_utils_dev/utils.py,sha256=BmVnbxc336c6WTeDFcEHN6Mavt7fJrIEyK4GXODV3gI,13345
|
|
29
29
|
easy_utils_dev/winserviceapi.py,sha256=2ZP6jaSt1-5vEJYXqwBhwX-1-eQ3V3YzntsoOoko2cw,18804
|
|
30
|
-
easy_utils_dev/wsnoclib.py,sha256=
|
|
30
|
+
easy_utils_dev/wsnoclib.py,sha256=z18kdPJJeNYAaomqH1t6KfTWm77BNPx6aPAW9P0PSOc,30813
|
|
31
31
|
easy_utils_dev/wsselib.py,sha256=YweScnoAAH_t29EeIjBpkQ6HtX0Rp9mQudRsRce2SE8,7920
|
|
32
32
|
easy_utils_dev/ept_sql/create_dirs.sql,sha256=KWfX-Nc6lvr_BC-P6O97NE0idoPW4GNKUKUCgonJhto,3508
|
|
33
33
|
easy_utils_dev/ept_sql/create_ept_tables.sql,sha256=WDHyIyeReV8_QaYBPIpSy-lto3OKvZtex1tWs-FPURQ,67737
|
|
34
|
-
easy_utils_dev-2.
|
|
35
|
-
easy_utils_dev-2.
|
|
36
|
-
easy_utils_dev-2.
|
|
37
|
-
easy_utils_dev-2.
|
|
34
|
+
easy_utils_dev-2.138.dist-info/METADATA,sha256=uN_YPuZajKHryq24B8n7zfC3qVYpw9oXaDabo_Vfo1E,510
|
|
35
|
+
easy_utils_dev-2.138.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
|
|
36
|
+
easy_utils_dev-2.138.dist-info/top_level.txt,sha256=7vBsrpq7NmilkdU3YUvfd5iVDNBaT07u_-ut4F7zc7A,15
|
|
37
|
+
easy_utils_dev-2.138.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|