-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(apikeys): implement the base paths for the api keys resource #22
Changes from 4 commits
350cc4a
9e36a75
9ab470d
ce5bdd2
9d38fdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import API from '../../APICore'; | ||
import {New} from '../BaseInterfaces'; | ||
import Resource from '../Resource'; | ||
import {ApiKeyModel, CreateApiKeyOptions} from './ApiKeysInterfaces'; | ||
|
||
export default class ApiKey extends Resource { | ||
static baseUrl = `/rest/organizations/${API.orgPlaceholder}/apikeys`; | ||
|
||
list() { | ||
return this.api.get<ApiKeyModel[]>(ApiKey.baseUrl); | ||
} | ||
|
||
create(apiKey: New<ApiKeyModel, 'resourceId'>, options?: CreateApiKeyOptions) { | ||
return this.api.post<ApiKeyModel>(this.buildPath(ApiKey.baseUrl, options), apiKey); | ||
} | ||
|
||
get(apiKeyId: string) { | ||
return this.api.get<ApiKeyModel>(`${ApiKey.baseUrl}/${apiKeyId}`); | ||
} | ||
|
||
update(apiKey: ApiKeyModel) { | ||
return this.api.put(`${ApiKey.baseUrl}/${apiKey.id}`, apiKey); | ||
} | ||
|
||
toggle(apiKey: ApiKeyModel) { | ||
const path = `${ApiKey.baseUrl}/${apiKey.id}/${apiKey.enabled ? 'disable' : 'activate'}`; | ||
|
||
return this.api.put(path, apiKey); | ||
} | ||
|
||
delete(apiKeyId: string) { | ||
return this.api.delete(`${ApiKey.baseUrl}/${apiKeyId}`); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
export interface ApiKeyModel { | ||
rosalie-liu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
organizationId?: string; | ||
id?: string; | ||
enabled?: boolean; | ||
value?: string; | ||
displayName?: string; | ||
description?: string; | ||
createdBy?: {}; | ||
createdDate?: number; | ||
allowedIps?: string[]; | ||
apiKeysThatCanEdit?: IdAndDisplayNameModel[]; | ||
deniedIps?: string[]; | ||
groupsThatCanEdit?: IdAndDisplayNameModel[]; | ||
privileges?: PrivilegeModel[]; | ||
resourceId?: string; | ||
} | ||
|
||
export enum Provider { | ||
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong. |
||
SALESFORCE = 'SALESFORCE', | ||
SALESFORCE_SANDBOX = 'SALESFORCE_SANDBOX', | ||
GOOGLE = 'GOOGLE', | ||
OFFICE365 = 'OFFICE365', | ||
SAML = 'SAML', | ||
EMAIL = 'EMAIL', | ||
OTHER = 'OTHER', | ||
} | ||
|
||
export interface IdAndDisplayNameModel { | ||
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong. |
||
id: string; | ||
displayName?: string; | ||
} | ||
|
||
export interface PrivilegeModel { | ||
rosalie-liu marked this conversation as resolved.
Show resolved
Hide resolved
This comment was marked as resolved.
Sorry, something went wrong.
This comment was marked as resolved.
Sorry, something went wrong. |
||
owner: string; | ||
targetDomain: string; | ||
targetId: string; | ||
type?: string; | ||
} | ||
|
||
export interface CreateApiKeyOptions { | ||
apiKeyTemplateId?: string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from './ApiKeys'; | ||
export * from './ApiKeysInterfaces'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import API from '../../../APICore'; | ||
import {New} from '../../BaseInterfaces'; | ||
import ApiKey from '../ApiKeys'; | ||
import {ApiKeyModel} from '../ApiKeysInterfaces'; | ||
|
||
jest.mock('../../../APICore'); | ||
|
||
const APIMock: jest.Mock<API> = API as any; | ||
|
||
describe('ApiKey', () => { | ||
let apiKey: ApiKey; | ||
const api = new APIMock() as jest.Mocked<API>; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
apiKey = new ApiKey(api); | ||
}); | ||
|
||
describe('list', () => { | ||
it('should make a GET call to the ApiKeys base url', () => { | ||
apiKey.list(); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(ApiKey.baseUrl); | ||
}); | ||
}); | ||
|
||
describe('create', () => { | ||
it('should make a POST call to the ApiKeys base url', () => { | ||
const apiKeyModel: New<ApiKeyModel> = { | ||
organizationId: 'a-smol-org', | ||
value: '', | ||
}; | ||
|
||
apiKey.create(apiKeyModel); | ||
expect(api.post).toHaveBeenCalledTimes(1); | ||
expect(api.post).toHaveBeenCalledWith(ApiKey.baseUrl, apiKeyModel); | ||
}); | ||
}); | ||
|
||
describe('get', () => { | ||
it('should make a GET call to the specific ApiKey url', () => { | ||
const apiKeyToGetId = 'ApiKey-to-be-fetched'; | ||
|
||
apiKey.get(apiKeyToGetId); | ||
expect(api.get).toHaveBeenCalledTimes(1); | ||
expect(api.get).toHaveBeenCalledWith(`${ApiKey.baseUrl}/${apiKeyToGetId}`); | ||
}); | ||
}); | ||
|
||
describe('update', () => { | ||
it('should make a PUT call to the specific ApiKey url', () => { | ||
const apiKeyModel: ApiKeyModel = { | ||
organizationId: 'a-smol-org', | ||
id: 'a-specific-id', | ||
value: '', | ||
}; | ||
|
||
apiKey.update(apiKeyModel); | ||
expect(api.put).toHaveBeenCalledTimes(1); | ||
expect(api.put).toHaveBeenCalledWith(`${ApiKey.baseUrl}/${apiKeyModel.id}`, apiKeyModel); | ||
}); | ||
}); | ||
|
||
describe('delete', () => { | ||
it('should make a DELETE call to the specific ApiKey url', () => { | ||
const apiKeyToDeleteId = 'ApiKey-to-be-deleted'; | ||
|
||
apiKey.delete(apiKeyToDeleteId); | ||
expect(api.delete).toHaveBeenCalledTimes(1); | ||
expect(api.delete).toHaveBeenCalledWith(`${ApiKey.baseUrl}/${apiKeyToDeleteId}`); | ||
}); | ||
}); | ||
|
||
describe('toggle', () => { | ||
const apiKeyModel: ApiKeyModel = { | ||
id: 'ApiKey-to-be-toggled', | ||
organizationId: 'a-smol-org', | ||
enabled: null, | ||
}; | ||
|
||
it('should make a PUT call to disable the specific apiKey', () => { | ||
apiKeyModel.enabled = true; | ||
|
||
apiKey.toggle(apiKeyModel); | ||
expect(api.put).toHaveBeenCalledTimes(1); | ||
expect(api.put).toHaveBeenCalledWith(`${ApiKey.baseUrl}/${apiKeyModel.id}/disable`, apiKeyModel); | ||
}); | ||
|
||
it('should make a PUT call to activate the specific apiKey', () => { | ||
apiKeyModel.enabled = false; | ||
|
||
apiKey.toggle(apiKeyModel); | ||
expect(api.put).toHaveBeenCalledTimes(1); | ||
expect(api.put).toHaveBeenCalledWith(`${ApiKey.baseUrl}/${apiKeyModel.id}/activate`, apiKeyModel); | ||
}); | ||
}); | ||
}); |
This comment was marked as resolved.
Sorry, something went wrong.