-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #334 from DEFRA/485829
Update lookup service to call portal-backend instead of GitHub
- Loading branch information
Showing
6 changed files
with
22 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,27 @@ | ||
import Joi from 'joi' | ||
|
||
import { getContent } from '~/src/helpers/github/get-content.js' | ||
import { config } from '~/src/config/index.js' | ||
|
||
const org = config.get('github.org') | ||
const repo = config.get('github.repos.cdpTfSvcInfra') | ||
|
||
const schema = Joi.object({ | ||
zone: Joi.string().valid('public', 'protected').required(), | ||
service_code: Joi.any(), | ||
mongo: Joi.boolean(), | ||
redis: Joi.boolean(), | ||
test_suite: Joi.string() | ||
}).unknown(true) | ||
import { fetcher } from '~/src/helpers/fetcher.js' | ||
import Boom from '@hapi/boom' | ||
|
||
/** | ||
* Get service from the multi-file version of tenants.json | ||
* Get service from portal-backend | ||
* @param {string} service | ||
* @param {string} environment | ||
* @param {Logger} logger | ||
* @param {string} ref | ||
* @returns {Promise<undefined|*>} | ||
*/ | ||
async function lookupTenantService(service, environment, logger, ref = 'main') { | ||
const filePath = `environments/${environment}/tenants/${service}.json` | ||
try { | ||
const data = await getContent(org, repo, filePath, ref) | ||
if (!data) { | ||
logger.warn(`Tenant environment file ${filePath} from GitHub not found`) | ||
return undefined | ||
} | ||
const service = JSON.parse(data) | ||
Joi.assert(service, schema) // Check file in correct format | ||
return service | ||
} catch (error) { | ||
logger.error(error, `Error attempting to retrieve ${filePath} from GitHub`) | ||
async function lookupTenantService(service, environment, logger) { | ||
const url = `${config.get('portalBackendUrl')}/tenant-services/${service}/${environment}` | ||
const response = await fetcher(url, { | ||
method: 'get', | ||
headers: { 'Content-Type': 'application/json' } | ||
}) | ||
const json = await response.json() | ||
|
||
if (response.ok) { | ||
return json | ||
} | ||
logger.error(`Service lookup failed: ${json.message}`) | ||
throw Boom.boomify(new Error(json.message), { statusCode: response.status }) | ||
} | ||
|
||
export { lookupTenantService } |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters