-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathUserGPGKeys.ts
54 lines (47 loc) · 1.83 KB
/
UserGPGKeys.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
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper } from '../infrastructure';
import type { GitlabAPIResponse, ShowExpanded, Sudo } from '../infrastructure';
export interface UserGPGKeySchema extends Record<string, unknown> {
id: number;
key: string;
created_at: string;
}
const url = (userId?: number) => (userId ? `users/${userId}/gpg_keys` : 'user/gpg_keys');
export class UserGPGKeys<C extends boolean = false> extends BaseResource<C> {
// Convienence method
add<E extends boolean = false>(
key: string,
options?: { userId?: number } & Sudo & ShowExpanded<E>,
): Promise<GitlabAPIResponse<UserGPGKeySchema, C, E, void>> {
return this.create<E>(key, options);
}
all<E extends boolean = false>({
userId,
...options
}: { userId?: number } & Sudo & ShowExpanded<E> = {}): Promise<
GitlabAPIResponse<UserGPGKeySchema[], C, E, void>
> {
return RequestHelper.get<UserGPGKeySchema[]>()(this, url(userId), options);
}
create<E extends boolean = false>(
key: string,
{ userId, ...options }: { userId?: number } & Sudo & ShowExpanded<E> = {},
): Promise<GitlabAPIResponse<UserGPGKeySchema, C, E, void>> {
return RequestHelper.post<UserGPGKeySchema>()(this, url(userId), {
key,
...options,
});
}
show<E extends boolean = false>(
keyId: number,
{ userId, ...options }: { userId?: number } & Sudo & ShowExpanded<E> = {},
): Promise<GitlabAPIResponse<UserGPGKeySchema, C, E, void>> {
return RequestHelper.get<UserGPGKeySchema>()(this, `${url(userId)}/${keyId}`, options);
}
remove<E extends boolean = false>(
keyId: number,
{ userId, ...options }: { userId?: number } & Sudo & ShowExpanded<E> = {},
): Promise<GitlabAPIResponse<void, C, E, void>> {
return RequestHelper.del()(this, `${url(userId)}/${keyId}`, options);
}
}