This application is created for LAA Crime Application Adaptor.
- Contact the team
- Dependencies
- Set up (Docker)
- Generate JWT and Authenticate With Mock Application
- How to use the API
- Accessing the database
- Contributing
Court Data Adaptor is maintained by staff in the Legal Aid Agency. If you need support, you can contact the team on our Slack channel:
- #laa-crime-apps-core on MOJ Digital & Technology
- Ruby version
Install dependencies with bundler:
bundle install
To run the app locally, you will need to download the appropriate environment variables from the team vault in 1Password. These environment variables are stored as a .env file, which docker-compose uses when starting up the service. If you don't see the team vault, speak to your tech lead to get access.
To begin with, make sure that you have the 1Password CLI installed:
op --version
If the command is not found, follow the steps on the 1Password developer docs to get the CLI set-up.
Once you're ready to run the application:
./start-local.sh
The values YAML files are encrypted using git-crypt.
To be able to view and/or edit these files, you will need to decrypt them first.
The database will be set up as part of the build command above. It will be seeded with some sample records to work with. The application will run at http://localhost:3003/.
This mock API utilizes symmetrical HS256 encryption using a shared private secret to authenticate/authorise. To test this app locally we can generate our own JWT using a Java command line app at the root of the project, specifically made for this purpose. This java jar app is called command-line-jwt-generator.jar and to use this:
- run "java -jar command-line-jwt-generator.jar BASE_64_ENCODED_SECRET_FOUND_IN_ENV_DEVELOPMENT ISSUER" from the root directory
- As you can see it takes two parameters: a base64 encoded string that can be found in the relevant .env file BASE64 decoded (you need to encode); Also, an issuer - this is the app that would normally be issuing the JWT. In our case "maat-adapter-dev" or "maat-adapter-test" would normally issue this JWT to communicate to our mock.
- When we call the app endpoint using Postman/CURL we can now use this Bearer token JWT to authenticate/authorize with our app.
- On the non-production environments this shared secret will be generated by the platform and we'd need to use this.
The following endpoints are currently available:
- GET: http://localhost:3003/api/v1/maat/applications/10000133
- POST: http://localhost:3003/api/v1/maat/applications/
- PUT: http://localhost:3003/api/v1/maat/applications/10000133
The usn on the end of the GET and PUT is an example - you will replace this with your own as applicable.
When you ran 'docker-compose build' the database will have been seeded with sample records to use. If you wish to add your own, you can submit a request to either the POST or PUT endpoints listed above. If you submit a request to the PUT and provide a usn that doesn't exist, a new record will be created (otherwise it'll update the existing record).
- In postman (or similar), set up a new PUT request with a URL of the following: http://localhost:3003/api/v1/maat/applications/10000133
- Set the Authorization type to 'Bearer Token', and paste in the token generated from the 'Generate JWT and Authenticate With Mock Application' section above. Don't include the word 'Bearer' from the beginning that the tool generates.
- Copy the contents of the 'sample_request.json' file from the root of this project and paste it into the body of your request. Set the body to 'raw' and the type to 'JSON'
- Submit your request. If successful, it should respond with an ID.
Important: The 'reference' value in your request body should match the urn you provide on the end the URL.
- In postman (or similar), set up a new GET request with a URL of the following: http://localhost:3003/api/v1/maat/applications/10000133
- Set the Authorization type to 'Bearer Token', and paste in the token generated from the 'Generate JWT and Authenticate With Mock Application' section above. Don't include the word 'Bearer' from the beginning that the tool generates.
- Submit your request. If successful, it should respond with the data of the application with the usn you provided.
Important: The GET request will only return applications that have a review_status of 'ready_for_assessment'. The seeded data that is generated when you 'docker-compose build' is already set to this, but any new records you add won't be at this stage. You will need to manually update this field in the database if you wish to GET the record.
This API uses a PostgreSQL database. The database will have been generated for you as part of the docker build. Once you have the application running, you can access your database in multiple ways.
If you are using docker desktop, you can click on your container and select 'Terminal'. You can log into the database by running:
psql -U postgres -h db -d laa-crime-apply-mock-api
From here you can use SQL commands. You may want to update the review status on records so that you can retrieve them via the API. To update all records with this status, run:
UPDATE crime_applications SET review_status = 'ready_for_assessment';
If you are using a tool on your machine to connect to the database, you will need to set the following values:
- URL: jdbc:postgresql://localhost:5432/laa-crime-apply-mock-api
- Host: localhost
- Port: 5432
- Database: laa-crime-apply-mock-api
- Username: postgres
Password should be left blank.
When making changes to the database using the migration files, this provides useful guidance.
- You can generate a new migrate files with this command:
bin/rails generate migration <db_update_descriptive_name>
- You can add your updates to this file. It should be possible to make these changes by comparing with the Crime Apply application.
- Following changes you will want to run
bin/rails db:create
in order to create your database on your machine, this is necessary for the next step. - Next run
bin/rails db:migrate
which will update your schema.rb with your changes. - Now you can set up and run the application locally to test the changes have been made.
Bug reports and pull requests are welcome.
- Clone the project (https://github.com/ministryofjustice/laa-crime-apply-mock-api)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit until you are happy with your contribution (
git commit -am 'Add some feature'
) - Push the branch (
git push origin my-new-feature
) - Make sure your changes are covered by tests, so that we don't break it unintentionally in the future.
- Create a new pull request.