Skip to content

Commit

Permalink
HEAT-230 sanitise hostname (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrlee authored May 28, 2024
1 parent 5a203af commit 0c40368
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/data/appInsights/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { sanitize } from '.'

describe('sanitise', () => {
test('check removes :443', () => {
expect(sanitize('approved-premises-api.hmpps.service.justice.gov.uk:443')).toStrictEqual('approved-premises-api.hmpps.service.justice.gov.uk')
})

test('check removes random suffix', () => {
expect(sanitize('education-employment-api.hmpps.service.justice.gov.uk | aaaaaaa-eeee-dddd-ccccc-bbbbbbbb')).toStrictEqual(
'education-employment-api.hmpps.service.justice.gov.uk',
)
})
})
4 changes: 3 additions & 1 deletion src/data/appInsights/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ import { type Dependency } from '../Components'
import AppInsights from './Client'
import Queries from './queries'

export const sanitize = (s: string) => (s ? s.replace(':443', '').replace(/(.*?\.gov\.uk).*/, '$1') : '')

const getDependencies = async (appInsightsCreds: AppInsightsCreds): Promise<Dependency[]> => {
const appInsights = new AppInsights(appInsightsCreds)
const results = await appInsights.query(Queries.DEPENDENCIES())

return results.rows.map(row => ({ componentName: row[0], dependencyHostname: row[1], type: row[2] }))
return results.rows.map(row => ({ componentName: row[0], dependencyHostname: sanitize(row[1]), type: row[2] }))
}

export default getDependencies

0 comments on commit 0c40368

Please sign in to comment.