Emulator for the Backblaze B2 Cloud Storage service. Goal is to mimic the B2 API to provide a tool that can be used to test applications built to use B2.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci
.vscode
src/B2Emulator
test/B2Emulator.Tests
B2Emulator.sln
README.md

README.md

B2Emulator

Branch CircleCI
Master CircleCI

BuitlWithDot.Net shield

An emulator for the Backblaze B2 Cloud Storage service. The goal of the project is to mimic the B2 API to provide a tool that can be used to test applications built to use B2.

Note: This project is currently in an early state. There is little coverage of the B2 API.

Current partially implemented endpoints

  • b2_upload_file - "fileInfo" ignored, error codes don't match B2 API
  • b2_download_file_by_id - "fileInfo" ignored, error codes don't match B2 API

Running with Docker

The latest version is published at the mwelke/b2-emulator Docker repository.

To run the image locally:

docker run --name b2-emulator \
  -e "ASPNETCORE_ENVIRONMENT=Production" \
  -e "ASPNETCORE_URLS=http://0.0.0.0:5000" \
  -e "PROVIDER=MEMORY" \
  -e "B2_CLOUD_STORAGE_ACCOUNT_ID=..." \
  -e "B2_CLOUD_STORAGE_BUCKET_ID=..." \
  -p 5000:5000 \
  mwelke/b2-emulator:latest

Example docker-compose.yml file:

version: "3.5"

services:

  b2-emulator:
    image: "mwelke/b2-emulator:latest"
    restart: always
    environment:
      ASPNETCORE_ENVIRONMENT: "Production"
      ASPNETCORE_URLS: "http://0.0.0.0:5000"
      PROVIDER: "MEMORY" # Others include ex. "DISK"
      B2_CLOUD_STORAGE_ACCOUNT_ID: "..." # Replace with fake Account ID for tests
      B2_CLOUD_STORAGE_BUCKET_ID: "..." # Replace with fake bucket ID for tests
    ports:
      - "5000:5000"

Choosing a file storage provider

Set the PROVIDER environment variable to choose which provider is loaded at runtime. Options are:

  • MEMORY - An in memory provider. Stores the files in a concurrent dictionary data structure in memory until the process exits. Warning: Files will not be persisted once process exits

Upload Example with Curl and jq

curl \
  -H 'Authorization: 249995b4-502d-4a30-9aaa-e45645623bde' \
  -H 'Content-Type: image/png' \
  -H 'X-Bz-File-Name: image.png' \
  -H 'X-Bz-Content-Sha1: 0A0A9F2A6772942557AB5355D76AF442F8F65E01' \
  -d "$(cat image.png)" \
  http://localhost:5000/b2api/v1/b2_upload_file | jq

Example response:

{
  "fileId": "c01b7aec-a914-4bd0-9205-24526e2d1b5b",
  "fileName": "image.png",
  "accountId": "50bc4680-4c4f-4b2d-9acc-76f4488107f3",
  "bucketId": "b0e88038-fe8a-4c25-900d-db63a9670dc1",
  "contentLength": 94967,
  "contentSha1": "0A0A9F2A6772942557AB5355D76AF442F8F65E01",
  "contentType": "image/png",
  "fileInfo": {},
  "action": "upload",
  "uploadTimestamp": 1535838856198
}

Dev Machine Prerequisites

  • The .NET SDK must be installed.

Build

  1. Run dotnet build from the project/solution directory.

Test

  1. Run dotnet test from the test/B2Emulator.Tests subdirectory.

Run in development

From the src/B2Emulator subdirectory, run dotnet run with the following environment variables set:

  • ASPNETCORE_ENVIRONMENT - Development
  • ASPNETCORE_URLS - http://0.0.0.0:DESIRED_PORT
  • B2_CLOUD_STORAGE_ACCOUNT_ID - ACCOUNT_ID
  • B2_CLOUD_STORAGE_BUCKET_ID - BUCKET_ID

Note that the B2 credentials are used to fake authorization endpoints and bucket behavior. They are not transmitted.

License

FOSSA Status