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

DOP-3960: use dev endpoint to fetch versioned API spec in staging #936

Merged
merged 13 commits into from
Nov 20, 2023
2 changes: 2 additions & 0 deletions modules/oas-page-builder/src/services/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ const getDbName = () => {
switch (env) {
// Autobuilder's prd env
case 'production':
return 'snooty_prod';
case 'dotcomprd':
return 'snooty_dotcomprd';
// Autobuilder's pre-prd env
rayangler marked this conversation as resolved.
Show resolved Hide resolved
case 'staging':
return 'snooty_stage';
case 'dotcomstg':
return 'snooty_dotcomstg';
default:
Expand Down
13 changes: 10 additions & 3 deletions modules/oas-page-builder/src/services/pageBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,15 @@ import { findLastSavedVersionData, saveSuccessfulBuildVersionData } from './data
import { VersionData } from './models/OASFile';
import { normalizeUrl } from '../utils/normalizeUrl';

const OAS_FILE_SERVER = 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/';
const GIT_HASH_URL = 'https://cloud.mongodb.com/version';
const env = process.env.SNOOTY_ENV ?? '';

const OAS_FILE_SERVER =
env === 'dotcomprd'
? 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/'
: 'https://mongodb-mms-build-server.s3.amazonaws.com/openapi/';

const GIT_HASH_URL =
env === 'dotcomprd' ? 'https://cloud.mongodb.com/version' : 'https://cloud-dev.mongodb.com/version';

const fetchTextData = async (url: string, errMsg: string) => {
const res = await fetch(url);
Expand Down Expand Up @@ -274,7 +281,7 @@ export const buildOpenAPIPages = async (
if (totalSuccess && sourceType == 'atlas') {
try {
const gitHash = await fetchGitHash();
const versions = await fetchVersionData(gitHash);
const versions = await fetchVersionData(gitHash, OAS_FILE_SERVER);
await saveSuccessfulBuildVersionData(source, gitHash, versions);
rayangler marked this conversation as resolved.
Show resolved Hide resolved
} catch (e) {
console.error(e);
Expand Down
4 changes: 2 additions & 2 deletions modules/oas-page-builder/src/utils/fetchVersionData.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fetch from 'node-fetch';

export const fetchVersionData = async (gitHash: string) => {
const versionUrl = `https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${gitHash}-api-versions.json`;
export const fetchVersionData = async (gitHash: string, serverURL: string) => {
const versionUrl = `${serverURL}${gitHash}-api-versions.json`;
const res = await fetch(versionUrl);
const { versions } = await res.json();
return versions;
Expand Down
16 changes: 8 additions & 8 deletions modules/oas-page-builder/tests/unit/services/pageBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('pageBuilder', () => {
);
// Atlas
expect(mockExecute).toBeCalledWith(
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}.json`,
`https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}.json`,
getExpectedOutputPath(testOptions.output, testEntries[2][0]),
expectedAtlasBuildOptions,
undefined
Expand Down Expand Up @@ -139,7 +139,7 @@ describe('pageBuilder', () => {
);
// Atlas
expect(mockExecute).toBeCalledWith(
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v1.json`,
`https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v1.json`,
getExpectedOutputPath(testOptions.output, testEntries[2][0], API_VERSION),
expectedAtlasBuildOptions,
undefined
Expand Down Expand Up @@ -211,14 +211,14 @@ describe('pageBuilder', () => {

// Atlas
expect(mockExecute).toBeCalledWith(
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${RESOURCE_VERSION}.json`,
`https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${RESOURCE_VERSION}.json`,
getExpectedOutputPath(testOptions.output, testEntries[2][0], API_VERSION, RESOURCE_VERSION),
expectedAtlasBuildOptions,
getExpectedVersionOptions(`${SITE_URL}/${testEntries[2][0]}`)
);

expect(mockExecute).toBeCalledWith(
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${RESOURCE_VERSION}.json`,
`https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${RESOURCE_VERSION}.json`,
getExpectedOutputPath(testOptions.output, testEntries[2][0], API_VERSION, RESOURCE_VERSION),
expectedAtlasBuildOptions,
getExpectedVersionOptions(`${SITE_URL}/${testEntries[2][0]}`)
Expand Down Expand Up @@ -254,21 +254,21 @@ describe('pageBuilder', () => {
await buildOpenAPIPages(testEntries, testOptions);

expect(mockExecute).toBeCalledWith(
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${OLDEST_RESOURCE_VERSION}.json`,
`https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${OLDEST_RESOURCE_VERSION}.json`,
getExpectedOutputPath(testOptions.output, testEntries[0][0], API_VERSION, OLDEST_RESOURCE_VERSION),
expectedAtlasBuildOptions,
getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`, OLDEST_RESOURCE_VERSION)
);

expect(mockExecute).toBeCalledWith(
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${LATEST_RESOURCE_VERSION}.json`,
`https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${LATEST_RESOURCE_VERSION}.json`,
getExpectedOutputPath(testOptions.output, testEntries[0][0], API_VERSION, LATEST_RESOURCE_VERSION),
expectedAtlasBuildOptions,
getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`, LATEST_RESOURCE_VERSION)
);

expect(mockExecute).toBeCalledWith(
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${LATEST_RESOURCE_VERSION}.json`,
`https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${MOCKED_GIT_HASH}-v2-${LATEST_RESOURCE_VERSION}.json`,
getExpectedOutputPath(testOptions.output, testEntries[0][0], API_VERSION, LATEST_RESOURCE_VERSION),
expectedAtlasBuildOptions,
getExpectedVersionOptions(`${SITE_URL}/${testEntries[0][0]}`, LATEST_RESOURCE_VERSION)
Expand All @@ -283,7 +283,7 @@ describe('pageBuilder', () => {

await buildOpenAPIPages(testEntries, testOptions);
expect(mockExecute).toBeCalledWith(
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/${LAST_SAVED_GIT_HASH}.json`,
`https://mongodb-mms-build-server.s3.amazonaws.com/openapi/${LAST_SAVED_GIT_HASH}.json`,
getExpectedOutputPath(testOptions.output, testEntries[0][0]),
expectedAtlasBuildOptions,
undefined
Expand Down
Loading