Skip to content

Commit

Permalink
Merge branch 'main' into DAS-1601-remove-PNG-JPEG-from-HGA
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durbin authored Oct 10, 2024
2 parents 715432c + e8fc303 commit 1f61246
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions services/harmony/app/middleware/cmr-collection-reader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@ import { EdlUserEulaInfo, verifyUserEula } from '../util/edl-api';
// (some clients may translate + to space)
const CMR_CONCEPT_ID_URL_PATH_REGEX = /\/(?:C\d+-\w+[+\s])*(?:C\d+-\w+)+(?:\/|$)/g;

// Regex for any routes that we expect to begin with a CMR collection identifier
const COLLECTION_ROUTE_REGEX = /^(\/(?!docs).*\/)(wms|ogc-api-coverages|cube|area|position|trajectory)/;
// Regex for any routes that we expect to begin with a CMR collection identifier or /ogc-api-edr/
const COLLECTION_ROUTE_REGEX = /^((\/(?!docs).*\/)(wms|ogc-api-coverages)|\/ogc-api-edr\/)/;

// Regex for retrieving collection identifier of EDR request
const EDR_COLLECTION_ROUTE_REGEX = /^\/ogc-api-edr\/.*\/collections\/(.*)\//;

/**
* Loads the variables for the given collection from the CMR and sets the collection's
Expand Down Expand Up @@ -122,9 +125,14 @@ async function cmrCollectionReader(req: HarmonyRequest, res, next: NextFunction)
// The request used a short name
const shortNameMatch = req.url.match(COLLECTION_ROUTE_REGEX);
if (shortNameMatch) {
const shortNamePart = shortNameMatch[1].substr(1, shortNameMatch[1].length - 2);
// fix the short name for ogc EDR requests
const shortName = shortNamePart.replace(/^ogc-api-edr\/.*\/collections\//, '');
let shortName = '';
if (shortNameMatch[1] == '/ogc-api-edr/') {
const edrMatch = req.url.match(EDR_COLLECTION_ROUTE_REGEX);
shortName = edrMatch[1];
} else {
shortName = shortNameMatch[2].substr(1, shortNameMatch[2].length - 2);
}

const collections = await getCollectionsByShortName(shortName, req.accessToken);
let pickedCollection = collections[0];
if (collections.length > 1) {
Expand Down
6 changes: 3 additions & 3 deletions services/harmony/test/service-image-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ describe('Service image endpoint', async function () {
describe('when the service does exist', async function () {
before(async function () {
hookRedirect('joe');
this.res = await request(this.frontend).get('/service-image-tag/hoss').use(auth({ username: 'joe' }));
this.res = await request(this.frontend).get('/service-image-tag/trajectory-subsetter').use(auth({ username: 'joe' }));
});

after(function () {
Expand Down Expand Up @@ -367,7 +367,7 @@ describe('Service image endpoint', async function () {
describe('when the service does exist', async function () {
before(async function () {
hookRedirect('buzz');
this.res = await request(this.frontend).get('/service-image-tag/hoss').use(auth({ username: 'buzz' }));
this.res = await request(this.frontend).get('/service-image-tag/trajectory-subsetter').use(auth({ username: 'buzz' }));
});

after(function () {
Expand Down Expand Up @@ -412,7 +412,7 @@ describe('Service image endpoint', async function () {
describe('when the service does exist', async function () {
before(async function () {
hookRedirect('coraline');
this.res = await request(this.frontend).get('/service-image-tag/hoss').use(auth({ username: 'coraline' }));
this.res = await request(this.frontend).get('/service-image-tag/trajectory-subsetter').use(auth({ username: 'coraline' }));
});

after(function () {
Expand Down

0 comments on commit 1f61246

Please sign in to comment.