Giter Site home page Giter Site logo

covidwatch-cloud-functions's Introduction

COVID-Watch Cloud Functions

This repo contains code which is used in the Firebase project to control the Firestore security rules, and define cloud functions.

TODO

  • TypeScript Build System
  • Initial Test Suite
  • Validate Survey Data
  • Initial Survey Endpoint
  • Write to Firestore
  • Add watcher to auto build .ts to .js
  • Agree on API / Response Payloads
  • Verify Cryptographic Hashes
  • Cache Reads in Buckets

Setup

  • VSCode
  • Prettier Code Formatter
  • Node 10+
  • Firestore CLI
  • Postman

Security Model

The idea is to set reads to be open and public as all data is inherently anonymous. Writes are set to disabled except through a cloud endpoint which does the job validating the cryptographic signatures are valid before writing to the firestore.

See the TCN implementation here: https://github.com/TCNCoalition/TCN

NPM Install

$ cd functions
$ npm install

Run Firestore Emulators

Run with debug logging enabled to see console.logs

$ DEBUG_LOGGING=1; firebase emulators:start

Run Tests

$ cd functions
$ npm test

Firebase Functions

TypeScript + Babel

We are using TypeScript and Babel to convert to JS which will run on Node 10 and the Firebase Emulator.

Build

To convert the .ts files in src into .js files in lib run:

$ npm run-script build

The emulator should hot reload the scripts.

Local Endpoints

You can hit the endpoints with curl or Postman.

http://localhost:5001/tagstwo-431e3/us-central1/submitReport

Example Report JSON Payload:

{
  "temporary_contact_key_bytes": "PvLGpfQZgGqnoQRtSr0AHd8J5/WdKwaJNLRCkhGlgHU=",
  "memo_data": "SGVsbG8sIFdvcmxkIQ==",
  "memo_type": 1,
  "start_index": 1,
  "end_index": 8,
  "signature_bytes": "+k7HDsVZPY5Pxcz0cpwVBvDOHrrQ0+AyDVL/MbGkXBYG2WAyoqLaNxFuXiB9rSzkdCesDv1NSSk06hrjx2YABA==",
  "report_verification_public_key_bytes": "v78liBBYQrFXqOH6YydUD1aGpXLMgruKATAjFZ0ycLk="
}

Firestore Emulator REST API

You can query the Firestore API with urls like this: http://localhost:8080/v1/projects/tagstwo-431e3/databases/(default)/documents/signed_reports

$ curl --location --request GET 'http://localhost:8080/v1/projects/tagstwo-431e3/databases/(default)/documents/signed_reports'

Postman Collection

You can import the COVID-Watch.postman_collection.json to play with the local Cloud Functions and Firestore Emulator.

Deployment

Cloud Functions

Deploy a single function:

$ firebase deploy --only functions:submitReport

Live URLS

https://us-central1-tagstwo-431e3.cloudfunctions.net/submitReport

covidwatch-cloud-functions's People

Contributors

madhavajay avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.