DAML HUb facing issues when DAZL code is calling outside apis

Hello Guys,

I am using the DAZL library to write a python bot and need to call and thirdparty api when the ledger is ready. In our company we set the proxy and call the third party api. It works for us. But we want to demo using the DAML Hub.

Here is the code snippet of the python code. I am replacing the api with a get to w3schools which is also facing the similar issue.

Can someone please help me?

import csv

import json

import logging

import os

from os.path import dirname, join

import dazl

import requests

from requests.structures import CaseInsensitiveDict

dazl.setup_default_logger(logging.INFO)

def main():

    url = os.getenv('DAML_LEDGER_URL')

    

    party = "ledger_id"

    

    network = dazl.Network()

    network.set_config(url=url)

    client = network.aio_party(party)

    def check_stuff():

        # ADIA api should be called here

        logging.info(f'A22222222222222222222222222222222')

        x = requests.get('https://w3schools.com')#, proxies = proxies)

        logging.info(x)

        logging.info("A333333333333333333333333333333333")

        return True

    @client.ledger_ready()

    def ensure_setup(event):

        logging.info(f"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAaa checking here")

        a = check_stuff()  

        logging.info("A44444444444444444444444444444444")

 

    
    

    network.run_forever()

if __name__ == '__main__':

    main()

Unfortunately we do not allow bots to communicate with the outside world for security reasons.

Please see this post for a more detailed explanation:

2 Likes

Following up on what @dtanabe and @Alex_Matson have both said, Bots in Daml Hub do not have access to the external network. This is intentional, and done for security reasons. What you’ll see when you attempt to run your bot is that the requests.get will fail because it cannot reach the outside world.

This leaves two options for meeting your requirement:

  1. Write an externally hosted service that uses an API already offered by Daml Hub to manage the external network calls.
  2. Write an ‘integration’ instead of a bot.

For the first option, Daml Hub already offers the HTTP JSON API for accessing data on a ledger. This lets externally hosted software authenticate using a JWT and issue requests for ledger data and issue commands to the ledger. I’ve linked to the hub documentation above, but the general structure of this approach would be to write a bot that would connect to the ledger using the JSON API and issue whatever requests are necessary to external systems. This would not be subject to the networking limitations above - the code issuing the network requests would not be hosted by Daml Hub.

The second option is to write an integration. Integrations are visible under the ‘browse integrations’ tab in Daml Hub, and can be deployed to a ledger for the purpose of connecting that ledger to external systems. Internally, Integrations are bots, but there’s a specific API they follow to interface with DAML Hub, and they need to be deployed by users with specific access. If this is the path you choose to follow, we can help, but in the meantime, here are a few links to show what an integration looks like in concrete terms.

We have an integration with the Coindesk API that shows how ledgers can issue web requests in response to ledger events and then store the data on ledger. This is a good illustration of the structure and patterns involved in writing a Daml Hub integration.

The code to issue the web request is here:

(You can see how it’s triggered by a ledger event.)

Integrations are also written with a specific framework, that’s a wrapper around Dazl.

The integration framework allows for health and status monitoring and manages the connection of the integration with Daml Hub itself.

There is also a build tool that makes it easy to build integrations and run them locally against a sandbox for testing.

The last two repositories have documentation in their readme that goes into more detail than I can in this post about how these pieces fit together. I’m also happy to field any other questions as well.

3 Likes