Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Drop BOPS_SUBMISSION_URL_* env vars in favour of DB values #2581

Merged
merged 4 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ PRODUCTION_PG_URL_FOR_USER_GITHUB_ACTIONS=πŸ‘»
SHAREDB_PORT=7003

# Integrations (local and pull request environments point to third party staging environments)
BOPS_API_ROOT_DOMAIN=πŸ‘»
BOPS_API_TOKEN=πŸ‘»

GOVUK_NOTIFY_API_KEY=πŸ‘»
Expand All @@ -89,26 +88,16 @@ SUPPRESS_LOGS=true
## Lambeth
GOV_UK_PAY_TOKEN_LAMBETH=πŸ‘»
UNIFORM_CLIENT_LAMBETH=πŸ‘»
BOPS_SUBMISSION_URL_LAMBETH=https://lambeth.${BOPS_API_ROOT_DOMAIN}

## Southwark
GOV_UK_PAY_TOKEN_SOUTHWARK=πŸ‘»
UNIFORM_CLIENT_SOUTHWARK=πŸ‘»
BOPS_SUBMISSION_URL_SOUTHWARK=https://southwark.${BOPS_API_ROOT_DOMAIN}

## Buckinghamshire
GOV_UK_PAY_TOKEN_BUCKINGHAMSHIRE=πŸ‘»
UNIFORM_CLIENT_AYLESBURY_VALE=πŸ‘»
UNIFORM_CLIENT_CHILTERN=πŸ‘»
UNIFORM_CLIENT_WYCOMBE=πŸ‘»
BOPS_SUBMISSION_URL_BUCKINGHAMSHIRE=https://buckinghamshire.${BOPS_API_ROOT_DOMAIN}

## Camden
BOPS_SUBMISSION_URL_CAMDEN=https://camden.${BOPS_API_ROOT_DOMAIN}

## Gloucester
BOPS_SUBMISSION_URL_GLOUCESTER=https://gloucester.${BOPS_API_ROOT_DOMAIN}

## End-to-end test team (borrows Lambeth's details)
GOV_UK_PAY_TOKEN_E2E=πŸ‘»
BOPS_SUBMISSION_URL_E2E=https://lambeth.${BOPS_API_ROOT_DOMAIN}
12 changes: 1 addition & 11 deletions api.planx.uk/.env.test.example
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ HASURA_GRAPHQL_URL=http://hasura:8080/v1/graphql
HASURA_PLANX_API_KEY=πŸ‘»

# Integrations
BOPS_API_ROOT_DOMAIN=πŸ‘»
BOPS_API_TOKEN=πŸ‘»

GOV_UK_PAY_TOKEN_BUCKINGHAMSHIRE=πŸ‘»
Expand All @@ -42,18 +41,9 @@ SLACK_WEBHOOK_URL=πŸ‘»
# Local authority specific integrations
## Lambeth
GOV_UK_PAY_TOKEN_LAMBETH=πŸ‘»
BOPS_SUBMISSION_URL_LAMBETH=https://lambeth.${BOPS_API_ROOT_DOMAIN}

## Southwark
GOV_UK_PAY_TOKEN_SOUTHWARK=πŸ‘»
BOPS_SUBMISSION_URL_SOUTHWARK=https://southwark.${BOPS_API_ROOT_DOMAIN}

## Buckinghamshire
GOV_UK_PAY_TOKEN_BUCKINGHAMSHIRE=πŸ‘»
BOPS_SUBMISSION_URL_BUCKINGHAMSHIRE=https://buckinghamshire.${BOPS_API_ROOT_DOMAIN}

## Camden
BOPS_SUBMISSION_URL_CAMDEN=https://camden.${BOPS_API_ROOT_DOMAIN}

## Gloucester
BOPS_SUBMISSION_URL_GLOUCESTER=https://gloucester.${BOPS_API_ROOT_DOMAIN}
GOV_UK_PAY_TOKEN_BUCKINGHAMSHIRE=πŸ‘»
70 changes: 68 additions & 2 deletions api.planx.uk/modules/send/bops/bops.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ jest.mock("@opensystemslab/planx-core", () => {
};
});

