-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathDeployTokens.ts
134 lines (119 loc) · 3.71 KB
/
DeployTokens.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper, endpoint } from '../infrastructure';
import type {
BaseRequestOptions,
GitlabAPIResponse,
OneOf,
OneOrNoneOf,
PaginationRequestOptions,
PaginationTypes,
ShowExpanded,
Sudo,
} from '../infrastructure';
export type DeployTokenScope =
| 'read_repository'
| 'read_registry'
| 'write_registry'
| 'read_package_registry'
| 'write_package_registry';
export interface DeployTokenSchema extends Record<string, unknown> {
id: number;
name: string;
username: string;
expires_at: string;
revoked: boolean;
expired: boolean;
scopes?: DeployTokenScope[];
}
export interface NewDeployTokenSchema extends DeployTokenSchema {
token: string;
}
export class DeployTokens<C extends boolean = false> extends BaseResource<C> {
all<E extends boolean = false, P extends PaginationTypes = 'offset'>(
{
projectId,
groupId,
...options
}: OneOrNoneOf<{ projectId: string | number; groupId: string | number }> & {
active?: boolean;
} & PaginationRequestOptions<P> &
BaseRequestOptions<E> = {} as any,
): Promise<GitlabAPIResponse<DeployTokenSchema[], C, E, P>> {
let url: string;
if (projectId) url = endpoint`projects/${projectId}/deploy_tokens`;
else if (groupId) url = endpoint`groups/${groupId}/deploy_tokens`;
else url = 'deploy_tokens';
return RequestHelper.get<DeployTokenSchema[]>()(this, url, options);
}
create<E extends boolean = false>(
name: string,
scopes: DeployTokenScope[],
{
projectId,
groupId,
...options
}: OneOf<{ projectId: string | number; groupId: string | number }> & {
expires_at?: string;
username?: string;
} & Sudo &
ShowExpanded<E> = {} as any,
): Promise<GitlabAPIResponse<NewDeployTokenSchema, C, E, void>> {
let url: string;
if (projectId) url = endpoint`projects/${projectId}/deploy_tokens`;
else if (groupId) url = endpoint`groups/${groupId}/deploy_tokens`;
else {
throw new Error(
'Missing required argument. Please supply a projectId or a groupId in the options parameter.',
);
}
return RequestHelper.post<NewDeployTokenSchema>()(this, url, {
name,
scopes,
...options,
});
}
remove<E extends boolean = false>(
tokenId: number,
{
projectId,
groupId,
...options
}: OneOf<{ projectId: string | number; groupId: string | number }> &
Sudo &
ShowExpanded<E> = {} as any,
): Promise<GitlabAPIResponse<void, C, E, void>> {
let url: string;
if (projectId) url = endpoint`projects/${projectId}/deploy_tokens/${tokenId}`;
else if (groupId) url = endpoint`groups/${groupId}/deploy_tokens/${tokenId}`;
else {
throw new Error(
'Missing required argument. Please supply a projectId or a groupId in the options parameter.',
);
}
return RequestHelper.del()(this, url, options as any as Sudo & ShowExpanded<E>);
}
show<E extends boolean = false>(
tokenId: number,
{
projectId,
groupId,
...options
}: OneOf<{ projectId: string | number; groupId: string | number }> &
Sudo &
ShowExpanded<E> = {} as any,
): Promise<GitlabAPIResponse<DeployTokenSchema, C, E, void>> {
let url: string;
if (projectId) url = endpoint`projects/${projectId}/deploy_tokens/${tokenId}`;
else if (groupId) url = endpoint`groups/${groupId}/deploy_tokens/${tokenId}`;
else {
throw new Error(
'Missing required argument. Please supply a projectId or a groupId in the options parameter.',
);
}
return RequestHelper.get<DeployTokenSchema>()(
this,
url,
options as any as Sudo & ShowExpanded<E>,
);
}
}