Skip to content

Task to process test resultst DynamoDB Stream events and push them onto a queue for onward processing

License

Notifications You must be signed in to change notification settings

dvsa/cvs-tsk-cert-gen-init

Repository files navigation

cvs-tsk-cert-gen-init

Introduction

The cert gen service is a lambda which is used to marshall data before cert gen service task generates the test certificates when tests are submitted.

Dependencies

The project runs on node >10 with typescript and serverless framework. For further details about project dependencies, please refer to the package.json file. nvm is used to managed node versions and configuration explicitly done per project using an .npmrc file.

Prerequisites

Please install and run the following securiy programs as part of your development process:

  • git-secrets After installing, do a one-time set up with git secrets --register-aws. Run with git secrets --scan.

These will be run as part of your projects hooks so you don't accidentally introduce any new security vulnerabilities.

You will also require Docker to run the service locally if you wish to mock external dependencies.

Architecture

End to end design

All in one view

cert gen microservice

More information about technical designs can be found under the cert gen section.

Getting started

Set up your nodejs environment running nvm use and once the dependencies are installed using npm i, you can run the scripts from package.json to build your project. This code repository uses serverless framework to mock AWS capabilities for local development.

Environmental variables

  • The BRANCH environment variable indicates in which environment is this application running. Not setting this variable will result in defaulting to local.

Scripts

  • Building without source maps - npm run build
  • Building with source maps - npm run build:dev
  • Building the docker containers - npm run build:docker

Running

The app can be started by running npm run start:docker.

Configuration

The configuration file can be found under src/config/config.yml. Environment variable injection is possible with the syntax: ${BRANCH}, or you can specify a default value: ${BRANCH:local}.

SQS

SQS contains configuration for the local environment or the AWS environment. Locally, you need to provide the localhost region and the SQS endpoint, which in this case is the address of a docker image. apiVersion and queueName need to be provided for both environments.

sqs:
  local:
    params:
      region: localhost
      endpoint: http://sqs:9324
      apiVersion: "2012-11-05"
    queueName: cert-gen-q
  remote:
    params:
      apiVersion: "2012-11-05"
    queueName: cert-gen-q

Debugging

The following environmental variables can be given to your serverless scripts to trace and debug your service:

AWS_XRAY_CONTEXT_MISSING = LOG_ERROR
SLS_DEBUG = *
BRANCH = local

Testing

Unit testing

In order to test, you need to run the following:

npm run test # unit tests

End to end

Infrastructure

We follow a gitflow approach for development. For the CI/CD and automation please refer to the following pages for further details:

Contributing

Please familiarise yourself with commitlint and conventional commits conventions as a hook is in place to enforce standards.

Hooks and code standards

The projects has multiple hooks configured using husky which will execute the following scripts: security-checks, audit, tslint, prepush. The codebase uses typescript clean code standards as well as sonarqube for static analysis.

SonarQube is available locally, please follow the instructions below if you wish to run the service locally (brew is the preferred approach).

Static code analysis

Brew (recommended):

  • Install sonarqube using brew
  • Change sonar.host.url to point to localhost, by default, sonar runs on http://localhost:9000
  • run the sonar server sonar start, then perform your analysis npm run sonar-scanner

Manual:

  • Download sonarqube
  • Add sonar-scanner in environment variables in your profile file add the line: export PATH=<PATH_TO_SONAR_SCANNER>/sonar-scanner-3.3.0.1492-macosx/bin:$PATH
  • Start the SonarQube server: cd <PATH_TO_SONARQUBE_SERVER>/bin/macosx-universal-64 ./sonar.sh start
  • In the microservice folder run the command: npm run sonar-scanner