-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathapi-user.ts
64 lines (53 loc) · 1.48 KB
/
api-user.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
import type { ApiTokenType } from './models/api-token';
import { ValidationError } from 'joi';
import { CLIENT } from './permissions';
export interface IApiUserData {
permissions?: string[];
projects?: string[];
project?: string;
environment: string;
type: ApiTokenType;
secret: string;
tokenName: string;
}
export interface IApiUser {
internalAdminTokenUserId?: number; // user associated to an admin token
username: string;
permissions: string[];
projects: string[];
environment: string;
type: ApiTokenType;
secret: string;
}
export default class ApiUser implements IApiUser {
readonly isAPI: boolean = true;
readonly permissions: string[];
readonly projects: string[];
readonly environment: string;
readonly type: ApiTokenType;
readonly secret: string;
readonly username: string;
constructor({
permissions = [CLIENT],
projects,
project,
environment,
type,
secret,
tokenName,
}: IApiUserData) {
if (!tokenName) {
throw new ValidationError('tokenName is required', [], undefined);
}
this.username = tokenName;
this.permissions = permissions;
this.environment = environment;
this.type = type;
this.secret = secret;
if (projects && projects.length > 0) {
this.projects = projects;
} else {
this.projects = project ? [project] : [];
}
}
}