Skip to content

Commit

Permalink
Add creation for service accounts on selfhosted instances (#3458)
Browse files Browse the repository at this point in the history
  • Loading branch information
Djcd authored Nov 17, 2023
1 parent c39ac08 commit 29c2b39
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 3 deletions.
9 changes: 9 additions & 0 deletions packages/core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1645,6 +1645,15 @@ import { Gitlab } from '@gitbeaker/core';
</td>
</tr>
<tr>
<th>ServiceAccounts</th>
<td>
<a href="https://docs.gitlab.com/ee/api/users.html#create-service-account-user">🦊</a>
</td>
<td>
<a href="./src/resources/ServiceAccounts.ts">⌨️</a>
</td>
</tr>
<tr>
<th>ServiceData</th>
<td>
<a href="https://docs.gitlab.com/16.4/ee/api/usage_data.html">🦊</a>
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/resources/Gitlab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import { PyPI } from './PyPI';
import { RubyGems } from './RubyGems';
import { Search } from './Search';
import { SearchAdmin } from './SearchAdmin';
import { ServiceAccounts } from './ServiceAccounts';
import { ServiceData } from './ServiceData';
import { SidekiqMetrics } from './SidekiqMetrics';
import { SidekiqQueues } from './SidekiqQueues';
Expand Down Expand Up @@ -237,6 +238,7 @@ export interface Gitlab<C extends boolean = false> extends BaseResource<C> {
RubyGems: RubyGems<C>;
Search: Search<C>;
SearchAdmin: SearchAdmin<C>;
ServiceAccounts: ServiceAccounts<C>;
ServiceData: ServiceData<C>;
SidekiqMetrics: SidekiqMetrics<C>;
SidekiqQueues: SidekiqQueues<C>;
Expand Down Expand Up @@ -426,6 +428,7 @@ const resources = {
RubyGems,
Search,
SearchAdmin,
ServiceAccounts,
ServiceData,
SidekiqMetrics,
SidekiqQueues,
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/resources/GroupServiceAccounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { AccessTokenSchema } from '../templates/ResourceAccessTokens';
import { RequestHelper, endpoint } from '../infrastructure';
import type { GitlabAPIResponse, MappedOmit, ShowExpanded, Sudo } from '../infrastructure';

export interface ServiceAccountSchema extends Record<string, unknown> {
export interface GroupServiceAccountSchema extends Record<string, unknown> {
id: number;
username: string;
name: string;
Expand All @@ -15,8 +15,8 @@ export class GroupServiceAccounts<C extends boolean = false> extends BaseResourc
create<E extends boolean = false>(
groupId: string | number,
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<ServiceAccountSchema, C, E, void>> {
return RequestHelper.post<ServiceAccountSchema>()(
): Promise<GitlabAPIResponse<GroupServiceAccountSchema, C, E, void>> {
return RequestHelper.post<GroupServiceAccountSchema>()(
this,
endpoint`groups/${groupId}/service_accounts`,
options,
Expand Down
21 changes: 21 additions & 0 deletions packages/core/src/resources/ServiceAccounts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper, endpoint } from '../infrastructure';
import type { GitlabAPIResponse, ShowExpanded, Sudo } from '../infrastructure';

export interface ServiceAccountSchema extends Record<string, unknown> {
id: number;
name: string;
username: string;
state: string;
locked: boolean;
avatar_url: string;
web_url: string;
}

export class ServiceAccounts<C extends boolean = false> extends BaseResource<C> {
create<E extends boolean = false>(
options?: Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<ServiceAccountSchema, C, E, void>> {
return RequestHelper.post<ServiceAccountSchema>()(this, endpoint`service_accounts`, options);
}
}
1 change: 1 addition & 0 deletions packages/core/src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export * from './PyPI';
export * from './RubyGems';
export * from './Search';
export * from './SearchAdmin';
export * from './ServiceAccounts';
export * from './ServiceData';
export * from './SidekiqMetrics';
export * from './SidekiqQueues';
Expand Down
1 change: 1 addition & 0 deletions packages/rest/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export const {
RubyGems,
Search,
SearchAdmin,
ServiceAccounts,
ServiceData,
SidekiqMetrics,
SidekiqQueues,
Expand Down

0 comments on commit 29c2b39

Please sign in to comment.