Skip to content

Commit

Permalink
feat: add api key template api call for usage panel (#851)
Browse files Browse the repository at this point in the history
* feat: add api key template api call for usage panel
J:ORG-659

* chore: fix build

* chore: fix build

* chore: replace url by fetch by id

* chore: fix test

* chore: fix build

* Update src/resources/ApiKeyTemplate/ApiKeyTemplateInterface.ts

Co-authored-by: Gaël Dostie <35579930+gdostie@users.noreply.github.com>

* Update src/resources/ApiKeyTemplate/ApiKeyTemplate.ts

Co-authored-by: Gaël Dostie <35579930+gdostie@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Gaël Dostie <35579930+gdostie@users.noreply.github.com>

* chore: apply pr comments

* chore: fix build

* Update src/resources/ApiKeyTemplate/test/ApiKeyTemplate.spec.ts

Co-authored-by: Gaël Dostie <35579930+gdostie@users.noreply.github.com>

---------

Co-authored-by: Gaël Dostie <35579930+gdostie@users.noreply.github.com>
  • Loading branch information
schaoukicoveo and gdostie authored Sep 5, 2024
1 parent 2d6cbc4 commit 2375f77
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/resources/ApiKeyTemplate/ApiKeyTemplate.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import Resource from "../Resource.js";
import { 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}`)
}
}
28 changes: 28 additions & 0 deletions src/resources/ApiKeyTemplate/ApiKeyTemplateInterface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { PrivilegeModel } from "../BaseInterfaces.js";

export interface ApiKeyTemplateModel {
/**
* The unique identifier of the API key template.
*/
id?: string;
/**
* The displaye name of the Api key template.
*/
displayName?: string;
/**
* The descirption of the Api key template.
*/
description?: string;
/**
* A set of IP addresses allowed to use the Api key template.
*/
allowedIps?: string[];
/**
* A set of IP addresses that will be denied access when attempting to use the API key template.
*/
deniedIps?: string[];
/**
* A set of privileges binded to an api key template.
*/
privileges?: PrivilegeModel[];
}
2 changes: 2 additions & 0 deletions src/resources/ApiKeyTemplate/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './ApiKeyTemplate.js';
export * from './ApiKeyTemplateInterface.js';
27 changes: 27 additions & 0 deletions src/resources/ApiKeyTemplate/test/ApiKeyTemplate.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import API from '../../../APICore.js';

import ApiKeyTemplate from '../ApiKeyTemplate.js';

jest.mock('../../../APICore.js');

const APIMock: jest.Mock<API> = API as any;

describe('ApiKeyTemplateModel', () => {
let apiKeyTemplate: ApiKeyTemplate;
const api = new APIMock() as jest.Mocked<API>;
const serverlessApi = new APIMock() as jest.Mocked<API>;

beforeEach(() => {
jest.clearAllMocks();
apiKeyTemplate = new ApiKeyTemplate(api, serverlessApi);
});

describe('get', () => {
it('should make a GET call to the ApiKeys at the keyPurpose', async () => {
const apiKeyTemplateToGetId = 'ApikeyTemplate-to-be-fetched';
await apiKeyTemplate.get(apiKeyTemplateToGetId);
expect(api.get).toHaveBeenCalledTimes(1);
expect(api.get).toHaveBeenCalledWith(`${ApiKeyTemplate.baseUrl}/${apiKeyTemplateToGetId}`);
});
});
});
3 changes: 3 additions & 0 deletions src/resources/PlatformResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@ import Project from './Projects/Project.js';
import Resources from './Resources/Resources.js';
import CatalogContent from './Catalogs/CatalogContent.js';
import Properties from './AnalyticsAdmin/Properties/Properties.js';
import ApiKeyTemplate from './ApiKeyTemplate/ApiKeyTemplate.js';

const resourcesMap: Array<{key: string; resource: typeof Resource}> = [
{key: 'activity', resource: Activity},
{key: 'apiKey', resource: ApiKey},
{key: 'apiKeyTemplate', resource: ApiKeyTemplate},
{key: 'aws', resource: AWS},
{key: 'caseAssistConfig', resource: CaseAssistConfig},
{key: 'catalog', resource: Catalog},
Expand Down Expand Up @@ -120,6 +122,7 @@ class PlatformResources {

activity: Activity;
apiKey: ApiKey;
apiKeyTemplate: ApiKeyTemplate;
aws: AWS;
caseAssistConfig: CaseAssistConfig;
catalog: Catalog;
Expand Down
1 change: 1 addition & 0 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export {default as Resource} from './Resource.js';

export * from './Activities/index.js';
export * from './ApiKeys/index.js';
export * from './ApiKeyTemplate/index.js';
export * from './AWS/index.js';
export * from './BaseInterfaces.js';
export * from './CaseAssistConfigs/index.js';
Expand Down

0 comments on commit 2375f77

Please sign in to comment.