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

Update lookup service to call portal-backend instead of GitHub #334

Merged
merged 1 commit into from
Jan 2, 2025
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
6 changes: 3 additions & 3 deletions src/api/deploy-terminal/controllers/deploy-terminal.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ const deployTerminalController = {
)
}

const tenant = await lookupTenantService(
const service = await lookupTenantService(
payload.service,
payload.environment,
logger
)

if (!tenant?.zone) {
if (!service?.zone) {
logger.error(
`failed to find zone for ${payload.service} in ${payload.environment}`
)
Expand All @@ -61,7 +61,7 @@ const deployTerminalController = {
user,
token,
environment: payload.environment,
zone: tenant.zone,
zone: service.zone,
service: payload.service
})

Expand Down
4 changes: 2 additions & 2 deletions src/api/deploy/controllers/deploy-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const deployServiceController = {
service.zone,
user,
configLatestCommitSha,
service.service_code,
service.serviceCode,
request
)

Expand All @@ -109,7 +109,7 @@ const deployServiceController = {
service.zone,
user,
configLatestCommitSha,
service.service_code,
service.serviceCode,
shouldDeployByFile,
logger
)
Expand Down
44 changes: 15 additions & 29 deletions src/api/deploy/helpers/lookup-tenant-service.js
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 }
98 changes: 0 additions & 98 deletions src/api/deploy/helpers/lookup-tenant-service.test.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/listeners/github/helpers/bulk-update-tf-svc-infra.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const bulkUpdateTfSvcInfra = async (db, trimmedWorkflow, status) => {
const serviceName = serviceToUpdate.name

let runMode = 'Service'
if (serviceToUpdate?.tenantConfig?.test_suite) {
if (serviceToUpdate?.tenantConfig?.testSuite) {
runMode = 'Job'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,8 @@ describe('bulkUpdateTtfSvcInfra', () => {
}
])
lookupTenantService.mockResolvedValue({
test_suite: 'test1',
testSuite: 'test1',
zone: 'public',
mongo: false,
redis: false,
service_code: 'TST'
})

Expand Down
Loading