Categorygithub.com/ONSdigital/dp-legacy-cache-api
modulepackage
1.1.0
Repository: https://github.com/onsdigital/dp-legacy-cache-api.git
Documentation: pkg.go.dev

# README

dp-legacy-cache-api

REST API for managing cache control information for pages within the legacy CMS. dp-legacy-cache-api is called by:

  • dp-legacy-cache-proxy to read the release time for a particular item of content (Web subnet/ read-only mode)
  • Zebedee to set the right cache time for content based on publish notifications (Publishing subnet)

The API talks to DocumentDB in the environment (or MongoDB locally) in the cachetimes collection.

Database FieldsDescription
IDMD5 hash representing the unique identifier of the page's path.
PathURI indicating the location of the published page
Next Release TimeScheduled time for the next update in ISO-8601 format
Collection IDUtilised for organising and filtering cache time entries

Getting started

  • Ensure Docker is installed on your local machine. Installation steps can be found here.
  • Run docker run --name mongo-test -p 27017:27017 -e MONGO_INITDB_DATABASE=cache -v $(pwd)/mongo-init:/docker-entrypoint-initdb.d -d mongo.
    • This command launches a MongoDB container named mongo-test, maps port 27017 from the host to the container, sets cache as the default database, runs initialization scripts (located in the mongo-init directory), and operates in the background.
  • Run make debug to run the application on http://localhost:29100.
  • By default, the write (PUT) endpoint is disabled. To be able to create or update resources, please follow these steps:
    • Run Zebedee.
    • Run IS_PUBLISHING=true make debug. This will make the PUT endpoint available.
    • Send a valid request to the PUT endpoint. You'll need to set the Bearer token (the Authorization header's value should be Bearer your-token-here).
      • For local usage, you can use the Service Auth Token specified in the DP's install guide.
      • For Sandbox/Production usage (or to generate a different token), please follow this guide.
  • Run make help to see a full list of make targets.

Dependencies

  • No further dependencies other than those defined in go.mod

Configuration

Environment variableDefaultDescription
BIND_ADDR:29100The host and port to bind to
MONGODB_BIND_ADDRlocalhost:27017The MongoDB bind address
MONGODB_USERNAMEThe MongoDB Username
MONGODB_PASSWORDThe MongoDB Password
MONGODB_DATABASEcacheThe MongoDB database
MONGODB_COLLECTIONSCacheTimesCollection:cachetimesThe MongoDB collections
MONGODB_REPLICA_SETThe name of the MongoDB replica set
MONGODB_ENABLE_READ_CONCERNfalseSwitch to use (or not) majority read concern
MONGODB_ENABLE_WRITE_CONCERNtrueSwitch to use (or not) majority write concern
MONGODB_CONNECT_TIMEOUT5sThe timeout when connecting to MongoDB (time.Duration format)
MONGODB_QUERY_TIMEOUT15sThe timeout for querying MongoDB (time.Duration format)
MONGODB_IS_SSLfalseSwitch to use (or not) TLS when connecting to mongodb
GRACEFUL_SHUTDOWN_TIMEOUT5sThe graceful shutdown timeout in seconds (time.Duration format)
HEALTHCHECK_INTERVAL30sTime between self-healthchecks (time.Duration format)
HEALTHCHECK_CRITICAL_TIMEOUT90sTime to wait until an unhealthy dependent propagates its state to make this app unhealthy (time.Duration format)
IS_PUBLISHINGfalseDetermines if the instance is in publishing or not
ZEBEDEE_URLhttp://localhost:8082Zebedee host address and port for authentication

Auto-Deployment of secrets

Functionality has been added to the nomad plan so that when the secrets are deployed to Vault, this will automatically cause Nomad to trigger a redeployment of the application to pick up the new secrets. Please note that this functionality does not appear to work with the current nomad/vault versions, but if these are upgraded it may then become functional.

License

Copyright © 2024, Office for National Statistics (https://www.ons.gov.uk)

Released under MIT license, see LICENSE for details.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

BuildTime represents the time in which the service was built.
GitCommit represents the commit (SHA-1) hash of the service that is running.
Version represents the version of the service that is running.