Skip to content

Commit

Permalink
feat: add smoke test key option for NotifyService (#1227)
Browse files Browse the repository at this point in the history
* Updated multipleApiKey schema so that it allows smoke test keys as well now

* Updated NotifyService to look for api keys based on the api environment

* Updated docs for runner

* Updated summaryViewModel to match api key resolution for pay to notify
  • Loading branch information
ziggy-cyb authored Apr 5, 2024
1 parent b5d18e4 commit ebaa76e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
1 change: 1 addition & 0 deletions model/src/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ const feeSchema = joi.object().keys({

const multiApiKeySchema = joi.object({
test: joi.string().optional(),
smoke: joi.string().optional(),
production: joi.string().optional(),
});

Expand Down
47 changes: 24 additions & 23 deletions runner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,33 @@ To symlink an external .env file, for example inside a [Keybase](https://keybase
LINK_TO is optional, it defaults to `./${PROJECT_DIR}`.

### ⚠️ See [config](./config/default.js) for default values for each environment
Please use a config file instead. This will give you more control over each environment.

Please use a config file instead. This will give you more control over each environment.
The defaults can be found in [config](./config/default.js). Place your config files in `runner/config`
See [https://github.com/node-config/node-config#readme](https://github.com/node-config/node-config#readme) for more info.

| name | description | required | default | valid | notes |
|-------------------------|---------------------------------------|:-----------------------:|--------------|:---------------------------:|:-----------------------------------------------------------------------------------------------------------------------------------------:|
| NODE_ENV | Node environment | no | | development,test,production | |
| PORT | Port number | no | 3009 | | |
| OS_KEY | Ordnance Survey | no | | | For address lookup by postcode |
| PAY_API_KEY | Pay api key | yes | | | |
| PAY_RETURN_URL | Pay return url | yes | | | For GOV.UK Pay to redirect back to our service |
| PAY_API_URL | Pay api url | yes | | | |
| NOTIFY_TEMPLATE_ID | Notify api key | yes | | | Template ID required to send form payloads via [GOV.UK Notify](https://www.notifications.service.gov.uk) email service. |
| NOTIFY_API_KEY | Notify api key | yes | | | API KEY required to send form payloads via [GOV.UK Notify](https://www.notifications.service.gov.uk) email service. |
| GTM_ID_1 | Google Tag Manager ID 1 | no | | | |
| GTM_ID_2 | Google Tag Manager ID 2 | no | | | |
| MATOMO_URL | URL of Matomo | no | | | |
| MATOMO_ID | ID of Matomo site | no | | | |
| SSL_KEY | SSL Key | no | | | |
| SSL_CERT | SSL Certificate | no | | | |
| PREVIEW_MODE | Preview mode | no | false | | This should only be used in a dev or testing environment. Setting true will allow POST requests from the designer to add or mutate forms. |
| LOG_LEVEL | Log level | no | debug | trace,debug,info,error | |
| PRIVACY_POLICY_URL | The url used in footer's privacy link | no | help/privacy | | |
| API_ENV | Switch for API keys | no | | test,production | If the JSON file supplies test and live API keys, this is used to switch between which key which needs to be used |
| PHASE_TAG | Tag to use for phase banner | no | beta | alpha, beta, empty string | |
| AUTH_ENABLED | Enable auth for all form pages | no | false | | |
| name | description | required | default | valid | notes |
| ----------------------- | ------------------------------------- | :---------------------: | ------------ | :-------------------------: | :---------------------------------------------------------------------------------------------------------------------------------------: |
| NODE_ENV | Node environment | no | | development,test,production | |
| PORT | Port number | no | 3009 | | |
| OS_KEY | Ordnance Survey | no | | | For address lookup by postcode |
| PAY_API_KEY | Pay api key | yes | | | |
| PAY_RETURN_URL | Pay return url | yes | | | For GOV.UK Pay to redirect back to our service |
| PAY_API_URL | Pay api url | yes | | | |
| NOTIFY_TEMPLATE_ID | Notify api key | yes | | | Template ID required to send form payloads via [GOV.UK Notify](https://www.notifications.service.gov.uk) email service. |
| NOTIFY_API_KEY | Notify api key | yes | | | API KEY required to send form payloads via [GOV.UK Notify](https://www.notifications.service.gov.uk) email service. |
| GTM_ID_1 | Google Tag Manager ID 1 | no | | | |
| GTM_ID_2 | Google Tag Manager ID 2 | no | | | |
| MATOMO_URL | URL of Matomo | no | | | |
| MATOMO_ID | ID of Matomo site | no | | | |
| SSL_KEY | SSL Key | no | | | |
| SSL_CERT | SSL Certificate | no | | | |
| PREVIEW_MODE | Preview mode | no | false | | This should only be used in a dev or testing environment. Setting true will allow POST requests from the designer to add or mutate forms. |
| LOG_LEVEL | Log level | no | debug | trace,debug,info,error | |
| PRIVACY_POLICY_URL | The url used in footer's privacy link | no | help/privacy | | |
| API_ENV | Switch for API keys | no | | test,production,smoke | If the JSON file supplies test and live API keys, this is used to switch between which key which needs to be used |
| PHASE_TAG | Tag to use for phase banner | no | beta | alpha, beta, empty string | |
| AUTH_ENABLED | Enable auth for all form pages | no | false | | |
| AUTH_CLIENT_ID | oAuth client ID | If AUTH_ENABLED is true | | | |
| AUTH_CLIENT_SECRET | oAuth client secret | If AUTH_ENABLED is true | | | |
| AUTH_CLIENT_AUTH_URL | oAuth client authorise endpoint | If AUTH_ENABLED is true | | | |
Expand Down
8 changes: 5 additions & 3 deletions runner/src/server/plugins/engine/models/SummaryViewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,11 @@ export class SummaryViewModel {

get payApiKey() {
if (isMultipleApiKey(this._payApiKey)) {
return config.apiEnv === "production"
? this._payApiKey.production ?? this._payApiKey.test
: this._payApiKey.test ?? this._payApiKey.production;
return (
this._payApiKey[config.apiEnv] ??
this._payApiKey.test ??
this._payApiKey.production
);
}
return this._payApiKey;
}
Expand Down
6 changes: 3 additions & 3 deletions runner/src/server/services/notifyService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ export class NotifyService {
let { apiKey } = args;

if (isMultipleApiKey(apiKey)) {
apiKey = (config.apiEnv === "production"
? apiKey.production ?? apiKey.test
: apiKey.test ?? apiKey.production) as string;
apiKey = (apiKey[config.apiEnv] ??
apiKey.test ??
apiKey.production) as string;
}

const parsedOptions: SendEmailOptions = {
Expand Down

0 comments on commit ebaa76e

Please sign in to comment.