WebDAV

RiskScape Platform storage is also reachable over WebDAV, an HTTP-based protocol for reading and writing remote files.

Note

This page is aimed at advanced users. If you just want to use WebDAV to manually transfer a few files between your computer and the Platform, see the WebDAV section of the Navigating project files tutorial, which walks through setting up your operating system’s file explorer as a WebDAV client.

RiskScape Platform’s WebDAV API is is browsable and available at https://riskscape.nz/dav - from there you can select:

Clicking on a folder will show you the files and folders in that directory. Clicking on a file will download the file in your browser.

Authenticating

To access WebDAV from a script, you’ll need to use a WebDAV access token to authenticate. Refer to Authentication for how to create a WebDAV access token

The following examples assume that you have setup an environment variable called RISKSCAPE_TOKEN that contains your WebDAV token. You can test whether your secret is setup correctly using the curl command:

curl -u TOKEN:$RISKSCAPE_TOKEN https://riskscape.nz/dav

Accessing WebDAV from Python

If you are writing a script, the webdavclient3 Python package is a straightforward way to talk to WebDAV. To install webdavclient3, use:

pip install webdavclient3

Then a simple Python script to connect via the WebDAV API and download a file might look like this:

import os

from webdav3.client import Client

options = {
    "webdav_hostname": "https://riskscape.nz/dav/projects",
    "webdav_login": "TOKEN",
    "webdav_password": os.environ["RISKSCAPE_TOKEN"],
}
client = Client(options)

# list what is available at the top level
print(client.list())

# download a file from a project
client.download_sync(
    remote_path="riskscape/example/getting-started/README.md",
    local_path="README.md",
)

Note

webdavclient3 authenticates with HTTP Basic authentication by default, so the same TOKEN username and access token password apply here too.

Accessing WebDAV with Rclone

Rclone is a command-line tool for copying and syncing files, with built-in support for WebDAV.

Create a remote for RiskScape Platform:

rclone config create riskscape webdav \
  url=https://riskscape.nz/dav/projects \
  vendor=other \
  user=TOKEN \
  pass=$RISKSCAPE_TOKEN \
  --obscure

Note

The --obscure flag tells Rclone to obscure the plain-text password before storing it in its configuration file. Without it, Rclone expects the password to already be obscured.

Once the remote is set up, you can list and copy files:

rclone lsf riskscape:riskscape/example/getting-started

rclone copy riskscape:riskscape/example/getting-started/README.md .

Tip

Setting up Rclone like this is a handy way to keep a local CLI project in sync with the RiskScape Platform. Rclone has a --dry-run option to show you what would be copied, and options to exclude copying unnecessary files, e.g --exclude ".jython_cache/**" --exclude "**/__pycache__/**" --exclude "output/**".

Further reading

  • Authentication covers access tokens in more detail.

  • WebDAV walks through connecting a file explorer to WebDAV, with screenshots.