const submissionURL = process.env.BOPS_SUBMISSION_URL_SOUTHWARK;

describe(`sending an application to BOPS`, () => {
const submissionURL = "https://test.bops-test.com";

beforeEach(() => {
queryMock.mockQuery({
name: "FindApplication",
Expand All @@ -54,6 +54,38 @@ describe(`sending an application to BOPS`, () => {
insertBopsApplication: { id: 22 },
},
});

queryMock.mockQuery({
name: "GetStagingBopsSubmissionURL",
data: {
teams: [
{
integrations: {
bopsSubmissionURL: submissionURL,
},
},
],
},
variables: {
slug: "southwark",
},
});

queryMock.mockQuery({
name: "GetStagingBopsSubmissionURL",
data: {
teams: [
{
integrations: {
bopsSubmissionURL: null,
},
},
],
},
variables: {
slug: "unsupported-team",
},
});
});

it("proxies request and returns hasura id", async () => {
Expand Down Expand Up @@ -132,6 +164,8 @@ describe(`sending an application to BOPS`, () => {
});

describe(`sending an application to BOPS v2`, () => {
const submissionURL = "https://test.bops-test.com";

beforeEach(() => {
queryMock.mockQuery({
name: "FindApplication",
Expand All @@ -151,6 +185,38 @@ describe(`sending an application to BOPS v2`, () => {
insertBopsApplication: { id: 22 },
},
});

queryMock.mockQuery({
name: "GetStagingBopsSubmissionURL",
data: {
teams: [
{
integrations: {
bopsSubmissionURL: submissionURL,
},
},
],
},
variables: {
slug: "southwark",
},
});

queryMock.mockQuery({
name: "GetStagingBopsSubmissionURL",
data: {
teams: [
{
integrations: {
bopsSubmissionURL: null,
},
},
],
},
variables: {
slug: "unsupported-team",
},
});
});

it("successfully proxies request and returns hasura id", async () => {
Expand Down
23 changes: 19 additions & 4 deletions api.planx.uk/modules/send/bops/bops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ const sendToBOPS = async (req: Request, res: Response, next: NextFunction) => {
// a local or staging API instance should send to the BOPS staging endpoint
// production should send to the BOPS production endpoint
const localAuthority = req.params.localAuthority;
const bopsSubmissionURLEnvName = `BOPS_SUBMISSION_URL_${localAuthority.toUpperCase()}`;
const bopsSubmissionURL = process.env[bopsSubmissionURLEnvName];
const env = process.env.NODE_ENV === "production" ? "production" : "staging";
const bopsSubmissionURL = await $api.team.getBopsSubmissionURL(
localAuthority,
env,
);
const isSupported = Boolean(bopsSubmissionURL);
if (!isSupported) {
return next(
Expand Down Expand Up @@ -175,9 +178,21 @@ const sendToBOPSV2 = async (
// a local or staging API instance should send to the BOPS staging endpoint
// production should send to the BOPS production endpoint
const localAuthority = req.params.localAuthority;
const bopsSubmissionURLEnvName = `BOPS_SUBMISSION_URL_${localAuthority.toUpperCase()}`;
const bopsSubmissionURL = process.env[bopsSubmissionURLEnvName];
const env = process.env.NODE_ENV === "production" ? "production" : "staging";
const bopsSubmissionURL = await $api.team.getBopsSubmissionURL(
localAuthority,
env,
);
const isSupported = Boolean(bopsSubmissionURL);
if (!isSupported) {
return next(
new ServerError({
status: 400,
message: `Back-office Planning System (BOPS) is not enabled for this local authority (${localAuthority})`,
}),
);
}

if (!isSupported) {
return next(
new ServerError({
Expand Down
5 changes: 0 additions & 5 deletions api.planx.uk/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ app.use(helmet());
assert(process.env.GOVUK_NOTIFY_API_KEY);
assert(process.env.HASURA_PLANX_API_KEY);
assert(process.env.BOPS_API_TOKEN);
assert(process.env.BOPS_SUBMISSION_URL_LAMBETH);
assert(process.env.BOPS_SUBMISSION_URL_BUCKINGHAMSHIRE);
assert(process.env.BOPS_SUBMISSION_URL_SOUTHWARK);
assert(process.env.BOPS_SUBMISSION_URL_CAMDEN);
assert(process.env.BOPS_SUBMISSION_URL_GLOUCESTER);
assert(process.env.UNIFORM_TOKEN_URL);
assert(process.env.UNIFORM_SUBMISSION_URL);

Expand Down
3 changes: 1 addition & 2 deletions docker-compose.e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,4 @@ services:
UNIFORM_SUBMISSION_URL: http://mock-server:8080
UNIFORM_TOKEN_URL: http://mock-server:8080
UNIFORM_CLIENT_E2E: e2e:123
GOV_UK_PAY_TOKEN_E2E: ${GOV_UK_PAY_TOKEN_E2E}
BOPS_SUBMISSION_URL_E2E: http://mock-server:8080
GOV_UK_PAY_TOKEN_E2E: ${GOV_UK_PAY_TOKEN_E2E}
7 changes: 0 additions & 7 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,14 @@ services:
# Lambeth
GOV_UK_PAY_TOKEN_LAMBETH: ${GOV_UK_PAY_TOKEN_LAMBETH}
UNIFORM_CLIENT_LAMBETH: ${UNIFORM_CLIENT_LAMBETH}
BOPS_SUBMISSION_URL_LAMBETH: ${BOPS_SUBMISSION_URL_LAMBETH}
# Southwark
GOV_UK_PAY_TOKEN_SOUTHWARK: ${GOV_UK_PAY_TOKEN_SOUTHWARK}
UNIFORM_CLIENT_SOUTHWARK: ${UNIFORM_CLIENT_SOUTHWARK}
BOPS_SUBMISSION_URL_SOUTHWARK: ${BOPS_SUBMISSION_URL_SOUTHWARK}
# Buckinghamshire
GOV_UK_PAY_TOKEN_BUCKINGHAMSHIRE: ${GOV_UK_PAY_TOKEN_BUCKINGHAMSHIRE}
UNIFORM_CLIENT_AYLESBURY_VALE: ${UNIFORM_CLIENT_AYLESBURY_VALE}
UNIFORM_CLIENT_CHILTERN: ${UNIFORM_CLIENT_CHILTERN}
UNIFORM_CLIENT_WYCOMBE: ${UNIFORM_CLIENT_WYCOMBE}
BOPS_SUBMISSION_URL_BUCKINGHAMSHIRE: ${BOPS_SUBMISSION_URL_BUCKINGHAMSHIRE}
# Camden
BOPS_SUBMISSION_URL_CAMDEN: ${BOPS_SUBMISSION_URL_CAMDEN}
# Gloucester
BOPS_SUBMISSION_URL_GLOUCESTER: ${BOPS_SUBMISSION_URL_GLOUCESTER}

sharedb:
restart: unless-stopped
Expand Down
34 changes: 30 additions & 4 deletions e2e/tests/api-driven/src/invite-to-pay/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { $admin } from "../client";
import { TEST_EMAIL } from "../../../ui-driven/src/globalHelpers";
import { createTeam, createUser } from "../globalHelpers";
import gql from "graphql-tag";

export async function setUpMocks() {
const serverMockFile = readFileSync(`${__dirname}/mocks/server-mocks.yaml`);
Expand Down Expand Up @@ -159,12 +160,37 @@ export async function cleanup({
}
}

const setupMockBopsSubmissionUrl = async (teamId: number) => {
await $admin.client.request(
gql`
mutation SetupTeamIntegrationE2E(
$staging_bops_submission_url: String
$team_id: Int
) {
insert_team_integrations_one(
object: {
teamId: $team_id
stagingBopsSubmissionUrl: $staging_bops_submission_url
}
) {
id
}
}
`,
{
teamId,
stagingBopsSubmissionUrl: "http://mock-server:8080",
},
);
};

export const setup = async () => {
await setUpMocks();
const world = {
teamId: await createTeam(),
userId: await createUser(),
};
const teamId = await createTeam();
const userId = await createUser();
await setupMockBopsSubmissionUrl(teamId);

const world = { teamId, userId };

return world;
};
1 change: 0 additions & 1 deletion infrastructure/application/Pulumi.production.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ config:
secure: AAABAE+ZtQZO26XlmfAS7tG1DkwQ+G5OP82Roe4EOuk/tG1bMsI=
application:airbrake-project-key:
secure: AAABAPIGB+gWevPn0SzWnuSuV1RmdwpLOlWKnu8cM/kxLfslvdCIRcU0n0M0XNJ3jwj4EdFn7/llsL1Kg2XnDA==
application:bops-api-root-domain: bops.services
application:bops-api-token:
secure: AAABALRtSjQMRjERtkHs6WBOI7MBMw4bFOuHO8qLLPe9Pfg8Nlbp61XalZA1pmXsRt/T+59fGcdqbKA5WRkOZVibhFo=
application:cloudflare-zone-id: a9b9933f28e786ec4cfd4bb596f5a519
Expand Down
1 change: 0 additions & 1 deletion infrastructure/application/Pulumi.sandbox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ config:
application:airbrake-project-id: "329753"
application:airbrake-project-key:
secure: AAABAO8NgmVNdkwajWpiKwi+dxGicFACbAQzK66FREUCp+OUbSRyNAb9dSQHq/n9fZb8xWBdvYBCQ9eBr2jqPQ==
application:bops-api-root-domain: bops-staging.services
application:bops-api-token:
secure: AAABAHLQf7CFOK073geL2TbTYycQCzPYUy3Xi66UniwIrTlOAqve2YBikJXzMJ2xS9v4dGUZMUmwUba0OpTz8KAMXJ8=
application:cloudflare-zone-id: 9cdfc35484748e96b0ed2b1d303a694f
Expand Down
1 change: 0 additions & 1 deletion infrastructure/application/Pulumi.staging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ config:
secure: AAABABxcp8r3CZAw1kXuXkwPZ8cKRDQyOg4+gVvqzKuCFWb8BEU=
application:airbrake-project-key:
secure: AAABABujxMHxU8Abj4QpyQTz7bLt3AP2wBFaypVkDZ2khzc6eh6lHLljTEkzpLUncno3gNNDXnrmxzXvqKnQdQ==
application:bops-api-root-domain: bops-staging.services
application:bops-api-token:
secure: AAABAJx2KnnFeuEmwRB5VyE790TeYxiKmWFuVXVY8Lb7+HDNRYND8Pfd9d61zjwPzi9Jf2ZlT0OH++1MXYafhdQO28Y=
application:cloudflare-zone-id:
Expand Down
20 changes: 0 additions & 20 deletions infrastructure/application/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,26 +322,6 @@ export = async () => {
},
{ name: "SESSION_SECRET", value: config.requireSecret("session-secret") },
{ name: "API_URL_EXT", value: `https://api.${DOMAIN}` },
{
name: "BOPS_SUBMISSION_URL_LAMBETH",
value: pulumi.interpolate`https://lambeth.${config.requireSecret("bops-api-root-domain")}`,
},
{
name: "BOPS_SUBMISSION_URL_SOUTHWARK",
value: pulumi.interpolate`https://southwark.${config.requireSecret("bops-api-root-domain")}`,
},
{
name: "BOPS_SUBMISSION_URL_BUCKINGHAMSHIRE",
value: pulumi.interpolate`https://buckinghamshire.${config.requireSecret("bops-api-root-domain")}`,
},
{
name: "BOPS_SUBMISSION_URL_CAMDEN",
value: pulumi.interpolate`https://camden.${config.requireSecret("bops-api-root-domain")}`,
},
{
name: "BOPS_SUBMISSION_URL_GLOUCESTER",
value: pulumi.interpolate`https://gloucester.${config.requireSecret("bops-api-root-domain")}`,
},
{ name: "BOPS_API_TOKEN", value: config.requireSecret("bops-api-token") },
{ name: "JWT_SECRET", value: config.requireSecret("jwt-secret") },
{ name: "PORT", value: String(API_PORT) },
Expand Down
Loading