Here is an example of a working python script used to send a Terraform config file to the IriusRisk API OTM endpoint from a Linux OS:
import requests
api_endpoint = "https://yourServer.iriusrisk.com"
api_token = 'tokenValue'
api_endpointTF = "/api/v1/products/terraform"
url = api_endpoint+api_endpointTF
file_name = "file_name.tf"
file_path = "full_path_of_the_file.tf"
product_id = "product-id_name"
product_name = "product-name"
headers = { 'api-token': (api_token) }
files = [('tf-file',(file_name , open(file_path,'rb') , 'application/octet-stream')) ]
data = { 'product-id': product_id, 'name': product_name }
response = requests.post(url, headers=headers, files=files, data=data)
print (response)
print (response.text)
And here is an example of a working python script used from a Windows OS:
import requests
api_endpoint = "https://yourServer.iriusrisk.com"
api_token = 'tokenValue'
api_endpointTF = "/api/v1/products/terraform"
url = api_endpoint+api_endpointTF
file_name = "file_name.tf"
file_path = "full_path_of_the_file.tf_for_example___C:\\Terra\\file_name.tf"
product_id = "product-id_name"
product_name = "product-name"
headers = { 'api-token': (api_token) }
files = [('tf-file',(file_name , open(file_path,'rb') , 'application/octet-stream')) ]
data = { 'product-id': product_id, 'name': product_name }
response = requests.post(url, headers=headers, files=files, data=data)
print (response)
print (response.text
If you have a mapping file to attach as well, then the files section will look like this:
files=[
('tf-file',('file_name.tf',open('full/path.tf','rb'),'application/octet-stream')),
('mapping-file',('iriusrisk-tf-aws-mapping.yaml',open('full/path.yaml','rb'),'text/yaml'))
]
A successful response should come back with something similar to this:
<Response [201]>
{"ref":"testingterra2","name":"testingterra2","revision":"1","type":"STANDARD","status":"OPEN","priority":"0","tags":null,"workflowState":"creation","udts":[],"groups":null,"users":null}
PLEASE NOTE:
There can be code changes for other formats like visio or cloudformation regarding the application, the endpoint and the file type, and it would work using brackets or keys:
Cloudformation: application/json or text/yaml
Terraform: application/octet-stream
Visio: application/octet-stream
mapping files: text/yaml
You can find an example using cloudformation from a Linux OS below:
import requests
api_endpoint = "https://yourServer.iriusrisk.com"
api_token = "tokenValue"
api_endpointCF = "/api/v1/products/cloudformation"
url = api_endpoint+api_endpointCF
file_name = "file_name.json"
file_path = "full_path_of_the_file.json"
product_id = "product-id_name"
product_name = "product-name"
headers = {'api-token': (api_token)}
files = [('cft-file',(file_name , open(file_path,'rb') ,'application/json')) ]
data = {'product-id': product_id, 'name': product_name }
response = requests.post(url, headers=headers, files=files, data=data)
print (response)
print (response.text)
And from a Windows OS:
import requests
api_endpoint = "https://yourServer.iriusrisk.com"
api_token = "tokenValue"
api_endpointCF = "/api/v1/products/cloudformation"
url = api_endpoint+api_endpointCF
file_name = "file_name.json"
file_path = "full_path_of_the_file.json_for_example___C:\\cloudformation\\file_name.json"
product_id = "product-id_name"
product_name = "product-name"
headers = {'api-token': (api_token)}
files = [('cft-file',(file_name , open(file_path,'rb') ,'application/json')) ]
data = {'product-id': product_id, 'name': product_name }
response = requests.post(url, headers=headers, files=files, data=data)
print (response)
print (response.text)
For more advanced troubleshooting you can add some tools to the script and run it again, you want to add these lines:
from requests_toolbelt.utils import dump print(dump.dump_all(response).decode("utf-8"))
The full file would look like this:
import requests
from requests_toolbelt.utils import dump
api_endpoint = "https://yourServer.iriusrisk.com"
api_token = 'tokenValue'
api_endpointTF = "/api/v1/products/terraform"
url = api_endpoint+api_endpointTF
file_name = "file_name.tf"
file_path = "full_path_of_the_file.tf"
product_id = "product-id_name"
product_name = "product-name"
headers = { 'api-token': (api_token) }
files = [('tf-file',(file_name , open(file_path,'rb') , 'application/octet-stream')) ]
data = { 'product-id': product_id, 'name': product_name }
response = requests.post(url, headers=headers, files=files, data=data)
print (response)
print (response.text)
print(dump.dump_all(response).decode("utf-8"))
You can use this output to submit a ticket to our support team to help resolve your issue as well!
If you are using an on-prem solution of IriusRisk, you can also attach the Startleft logs to your trouble ticket:
docker logs iriusrisk-startleft
Comments
0 comments
Please sign in to leave a comment.