Introduction: This document describes about how to create API proxy for Azure Blob Storage with assign message and java script policy.
Here, we will create a container in Azure Blob Storage and then create an API proxy to access that container to create/delete/read blobs or files and also read the list of blobs or files in the container to access it.
Prerequisite: Create a container in Azure Storage with any name and generate SAS key to access it, Please click here to know the steps to create container and generate SAS Key for the container.
I have created one container with the name “data”.
Copy SAS Key and URL to use in SAP API Management
SAS Key :- sp=r&st=2023-12-24T13:36:40Z&se=2023-12-24T21:36:40Z&spr=https&sv=2022-11-02&sr=c&sig=sdsad%dasdsdDFasdasda%2FgfUCnxte8NtVPtswt2iMA%5F
URL:- https://<StorageAccount>.blob.core.windows.net/
Create an API provider in APIM for Azure Blob Storage.
Create API Proxy for Azure Storage Rest API.
***We need only three operations get, put and delete. remove all other operations and click on ok.
Activity | Azure Blob Permission (in access policy) | http Operation | Header | After https://<hostname>:<port>/<ContainerName or Resource Name>/ | Query Parameters |
Read the file names or list from storage | List | Get | x-ms-blob-type=blockblob | ?restype=container&comp=list&<SAS Key> | |
Read file from storage | Read | Get | x-ms-blob-type=blockblob | <FilePath or FileName> | <SAS Key> |
Create File | Create | Put | x-ms-blob-type=blockblob | <FilePath or FileName> | <SAS Key> |
Delete File | Delete | Delete | x-ms-blob-type=blockblob | <FilePath or FileName> | <SAS Key> |
Overwrite file | Write | Put | x-ms-blob-type=blockblob | <FilePath or FileName> | <SAS Key> |
*****Based on the activity, SAP API management will pass the headers and query parameters with the request to Azure Storage.
For reading list, APIM has to send additional query parameters “restype=container&comp=list” when request comes with get operations and without <FilePath or FileName>
So the condition string of “AMtoGetList” will check if request verb is “GET” and there is no <FilePath or FileName> after resource or container name then execute this policy else no action and flow will go to next policy.
Question: Why are we using javaScript policy for sig parameter?
Answer: Because signature value can have some special characters like “%” which will be encoded while sending the request on wire, so “%” will be converted into “%25” and it will change the signature value and authentication would be failed at Azure’s end.
Solution: Decode signature value before sending it on wire so that after encoding it will become the actual value of signature
This policy will call java script created “setSig”, which you can write under scripts
To create a script, click on “+”
Give any name and write the code in the script resource, here we can use decodeURIComponent() function to decode value of sig parameter.
Here, we can see response body with the content sent earlier while creating file.
Conclusion: This document explained that how to create an API proxy for Azure Blob Storage and perform get/put/delete operations.