Page 36 - MSDN Magazine, March 2019
P. 36

Figure 3 The Logic App Action that Handles the File Creation Event in SharePoint
from the Azure Functions connector, but this time, instead of the several file attributes, pick File Content. Once you’ve obtained the hash values for both file metadata and file content, it’s time to store it on the blockchain network. For this purpose, I’m using Azure Blockchain Workbench (aka.ms/abcworkbench) as the runtime environment for smart contracts running on Ethereum. Blockchain Workbench is expected to support multiple blockchain platforms, but for now
I’ll stick to Ethereum.
Access to the digital ledger can be obtained by sending
a message to the Azure Service Bus deployed as part of the Blockchain Workbench solution. An external system like a Logic App action can communicate with a smart contract hosted in Blockchain Workbench by sending a message to Service Bus. The message is picked by the Blockchain Workbench runtime and a new block- chain transaction is created, containing the message.
The code in Figure 2 implements the ComputeHashFunction Azure Function for computing a hash using the SHA256 algo- rithm. After reading the request body in the Run method, the function computes the hash using the SHA256 library available in the System.Security.Cryptography namespace. The hash value is returnedasaUTF8-encodedstring.
Communication with Ethereum can happen only by generating a transaction that invokes a smart contract, as depicted in Figure 5. To send a message from a Logic App flow to Service Bus you can use the Send message action on the Service Bus connector. A connection to an Azure Service Bus is identified by a connection nameandaconnectionstring.Youcanenteranyconvenientname
The Logic App flow is triggered when a new document is uploaded to a SharePoint site.
The Logic App flow is triggered when a new document is uploaded to a SharePoint site. This event is handled by one of the “When a file is created ...” actions on the SharePoint connector (as depicted in Figure 3). To configure this action, after entering your authentication credentials for SharePoint, you have to spec- ify the site address of the SharePoint site to monitor for new files, and the specific folder where files are uploaded. You can also set the frequency of polling this folder and checking for new files. A reasonable setting is to check once per minute.
The next step in the flow is, as already anticipated, the hashing of the uploaded file’s content and metadata. As I’ve implemented the hashing function as an Azure Function, all you need to invoke this function is the Choose an Azure function action
from the Azure Functions connector. Once you se-
lect ComputeHashFunction from the list of available
functions, you’ll be prompted to specify the request
body that will be passed to the function itself. This is
a JSON object that will be transferred in input to the
function, obtaining its hash value as output. I’ve defined
the following attributes as file metadata, as shown in
Figure 4: contentType, etag, id, name and path.
as connection name, and you obtain the Service Bus connection string from the Azure Portal where it’s deployed. The message to send to the Service Bus also requires the following parameters:
• requestId: A unique identifier for the request generated by the Logic App action
• processedDateTime: Timestamp of the request being sent • userChainIdentifier: User address in the deployed
Ethereum network
• applicationName: Name of the smart contract being
invoked on Ethereum
• workflowName: Name of the workflow being invoked on
Blockchain Workbench
The previous step is needed to hash the file metadata. Now I must hash also the entire file content, to preserve it in an immutable state in the blockchain network. As before, add another Choose an Azure function action
Figure 4 Attributes in the Request Body for the Hash Function
30 msdn magazine
Blockchain


































































































   34   35   36   37   38