This is a sample and generic service to collect audit log information for safekeeping.
This is a stand alone service intended to save audit log information generated by other services that are of interest to save. As an example who updated what product information.
To call this service a unique API key is required. For this initial simple version, there is only one API key that is read from an environment variable called 'AUDIT_API_KEY'.
This service uses MongoDB and you need either an on-premise or cloud based Atlas MongoDB access.
To start mongodb/brew/mongodb-community now and restart at login: brew services start mongodb/brew/mongodb-community
Or, if you don't want/need a background service you can just run: mongod --config /usr/local/etc/mongod.conf
All audit service configuration originates from environment variables.
- export NODE_ENV=development - Specified for what environment this configuration was created for.
- export SERVICE_NAME='audit-api' - Name of the service
- USE_HTTPS=false - Boolean value that indicates whether to listen on HTTP or HTTPS
- export AUDIT_PORT=3001 - Port number that the service should listen on.
- export MONGODB_URL='mongodb://localhost:27017/audit' - MongoDB connection string
- export AUDIT_API_KEY=1234abcd - API key that should be used to accept calls
- export LOG_LEVEL=debug - Minimum log level that should be logged
- export CONSOLELOG_ENABLED=true - Whether all received and generated log should be output to the console
- export FILELOG_ENABLED=true - Whether all received and generated log should be saved in a circular log file
- export MONGOLOG_ENABLED=true - Whether all received and generated log should be saved in the MongoDB database
Follow these steps to build and launch the service:
- Fork the repo
- Launch terminal and navigate to the root folder where the project was copied to.
- Update project dependencies: sudo npm update
- Audit for vulnerabilities and fix: npm audit
- Set environment variables: source ./setenv.sh
- If configured to run local MongoDB, then start the DB.
- Rebuild project: npm run build
- Start the service: npm run start
- Configure JEST: https://itnext.io/testing-with-jest-in-typescript-cc1cd0095421
- MongoDB Installation: https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/