Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.
/ barcode-service Public archive

The service is for getting a patron's barcode PNG file. The service is not production ready yet at this moment. Please visit https://qa-platformdocs.nypl.org/#/patrons/getBarcode for testing it.

Notifications You must be signed in to change notification settings

NYPL/barcode-service

Repository files navigation

Deprecated

As of August 2024, this codebase and the relevant AWS Lambda has been decommissioned and will not be supported. The Platform API endpoint this app served was /api/v0.1/patron/{id}/barcode and will be removed. Please contact the NYPL LSP or Remediation teams with any questions.

Getting Patron Barcodes

Searching within the nypl and nypl-discovery Github orgs, here is one example of getting a patron's barcodes through a different approach:

  • nypl-hold-request-consumer - This app is hitting the /patrons/{id} endpoint and getting the patron's barcode from the response's barCodes array.

NYPL Barcode Service

This app service the following routes:

  • GET /api/v0.1/patrons/{id}/barcode
  • GET /docs/barcode

Build Status Coverage Status

This package is intended to be used as a Lambda-based Node.js/PHP Barcode Service using the NYPL PHP Microservice Starter.

This package adheres to PSR-1, PSR-2, and PSR-4 (using the Composer autoloader).

Requirements

Homebrew is highly recommended for PHP:

  • brew install php71
  • brew install php71-pdo-pgsql

Installation

  1. Clone the repo.
  2. Install required dependencies.
    • Run npm install to install Node.js packages.
    • Run composer install to install PHP packages.
    • If you have not already installed node-lambda as a global package, run npm install -g node-lambda.
  3. Setup configuration files.
    • Copy the .env.sample file to .env.
    • Copy config/var_env.sample to config/var_dev.env.
  4. Replace sample values in .env and config/var_dev.env.

Configuration

Various files are used to configure and deploy the Lambda.

.env

.env is used locally for two purposes:

  1. By node-lambda for deploying to and configuring Lambda in all environments.
    • You should use this file to configure the common settings for the Lambda (e.g. timeout, Node version).
  2. To set local environment variables so the Lambda can be run and tested in a local environment. These parameters are ultimately set by the var environment files when the Lambda is deployed.

package.json

Configures npm run commands for each environment for deployment and testing. Deployment commands may also set the proper AWS Lambda VPC, security group, and role.

"scripts": {
    "deploy-dev": "node-lambda deploy -e qa -f config/var_qa.env -S config/event_sources_qa.json -o arn:aws:iam::224280085904:role/lambda_basic_execution -b subnet-f4fe56af -g sg-1d544067 -p nypl-sandbox",
    "deploy-qa": "node-lambda deploy -e qa -f config/var_qa.env -S config/event_sources_qa.json -o arn:aws:iam::224280085904:role/lambda_basic_execution -b subnet-f4fe56af -g sg-1d544067 -p nypl-sandbox",
    "deploy-production": "node-lambda deploy -e production -f config/var_production.env -S config/event_sources_production.json -b subnet-f4fe56af -g sg-1d544067"
},

config/var_app

Configures environment variables common to all environments.

config/var_environment.env

Configures environment variables specific to each environment.

config/event_sources_environment

Configures Lambda event sources (triggers) specific to each environment.

Usage

Process a Lambda Event

To use node-lambda to process the sample API Gateway event in event.json, run:

npm run test-recap-bib

Run as a Web Server

To use the PHP internal web server, run:

php -S localhost:8888 -t . index.php

You can then make a request to the Lambda: http://localhost:8888/api/v0.1/bibs.

Swagger Documentation Generator

Create a Swagger route to generate Swagger specification documentation:

$service->get("/swagger", function (Request $request, Response $response) {
    return SwaggerGenerator::generate(__DIR__ . "/src", $response);
});

Deployment

Before deploying, ensure configuration files have been properly set up:

  1. Copy config/var_env.sample to config/dev.env, config/var_qa.env, and config/var_production.env.
    • Verify environment variables are correct.
  2. Verify .env has correct settings for deployment.
  3. Verify package.json has correct command-line options for security group, VPC, and role (if applicable).
  4. Verify config/event_sources_dev.json, config/event_sources_qa.json, config/event_sources_production.json have proper event sources.

To deploy to an environment, run the corresponding command. For example:

npm run deploy-dev

About

The service is for getting a patron's barcode PNG file. The service is not production ready yet at this moment. Please visit https://qa-platformdocs.nypl.org/#/patrons/getBarcode for testing it.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •