1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-25 00:07:47 +01:00

fix: clean up proxy clients on API key deletion (#1950)

This commit is contained in:
olav 2022-08-22 15:02:39 +02:00 committed by GitHub
parent 655c0dea2c
commit 634e188f73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -31,6 +31,7 @@ import {
} from '../../openapi/spec/api-token-schema';
import { UpdateApiTokenSchema } from '../../openapi/spec/update-api-token-schema';
import { emptyResponse } from '../../openapi/util/standard-responses';
import { ProxyService } from '../../services/proxy-service';
interface TokenParam {
token: string;
@ -40,6 +41,8 @@ export class ApiTokenController extends Controller {
private accessService: AccessService;
private proxyService: ProxyService;
private openApiService: OpenApiService;
private logger: Logger;
@ -49,15 +52,20 @@ export class ApiTokenController extends Controller {
{
apiTokenService,
accessService,
proxyService,
openApiService,
}: Pick<
IUnleashServices,
'apiTokenService' | 'accessService' | 'openApiService'
| 'apiTokenService'
| 'accessService'
| 'proxyService'
| 'openApiService'
>,
) {
super(config);
this.apiTokenService = apiTokenService;
this.accessService = accessService;
this.proxyService = proxyService;
this.openApiService = openApiService;
this.logger = config.getLogger('api-token-controller.js');
@ -180,6 +188,7 @@ export class ApiTokenController extends Controller {
const { token } = req.params;
await this.apiTokenService.delete(token);
this.proxyService.deleteClientForProxyToken(token);
res.status(200).end();
}

View File

@ -114,6 +114,10 @@ export class ProxyService {
return client;
}
deleteClientForProxyToken(secret: string): void {
this.clients.delete(secret);
}
private static assertExpectedTokenType({ type }: ApiUser) {
assert(type === ApiTokenType.FRONTEND || type === ApiTokenType.ADMIN);
}