Skip to content

Commit

Permalink
feat(api-keys): +listing apikey eligibility call endpoint (#889)
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixBlaisThon authored Dec 2, 2024
1 parent e6cfa62 commit 45b9ad7
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/resources/ApiKeyTemplate/ApiKeyTemplate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import Resource from '../Resource.js';
import {ApiKeyTemplateModel} from './ApiKeyTemplateInterface.js';
import {ApiKeyTemplateEligibilityResponseModel, ApiKeyTemplateModel} from './ApiKeyTemplateInterface.js';

export default class ApiKeyTemplate extends Resource {
static baseUrl = '/rest/templates/apikeys';

get(apiKeyTemplateId: string) {
return this.api.get<ApiKeyTemplateModel>(`${ApiKeyTemplate.baseUrl}/${apiKeyTemplateId}`);
}

listAPIKeysEligibility() {
return this.api.get<ApiKeyTemplateEligibilityResponseModel[]>(
`${ApiKeyTemplate.baseUrl}/privileges/eligibility`,
);
}
}
15 changes: 15 additions & 0 deletions src/resources/ApiKeyTemplate/ApiKeyTemplateInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,18 @@ export interface ApiKeyTemplateModel {
*/
privileges?: PrivilegeModel[];
}

export interface ApiKeyTemplateEligibilityResponseModel {
/**
* The id of the template
*/
id: string;
/**
* The list of privileges missing to access the template
*/
missingPrivileges: PrivilegeModel[];
/**
* If the user can generate an API key from this template
*/
canGenerate: boolean;
}
8 changes: 8 additions & 0 deletions src/resources/ApiKeyTemplate/test/ApiKeyTemplate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ describe('ApiKeyTemplateModel', () => {
expect(api.get).toHaveBeenCalledWith(`${ApiKeyTemplate.baseUrl}/${apiKeyTemplateToGetId}`);
});
});

describe('listAPIKeysEligibility', () => {
it('should make a GET call to the listAPIKeysEligibility endpoint', async () => {
await apiKeyTemplate.listAPIKeysEligibility();
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${ApiKeyTemplate.baseUrl}/privileges/eligibility`);
});
});
});

0 comments on commit 45b9ad7

Please sign in to comment.