Git Product home page Git Product logo

step95-2020's Introduction

ASB API with cloud functions

Introduction

Cloud Functions are about serverless event-driven code. Serverless applications have become increasingly popular in recent years. Serverless computing offers several advantages over traditional server-centric infrastructure: avoids the need for server provisioning, offers easier setup, greater scalability, more flexibility, and quicker time to release. With serverless architectures, developers can focus on writing and testing the application.

To build our RESTful API using serverless technology, we use RTDB (i.e. Firebase realtime database) and Firebase cloud functions, which can be wired to respond directly to HTTP requests.

Table of Contents

Prerequisites

First, create a Firebase project in Firebase console.

We are going to be using node as well as express to host the server-side code and program in server-side Typescript. We also need to write functions locally with the help of firebase CLI. To set up the environment in Linux, follow these steps:

In Linux terminal, install nvm:

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | 

Restart Terminal once before starting using NVM.

Check in the terminal:

$ command -v nvm

Sample output: nvm

Install Node.js and npm:

$ nvm install v12.18.1

Check in the terminal:

$ node --version

Sample output: v12.18.1

$ npm --version

Sample output: 6.14.5

Install Firebase CLI

$ npm install -g firebase-tools

Can check its version

$ firebase --version

Initialize project

In Linux terminal, run:

$ mkdir folderName
$ cd folderName/
$ firebase login 

-> “Y” -> log in and allow access

$ firebase init

Select “Database, Functions, Hosting, Emulators” Select “Use an existing project” -> input projectID

Select Typescript

Type “Y” except “Configure as a single-page app (rewrite all urls to /index.html)?”

Select "Functions, Database, Hosting" for emulators

Should see ✔ Firebase initialization complete!

Then, run:

$ cd folderName/functions
$ npm install --save express body-parser

Directory Structure

There are three important things under the functions directory.

  • index.js is a Javascript file where we define all the functions.
  • Package.json is a Json file used by node, containing modules and their dependencies (e.g. Firebase Admin, Firebase functions) for the usage of the functions.
  • node_modules is a folder where NPM installed those modules during the setup.

Local testing

Run:

$ npm run lint
$ npm run build
$ firebase emulators:start

Check the output for the URL:

http://localhost:5001/projectID/us-central1/ROUTE

Three different ways to check the output:

a. Use curl in the terminal

b. Enter the url in a browser

c. Use Postman

Deploy

Run:

$ firebase deploy

Check the output for the URL:

$ curl https://step95-2020.firebaseapp.com/ROUTE -H "Authorization: bearer $(gcloud auth print-identity-token)"

step95-2020's People

Contributors

helenasg avatar neriyahbutler avatar egrimshaw avatar arjun-garg-google avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar  avatar

Forkers

neriyahbutler

step95-2020's Issues

Missing patch levels for certain CVEs

There are a few CVEs that are missing patch levels and thus are not added into the SPL CVE ID tree.

For example: CVE-2018-3567 has no patch level listed. It is in the 2018-04 ASB.

For now, any ID that is missing a patch level will be added to the -01 patch level.

Handling new versions of the bulletins

This issue happens rarely.

If a user were to accidentally upload a late version of a bulletin (ex: version 2) and then try to upload an older version (ex: version 1), the database would not update.

Because of this, the user will not be able to make a call to U-3 for version 1 and 2 (find changes in vulnerabilities between version x and version y of a certain bulletin) as the database will never have stored version 1.

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.