-
-
Notifications
You must be signed in to change notification settings - Fork 301
/
Copy pathUserSSHKeys.ts
79 lines (72 loc) · 2.24 KB
/
UserSSHKeys.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
import { BaseResource } from '@gitbeaker/requester-utils';
import { RequestHelper } from '../infrastructure';
import type { GitlabAPIResponse, ShowExpanded, Sudo } from '../infrastructure';
export interface UserSSHKeySchema extends Record<string, unknown> {
id: number;
key: string;
title: string;
created_at: string;
}
const url = (userId?: number) => (userId ? `users/${userId}/keys` : 'user/keys');
export class UserSSHKeys<C extends boolean = false> extends BaseResource<C> {
// Convienence method for create
add<E extends boolean = false>(
title: string,
key: string,
options?: {
userId?: number;
expiresAt?: string;
usageType?: 'auth' | 'signing' | 'auth_and_signing';
} & Sudo &
ShowExpanded<E>,
): Promise<GitlabAPIResponse<UserSSHKeySchema, C, E, void>> {
return this.create<E>(title, key, options);
}
all<E extends boolean = false>({
userId,
...options
}: { userId?: number } & Sudo & ShowExpanded<E> = {}): Promise<
GitlabAPIResponse<UserSSHKeySchema[], C, E, void>
> {
return RequestHelper.get<UserSSHKeySchema[]>()(
this,
url(userId),
options as Sudo & ShowExpanded<E>,
);
}
create<E extends boolean = false>(
title: string,
key: string,
{
userId,
...options
}: {
userId?: number;
expiresAt?: string;
usageType?: 'auth' | 'signing' | 'auth_and_signing';
} & Sudo &
ShowExpanded<E> = {},
): Promise<GitlabAPIResponse<UserSSHKeySchema, C, E, void>> {
return RequestHelper.post<UserSSHKeySchema>()(this, url(userId), {
title,
key,
...options,
});
}
show<E extends boolean = false>(
keyId: number,
{ userId, ...options }: { userId?: number } & Sudo & ShowExpanded<E> = {},
): Promise<GitlabAPIResponse<UserSSHKeySchema, C, E, void>> {
return RequestHelper.get<UserSSHKeySchema>()(
this,
`${url(userId)}/${keyId}`,
options as Sudo & ShowExpanded<E>,
);
}
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 as Sudo & ShowExpanded<E>);
}
}