Backend API for Princeton University Library's Allsearch application.
Requires:
- Ruby 3.4
- Clone the repository -
git clone [email protected]:pulibrary/allsearch_api.git - Go to the repository directory -
cd allsearch_api - Install the required ruby version -
asdf install - Install the required gems -
bundle install - Make sure you have wget installed -
brew install wget - Start local solr and postgres -
bundle exec rake servers:start - Start the application server on localhost:3000 -
bundle exec rails s - See the application running at http://localhost:3000/
To run all tests:
bundle exec rspecWe have a set of tests that test against the deployed staging environment. In order for these to pass, you must be on the VPN. To run these tests:
bundle exec rspec smoke_specTo calculate coverage, run COVERAGE=true bundle exec rspec
bundle exec rubocopbundle exec reekThis repository uses semgrep to:
- Perform static security analysis
To run semgrep locally:
brew install semgrep
semgrep --config auto . # run rules from the semgrep community
- If the upstream service requires a secret, add it to the vault and environment variables using a princeton_ansible pull request
- Create a new request spec for your service, based on the other service request specs
- Create a new route in
config/routesget '/search/new_service/', to: 'new_service#show', defaults: { format: 'json' } - Create a new controller for your service. You can inherit from
ServiceControllerand/or implement your own#showmethod. - Create a controller spec to confirm that query inputs are sanitized appropriately.
- Create a model to represent a request to the upstream service. Include the
Parsedmodule in your model. - Create a model to represent a document returned by the upstream service. This should inherit from
Documentand implement a#doc_keysmethod.#doc_keysshould return a list of fields (as symbols) that will be presented in allsearch's API response. Each symbol should match the name of a method in this model.
- Create an API spec for your service in spec/requests/api/
- Generate the swagger docs as described below.
- If the service uses solr, add some sample data.
Documentation lives in https://allsearch-api.princeton.edu/api-docs
To update the api documentation for a service:
- create a spec in:
spec/requests/api/ - Generate the docs by running:
bundle exec rake openapi:generate.- This will generate the file
swagger/v1/swagger.yaml. - Please make sure to commit it.
- Visit the documentation:
This repo uses vacuum to validate that the swagger.yaml file meets the OpenAPI standard.
brew install daveshanley/vacuum/vacuum
vacuum lint -d swagger/**/*.yaml
In order to update the banner at /banner, you can either update it on the rails console, or use a rake task.
Valid values for 'alert_status' are info|success|warning|error
There is a rake task that can accept multiple arguments. The arguments are [text, alert_status, dismissible, autoclear]. The arguments are comma delimited, with no spaces. If there is an argument you want to skip, just leave it blank, but leave any commas that might surround it (similar to a csv file). Depending on your shell, you may need to escape the brackets surrounding the arguments.
If there are any commas in your text, you will need to escape them using \
bundle exec rake banner:update\['new banner',info,true,true\]bundle exec rake banner:update\['newer banner',,,false\]LONG_HTML="<h2>All-Search Updated</h2><p> Introducing our new and improved All-Search\, upgraded with advanced technology and designed based on your feedback to enhance your research experience. Share your experience and help us improve it further by completing this <a href='https://example.com'>brief survey</a></p>"
bundle exec rake banner:update\["$LONG_HTML",'info',true,false\]Can be run locally against a remote environment. Must be on VPN.
bundle exec cap staging banner:enable
bundle exec cap staging banner:disableMust be done on the environment where you want to change it
bundle exec flipper enable banner
bundle exec flipper disable banner