Search code examples
oracle-cloud-infrastructureoci-python-sdk

how to get a Pre-Authenticated request for an object in OCI object storage using python SDK?


I want to create pre-authenticated request for an object inside a bucket in the OCI object storage using python SDK. I found out that I can use get_preauthenticated_request for the bucket to put objects inside the bucket but not to get the objects pre-authenticated. I can create a pre-authenticated request using the OCI console but I need to do it in a python script. can anybody help me in this issue?


Solution

  • You can use create_preauthenticated_request (see code) for both buckets and individual objects.

    The difference is in the access type:

    • ANY_OBJECT_WRITE is for the whole bucket
    • OBJECT_READ, OBJECT_READ_WRITE and OBJECT_WRITE are for objects

    So you should be able to create a Pre-Authenticated Request with something like

    request_details = create_preauthenticated_request_details()
    request_details.access_type("ObjectReadWrite")
    par = create_preauthenticated_request("namespace", "bucket", request_details)
    

    You can find more on the request details here and for the request itself here.

    Let me know if this works for you, I don't have an account to test against at the moment.