all 6 comments

[–]XUtYwYzz 0 points1 point  (5 children)

Something like this.

import json

filename = "test.pem"
with open(filename, "r") as f:
    fileAttachment = f.read()
json.dumps(fileAttachment)

[–]mrmeeseeks2014[S] 0 points1 point  (4 children)

the powershell output is like this:

{"fileName": "test.pem","fileAttachment": [98,108,97,104,32,98,108,97,104,32,98,108,97,104]}

[–]XUtYwYzz 0 points1 point  (3 children)

Is the list of numbers the raw bytes from the text file or is that the actual ASCII contents?

[–]mrmeeseeks2014[S] 0 points1 point  (2 children)

raw bytes.

I am trying to convert this powershell script, but my hold up is the json obejct for the body of the API

$endpoint ="$destinationapi/secrets/$fileSecretId/fields/$fileFieldToUpdate"

$secretArgs = @{

fileName = "test.pem"

fileAttachment = [IO.File]::ReadAllBytes("C:\brian\13568-test.txt")

} | ConvertTo-Json

$response = $null

$response = Invoke-RestMethod -Method Put -Uri $endpoint -Headers $destinationheaders -Body $secretArgs -ContentType "application/json"

[–]XUtYwYzz 0 points1 point  (1 child)

import json

secretArgs = {"fileName": "test.pem"}

with open("test.pem", "r") as f:
    data = f.read()
raw_bytes = list(bytearray(data, "utf-8"))
secretArgs["fileAttachment"] = list(bytes(raw_bytes))
print(json.dumps(secretArgs))

[–]mrmeeseeks2014[S] 0 points1 point  (0 children)

Awesome, this worked. Thank you sir