Skip to content

Commit

Permalink
feat: get broker booking partner identifiers from config (#546)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Luke Winship <[email protected]>
Co-authored-by: Nick Evans <[email protected]>
  • Loading branch information
3 people authored Jul 13, 2023
1 parent a178cd8 commit b321609
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 3 additions & 1 deletion packages/openactive-broker-microservice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ While debugging authentication it can be useful to log the configuration that th

Config for [Booking Partners](https://openactive.io/open-booking-api/EditorsDraft/1.0CR3/#dfn-booking-partner) that the Test Suite will use to connect to your Booking System.

Broker uses two Booking Partners, named `primary` and `secondary`.
When running Broker Microservice with [Integration Tests](../openactive-integration-tests/) (which is the primary usage of Broker Microservice), you must define two Booking Partners, named `primary` and `secondary`.

```json
"bookingPartners": {
Expand All @@ -178,6 +178,8 @@ Broker uses two Booking Partners, named `primary` and `secondary`.
}
```

When running Broker Microservice as a standalone app, any number of Booking Partners may be defined e.g. `acme1`, `acme2` and `acme3` instead of `primary` and `secondary`. Note that these will _not_ work with the [Integration Tests](../openactive-integration-tests/), which expect only `primary` and `secondary`.

The `authentication` field can contain one of several different authentication strategies for authenticating as the Booking Partner for Order and Order Proposal RPDE Feed requests. Set only one of these strategies. The different authentication strategies are documented in the below subsections.

#### `bookingPartners[bookingPartnerIdentifier].authentication.ordersFeedRequestHeaders`
Expand Down
12 changes: 3 additions & 9 deletions packages/openactive-broker-microservice/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const {
CONSOLE_OUTPUT_LEVEL,
HEADLESS_AUTH,
VALIDATOR_TMP_DIR,
BOOKING_PARTNER_IDENTIFIERS,
} = require('./src/broker-config');
const { getIsOrderUuidPresentApi } = require('./src/order-uuid-tracking/api');
const { createOpportunityListenerApi, getOpportunityListenerApi, createOrderListenerApi, getOrderListenerApi } = require('./src/twoPhaseListeners/api');
Expand Down Expand Up @@ -1652,14 +1653,9 @@ Validation errors found in Dataset Site JSON-LD:
}
});

/**
* @type {BookingPartnerIdentifier[]}
*/
const bookingPartnerIdentifiers = ['primary', 'secondary'];

// Only poll orders feed if included in the dataset site
if (!VALIDATE_ONLY && !DO_NOT_HARVEST_ORDERS_FEED && dataset.accessService && dataset.accessService.endpointUrl) {
for (const { feedUrl, type, feedContextIdentifier, bookingPartnerIdentifier: feedBookingPartnerIdentifier } of bookingPartnerIdentifiers.flatMap((bookingPartnerIdentifier) => [
for (const { feedUrl, type, feedContextIdentifier, bookingPartnerIdentifier: feedBookingPartnerIdentifier } of BOOKING_PARTNER_IDENTIFIERS.flatMap((bookingPartnerIdentifier) => [
{
feedUrl: `${dataset.accessService.endpointUrl}/orders-rpde`,
type: /** @type {OrderFeedType} */('orders'),
Expand All @@ -1681,9 +1677,7 @@ Validation errors found in Dataset Site JSON-LD:
baseUrl: feedUrl,
feedContextIdentifier,
headers: withOrdersRpdeHeaders(getOrdersFeedHeader(feedBookingPartnerIdentifier)),
processPage: feedBookingPartnerIdentifier === 'primary'
? monitorOrdersPage(type, feedBookingPartnerIdentifier)
: () => null,
processPage: monitorOrdersPage(type, feedBookingPartnerIdentifier),
isOrdersFeed: true,
bar: state.multibar,
processEndOfFeed: () => {
Expand Down
6 changes: 6 additions & 0 deletions packages/openactive-broker-microservice/src/broker-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ const ORDERS_FEED_IDENTIFIER = 'OrdersFeed';
/** @type {import('./models/core').OrderFeedIdentifier} */
const ORDER_PROPOSALS_FEED_IDENTIFIER = 'OrderProposalsFeed';

const BOOKING_PARTNER_IDENTIFIERS = Object.entries(config.get('broker.bookingPartners')).map(([key, value]) => {
if (value) return key;
return null;
}).filter(Boolean);

// These options are not recommended for general use, but are available for specific test environment configuration and debugging
const OPPORTUNITY_FEED_REQUEST_HEADERS = config.has('broker.opportunityFeedRequestHeaders') ? config.get('broker.opportunityFeedRequestHeaders') : {};
const DATASET_DISTRIBUTION_OVERRIDE = config.has('broker.datasetDistributionOverride') ? config.get('broker.datasetDistributionOverride') : [];
Expand Down Expand Up @@ -92,4 +97,5 @@ module.exports = {
HEADLESS_AUTH,
VALIDATOR_TMP_DIR,
VALIDATOR_INPUT_TMP_DIR,
BOOKING_PARTNER_IDENTIFIERS,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { SingleBar } from 'cli-progress';

export type OrderFeedType = 'orders' | 'order-proposals';
export type OrderFeedIdentifier = 'OrdersFeed' | 'OrderProposalsFeed';
export type BookingPartnerIdentifier = 'primary' | 'secondary';
export type BookingPartnerIdentifier = string;

export type FeedContext = {
currentPage: string;
Expand Down

0 comments on commit b321609

Please sign in to comment.