Skip to content

Commit

Permalink
Merge pull request #1760 from alphagov/pp_11812_revoke_api_keys
Browse files Browse the repository at this point in the history
PP-11812 Revoke API keys when a service is archived
  • Loading branch information
kbottla authored Nov 29, 2023
2 parents 1a5ef2a + 5bdc500 commit d36c5a9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/web/modules/services/detail.njk
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
Toggle the archived status of this service.
</p>
<p class="govuk-body">
This will remove ALL users from service, redacts gateway account credentials and impacts internal Pay team reports
This will remove ALL users from the service, revoke API keys, and redact gateway account credentials. Also impacts internal Pay team reports
</p>
<p class="govuk-body">This should not be used if you need to suspend a service</p>
{% endif %}
Expand Down
22 changes: 18 additions & 4 deletions src/web/modules/services/services.http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {Request, Response} from 'express'
import {ParsedQs, stringify} from 'qs'

import logger from '../../../lib/logger'
import {AdminUsers, Connector} from '../../../lib/pay-request/client'
import {AdminUsers, Connector, PublicAuth} from '../../../lib/pay-request/client'
import type {Service, User} from '../../../lib/pay-request/services/admin_users/types'
import {wrapAsyncErrorHandler} from '../../../lib/routes'
import {sanitiseCustomBrandingURL} from './branding'
Expand Down Expand Up @@ -47,7 +47,7 @@ const performancePlatformCsv = async function performancePlatformCsv(req: Reques
const liveActiveServices = await getLiveNotArchivedServices()

res.set('Content-Type', 'text/csv')
res.set('Content-Disposition', `attachment; filename="GOVUK_Pay_live_services_for_perfomance_platform.csv"`)
res.set('Content-Disposition', `attachment; filename="GOVUK_Pay_live_services_for_performance_platform.csv"`)
res.status(200).send(formatPerformancePlatformCsv(liveActiveServices))
}

Expand Down Expand Up @@ -207,7 +207,7 @@ const toggleTerminalStateRedirectFlag = async function toggleTerminalStateRedire
})
logger.info(`Toggled redirect to service on terminal state flag to ${enable} for service ${serviceId}`, {externalId: serviceId})

req.flash('info', `Redirect to service on terminal state ${ enable? 'enabled' : 'disabled'}`)
req.flash('info', `Redirect to service on terminal state ${enable ? 'enabled' : 'disabled'}`)
res.redirect(`/services/${serviceId}`)
}

Expand Down Expand Up @@ -313,12 +313,26 @@ const toggleArchiveService = async function toggleArchiveService(

const service = await AdminUsers.services.retrieve(serviceId);
const archive = !service.archived

if (archive) {
const serviceGatewayAccounts = await getServiceGatewayAccounts(service.gateway_account_ids)

serviceGatewayAccounts.map(async account => {
const tokensResponse = await PublicAuth.tokens.list({gateway_account_id: account.gateway_account_id})

tokensResponse.tokens.map(async token => {
await PublicAuth.tokens.delete({gateway_account_id: account.gateway_account_id, token_link: token.token_link})
logger.info(`Deleted API Token with token_link ${token.token_link} for Gateway Account ${account.gateway_account_id}`)
})
})
}

await AdminUsers.services.update(serviceId, {
archived: archive
})
logger.info(`Toggled archive status to ${archive} for service ${serviceId}`, {externalId: serviceId})

req.flash('info', `Service ${archive ? 'archived': 'un-archived'}`)
req.flash('info', `Service ${archive ? 'archived' : 'un-archived'}`)
res.redirect(`/services/${serviceId}`)
}

Expand Down

0 comments on commit d36c5a9

Please sign in to comment.