2
0
mirror of https://github.com/xcat2/confluent.git synced 2024-11-24 18:41:55 +00:00

Sample script to navigate first password change

This commit is contained in:
Jarrod Johnson 2021-08-27 16:13:14 -04:00
parent ce98ff6b3d
commit c48f3a8b59

40
misc/setinitalpwd.py Normal file
View File

@ -0,0 +1,40 @@
#!/usr/bin/python2
import pyghmi.util.webclient as webclient
import json
import os
import sys
tmppassword = 'to3BdS91ABrd'
missingargs = False
if 'XCCUSER' not in os.environ:
print('Must set XCCUSER environment variable')
missingargs = True
if 'XCCPASS' not in os.environ:
print('Must set XCCPASS environment variable')
missingargs = True
if missingargs:
sys.exit(1)
w = webclient.SecureHTTPConnection(sys.argv[1], 443, verifycallback=lambda x: True)
w.connect()
adata = json.dumps({'username': 'USERID', 'password': 'PASSW0RD'})
headers = {'Connection': 'keep-alive', 'Content-Type': 'application/json'}
w.request('POST', '/api/login', adata, headers)
rsp = w.getresponse()
if rsp.status == 200:
rspdata = json.loads(rsp.read())
w.set_header('Content-Type', 'application/json')
w.set_header('Authorization', 'Bearer ' + rspdata['access_token'])
if '_csrf_token' in w.cookies:
w.set_header('X-XSRF-TOKEN', w.cookies['_csrf_token'])
if rspdata.get('pwchg_required', False):
print(repr(w.grab_json_response('/api/function', {'USER_UserPassChange': os.environ['XCCPASS']})))
print(repr(w.grab_json_response('/api/dataset', {
'USER_GlobalPassExpWarningPeriod': '0',
'USER_GlobalPassExpPeriod': '0',
'USER_GlobalMinPassReuseCycle': '0',
'USER_GlobalMinPassReuseCycle': '0',
'USER_GlobalMinPassChgInt': '0',
})))
#print(repr(w.grab_json_response('/api/function', {'USER_UserPassChange': '1,' + os.environ['XCCPASS']})))