implemented headers for rest platform and option to turn ssl verification off
This commit is contained in:
parent
7e2f204141
commit
0f9cafb456
@ -12,6 +12,8 @@ authentication = basic
|
|||||||
username = my_username
|
username = my_username
|
||||||
password = my_password
|
password = my_password
|
||||||
payload = {"var1": "hi", "var2": 1}
|
payload = {"var1": "hi", "var2": 1}
|
||||||
|
headers = {"Content-Type": "application/json"}
|
||||||
|
verify = false
|
||||||
```
|
```
|
||||||
> **Returns:** `value_template` as rendered string
|
> **Returns:** `value_template` as rendered string
|
||||||
|
|
||||||
@ -26,6 +28,8 @@ payload = {"var1": "hi", "var2": 1}
|
|||||||
| username | No | Username to use for auth. | string |
|
| username | No | Username to use for auth. | string |
|
||||||
| password | No | Password to use for auth. | string |
|
| password | No | Password to use for auth. | string |
|
||||||
| payload | No | Payload for post request. | json |
|
| payload | No | Payload for post request. | json |
|
||||||
|
| headers | No | Custom headers for get or post | json |
|
||||||
|
| verify | No | Turn TLS verification on or off, default is True | true,false |
|
||||||
|
|
||||||
> **Working example:**
|
> **Working example:**
|
||||||
>```ini
|
>```ini
|
||||||
@ -62,6 +66,10 @@ class Platform:
|
|||||||
self.method = "GET"
|
self.method = "GET"
|
||||||
if not hasattr(self, "authentication"):
|
if not hasattr(self, "authentication"):
|
||||||
self.authentication = None
|
self.authentication = None
|
||||||
|
if not hasattr(self, "headers"):
|
||||||
|
self.headers = None
|
||||||
|
if not hasattr(self, "verify"):
|
||||||
|
self.verify = True
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
if self.authentication:
|
if self.authentication:
|
||||||
@ -72,14 +80,16 @@ class Platform:
|
|||||||
else:
|
else:
|
||||||
auth = None
|
auth = None
|
||||||
|
|
||||||
|
verify = False if str(self.verify).lower() == "false" else True
|
||||||
|
|
||||||
if self.method.upper() == "GET":
|
if self.method.upper() == "GET":
|
||||||
try:
|
try:
|
||||||
value = get(self.resource, auth=auth).json()
|
value = get(self.resource, auth=auth, headers=self.headers, verify=verify).json()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
value = f"{e}"
|
value = f"{e}"
|
||||||
|
|
||||||
elif self.method.upper() == "POST":
|
elif self.method.upper() == "POST":
|
||||||
payload = json.loads(self.payload.replace("'", '"'))
|
payload = json.loads(self.payload.replace("'", '"'))
|
||||||
value = post(self.resource, data=payload, auth=auth)
|
value = post(self.resource, data=payload, auth=auth, headers=self.headers, verify=verify)
|
||||||
value_template = render_template_string(self.value_template, value=value)
|
value_template = render_template_string(self.value_template, value=value)
|
||||||
return value_template
|
return value_template
|
||||||
|
Loading…
x
Reference in New Issue
Block a user