REST API
4.0.0
REST API for SafeNet Network HSMs
|
The REST API supports file input and output. This allows you to send and receive files within requests and responses.
When receiving a file the response object will contain the contents of the file in a buffer that can then be iterated and saved to a file.
Example:
r = requests.get("/api/lunasa/webServer/config/csr", stream=True, cookies=cookies, verify=False, allow_redirects=False) with open("ssl.csr", 'wb') as csr: for chunk in r.iter_content(chunk_size=1024): if chunk: csr.write(chunk)
Sending files requires one minor change to the request. The header Content-Type needs to be set to 'octet-stream' to notify the server that it will be receiving a file. In python passing the file object to the data parameter is all that is required.
Header format:
headers = {'Content-Type': "application/vnd.safenetinc.lunasa+octet-stream;version="}
Example:
with open(filename, 'rb') as payload: r = requests.put("/api/lunasa/webServer/config/certificate", stream=True, cookies=cookies, data=payload, header=headers, verify=False, allow_redirects=False)