Skip to content
CCPEDIAby Unity Nodes
App Development

How can I access environment variables in a Canton bootstrap script?

3 posts289 views3 likesLast activity Jun 2024

  1. georgOP

    I’m using a Canton bootstrap script to allocate parties/users and upload DARs at startup. I’d like to make this configurable in a Docker Compose setting. Is there a way I can access environment variables from within the script, or maybe there’s a different / better way how to parametrize the boostrap script?

  2. nycnewman 1

    Use something like the following:

    val fullyQualfiedDomainId = sys.env.getOrElse(“ENV_VAR_NAME”, throw new IllegalStateException(“missing required environment variable ENV_VAR_NAME”))

  3. WallaceKelly 2

    Here are some more examples, for my future self:

    // provide default
    val location = sys.env.getOrElse("DEMO_ROOT", "examples/demo")
    
    // throw if missing
    val host = sys.env.getOrElse("HOST_NAME",
       sys.error("missing required environment variable HOST_NAME"))
    
    // with pattern matching
    val namespace = sys.env.get("PARENT_TYPE") match {
      case None =>
        throw new IllegalArgumentException("missing PARENT_TYPE env var")
      case Some("Service") =>
        "service"
      case _ =>
        "ledger"
    }