-
-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the JobTokenScopes API (#3571)
- Loading branch information
1 parent
2f6335a
commit 32ed802
Showing
7 changed files
with
155 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { BaseResource } from '@gitbeaker/requester-utils'; | ||
import { RequestHelper, endpoint } from '../infrastructure'; | ||
import type { GitlabAPIResponse, ShowExpanded, Sudo } from '../infrastructure'; | ||
import { SimpleProjectSchema } from './Projects'; | ||
|
||
export interface JobTokenScopeSchema extends Record<string, unknown> { | ||
inbound_enabled: boolean; | ||
outbound_enabled: boolean; | ||
} | ||
|
||
export interface AllowListSchema extends Record<string, unknown> { | ||
source_project_id: number; | ||
target_project_id: number; | ||
} | ||
|
||
export class JobTokenScopes<C extends boolean = false> extends BaseResource<C> { | ||
show<E extends boolean = false>( | ||
projectId: string | number, | ||
options?: Sudo & ShowExpanded<E>, | ||
): Promise<GitlabAPIResponse<JobTokenScopeSchema, C, E, void>> { | ||
return RequestHelper.get<JobTokenScopeSchema>()( | ||
this, | ||
endpoint`projects/${projectId}/job_token_scope`, | ||
options, | ||
); | ||
} | ||
|
||
edit<E extends boolean = false>( | ||
projectId: string | number, | ||
enabled: boolean, | ||
options?: Sudo & ShowExpanded<E>, | ||
): Promise<GitlabAPIResponse<JobTokenScopeSchema, C, E, void>> { | ||
return RequestHelper.patch<JobTokenScopeSchema>()( | ||
this, | ||
endpoint`projects/${projectId}/job_token_scope`, | ||
{ ...options, enabled }, | ||
); | ||
} | ||
|
||
showInboundAllowList<E extends boolean = false>( | ||
projectId: string | number, | ||
options?: Sudo & ShowExpanded<E>, | ||
): Promise<GitlabAPIResponse<SimpleProjectSchema[], C, E, void>> { | ||
return RequestHelper.get<SimpleProjectSchema[]>()( | ||
this, | ||
endpoint`projects/${projectId}/job_token_scope/allowlist`, | ||
options, | ||
); | ||
} | ||
|
||
addToInboundAllowList<E extends boolean = false>( | ||
projectId: string | number, | ||
targetProjectId: string | number, | ||
options?: Sudo & ShowExpanded<E>, | ||
): Promise<GitlabAPIResponse<AllowListSchema, C, E, void>> { | ||
return RequestHelper.post<AllowListSchema>()( | ||
this, | ||
endpoint`projects/${projectId}/job_token_scope/allowlist/${targetProjectId}`, | ||
options, | ||
); | ||
} | ||
|
||
removeFromInboundAllowList<E extends boolean = false>( | ||
projectId: string | number, | ||
targetProjectId: string | number, | ||
options?: Sudo & ShowExpanded<E>, | ||
): Promise<GitlabAPIResponse<void, C, E, void>> { | ||
return RequestHelper.del()( | ||
this, | ||
endpoint`projects/${projectId}/job_token_scope/allowlist/${targetProjectId}`, | ||
options, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { JobTokenScopes } from '../../../src'; | ||
import { RequestHelper } from '../../../src/infrastructure'; | ||
|
||
jest.mock( | ||
'../../../src/infrastructure/RequestHelper', | ||
() => require('../../__mocks__/RequestHelper').default, | ||
); | ||
|
||
let service: JobTokenScopes; | ||
|
||
beforeEach(() => { | ||
service = new JobTokenScopes({ | ||
requesterFn: jest.fn(), | ||
token: 'abcdefg', | ||
}); | ||
}); | ||
|
||
describe('JobTokenScopes.show', () => { | ||
it('should request GET /projects/:id/job_token_scope', async () => { | ||
await service.show(1); | ||
|
||
expect(RequestHelper.get()).toHaveBeenCalledWith( | ||
service, | ||
'projects/1/job_token_scope', | ||
undefined, | ||
); | ||
}); | ||
}); | ||
|
||
describe('JobTokenScopes.edit', () => { | ||
it('should request PATCH /projects/:id/job_token_scope', async () => { | ||
await service.edit(1, false); | ||
|
||
expect(RequestHelper.get()).toHaveBeenCalledWith(service, 'projects/1/job_token_scope', { | ||
enabled: false, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('JobTokenScopes.showInboundAllowList', () => { | ||
it('should request GET /projects/:id/job_token_scope/allowlist', async () => { | ||
await service.showInboundAllowList(1); | ||
|
||
expect(RequestHelper.get()).toHaveBeenCalledWith( | ||
service, | ||
'projects/1/job_token_scope/allowlist', | ||
undefined, | ||
); | ||
}); | ||
}); | ||
|
||
describe('JobTokenScopes.addToInboundAllowList', () => { | ||
it('should request POST /projects/:id/job_token_scope/allowlist/:targetId', async () => { | ||
await service.addToInboundAllowList(1, 2); | ||
|
||
expect(RequestHelper.post()).toHaveBeenCalledWith( | ||
service, | ||
'projects/1/job_token_scope/allowlist/2', | ||
undefined, | ||
); | ||
}); | ||
}); | ||
|
||
describe('JobTokenScopes.removeFromInboundAllowList', () => { | ||
it('should request DEL /projects/:id/job_token_scope/allowlist/:targetId', async () => { | ||
await service.removeFromInboundAllowList(1, 2); | ||
|
||
expect(RequestHelper.del()).toHaveBeenCalledWith( | ||
service, | ||
'projects/1/job_token_scope/allowlist/2', | ||
undefined, | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters