Skip to content

Commit

Permalink
Remove tenant_service.json fallback from tenant service lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
chotai committed Sep 26, 2024
1 parent 49e2366 commit 10f657c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 130 deletions.
33 changes: 1 addition & 32 deletions src/api/deploy/helpers/lookup-tenant-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,38 +31,7 @@ async function lookupTenantService(service, environment, ref = 'main') {
Joi.assert(service, schema) // Check file in correct format
return service
} catch (error) {
logger.error(
`Error attempting to retrieve ${filePath} from GitHub - Falling back to tenant_services.json, ${error}`
)
return await lookupLegacyTenantService(service, environment, org, repo, ref)
}
}

/**
* Get service from the legacy single-file version of tenants.json
* @param {string} service
* @param {string} environment
* @param {string} owner
* @param {string} repo
* @param {string} ref
* @returns {Promise<undefined|*>}
*/
async function lookupLegacyTenantService(
service,
environment,
owner,
repo,
ref
) {
const filePath = `environments/${environment}/resources/tenant_services.json`
logger.info(`Getting legacy tenant file ${filePath}`)
try {
const data = await getContent(owner, repo, filePath, ref)
const services = JSON.parse(data)
return services[0][service]
} catch (error) {
logger.error(error, `Error attempting to retrieve ${filePath} from GitHub`)
return undefined
logger.error(`Error attempting to retrieve ${filePath} from GitHub`)
}
}

Expand Down
99 changes: 1 addition & 98 deletions src/api/deploy/helpers/lookup-tenant-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,101 +36,12 @@ describe('lookupTenantService', () => {
expect(result).toEqual(tenant)
})

test('should fallback to legacy tenant json when not found', async () => {
const tenants = [
{
someService: {
zone: 'public',
mongo: false,
redis: true,
service_code: 'ABC'
}
}
]

getContent
.mockReturnValueOnce(null)
.mockResolvedValue(JSON.stringify(tenants))

const result = await lookupTenantService('someService', 'dev')

expect(mockGetContent).toHaveBeenNthCalledWith(
1,
org,
repo,
'environments/dev/tenants/someService.json',
'main'
)

expect(mockGetContent).toHaveBeenNthCalledWith(
2,
org,
repo,
'environments/dev/resources/tenant_services.json',
'main'
)

expect(result).toEqual({
zone: 'public',
mongo: false,
redis: true,
service_code: 'ABC'
})
})

test('should fallback to legacy tenant json when service_code is missing', async () => {
const missingServiceCode = {
zone: 'public',
mongo: false,
redis: true
}
const tenants = [
{
someService: {
zone: 'public',
mongo: false,
redis: true,
service_code: 'ABC'
}
}
]

getContent
.mockReturnValueOnce(missingServiceCode)
.mockResolvedValue(JSON.stringify(tenants))

const result = await lookupTenantService('someService', 'dev')

expect(mockGetContent).toHaveBeenNthCalledWith(
1,
org,
repo,
'environments/dev/tenants/someService.json',
'main'
)

expect(mockGetContent).toHaveBeenNthCalledWith(
2,
org,
repo,
'environments/dev/resources/tenant_services.json',
'main'
)

expect(result).toEqual({
zone: 'public',
mongo: false,
redis: true,
service_code: 'ABC'
})
})

test('should return nothing when the service doesnt exist', async () => {
getContent.mockResolvedValue(null)

const result = await lookupTenantService('someService', 'dev')

expect(mockGetContent).toHaveBeenCalledTimes(2)
expect(mockGetContent).toHaveBeenCalledTimes(1)
expect(result).toBeUndefined()
})

Expand Down Expand Up @@ -159,14 +70,6 @@ describe('lookupTenantService', () => {
'environments/dev/tenants/someService.json',
'87428fc5'
)

expect(mockGetContent).toHaveBeenNthCalledWith(
2,
org,
repo,
'environments/dev/resources/tenant_services.json',
'87428fc5'
)
})

test('should get the tenant service from the single file version when present even if it has extra fields', async () => {
Expand Down

0 comments on commit 10f657c

Please sign in to comment.