This repository was archived by the owner on Aug 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwfrs.py
59 lines (47 loc) · 1.85 KB
/
wfrs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""
wfrs.py
Very simple authenticated API wrapper for requests.Session object
for use with WebFOCUS
Modeled from Ira Kaplan at [email protected]
"""
import xml.etree.ElementTree as ET
import requests
class WF_Session(requests.Session):
def __init__(self):
requests.Session.__init__(self)
self.IBIWF_SES_AUTH_TOKEN = None
def _save_ibi_csrf_token(self, xml):
"""Save IBI_CSRF_Token_Value from response to sign-on request."""
tree = ET.fromstring(xml)
token = tree.find('properties/entry[@key="IBI_CSRF_Token_Value"]')
token_value = token.attrib['value']
self.IBIWF_SES_AUTH_TOKEN = token_value
def mr_sign_on(self,
protocol='http',
host='localhost',
port='8080',
userid='admin',
password='admin'):
"""WebFOCUS Repository: Authenticating WebFOCUS Sign-On Requests."""
# Stored for sign off
self.protocol = protocol
self.host = host
self.port = port
data = {
'IBIRS_action': 'signOn',
'IBIRS_userName': userid,
'IBIRS_password': password,
}
url = '{}://{}:{}/ibi_apps/rs/ibfs'.format(self.protocol,
self.host,
self.port)
response = self.post(url=url, data=data)
self._save_ibi_csrf_token(response.content)
def mr_signoff(self):
"""WebFOCUS Repository: Signing-Off From WebFOCUS."""
data = {'IBIRS_action': 'signOff'}
url = '{}://{}:{}/ibi_apps/rs/ibfs'.format(self.protocol,
self.host,
self.port)
self.IBIWF_SES_AUTH_TOKEN = None
self.post(url=url, data=data)